Flutter 检查firestore是否有文档,是否未使用Future Builder 完整代码 class yourBookings扩展StatefulWidget{ @凌驾 _yourBookingsState createState()=>\u yourBookingsState(); } 类_yourbookingstate扩展状态{ 状态模型appState; bool\u loadingVisible=false; @凌驾 小部件构建(构建上下文){ appState=StateWidget.of(context.state); 最终编号=appState?.user?.number??”; Future getPosts()异步{ var firestore=firestore.instance; QuerySnapshot qn=等待firestore .收款(“已确认的2”) .文件(编号) .托收(“1”) .getDocuments(); 返回qn文件; } 返回脚手架( appBar:appBar( 标题:文本(“您的预订:”), ), 主体:容器( 孩子:未来建设者( future:getPosts(), 构建器:(\uux,快照){ if(snapshot.connectionState==connectionState.waiting){ 返回中心( 子项:文本(“加载…”), ); }else if(snapshot.hasData){ 返回ListView.builder( itemCount:snapshot.data.length, itemBuilder:(\ux,索引){ Widget image_carousel=新容器( 高度:200.0, 儿童:新旋转木马( //borderRadius:borderRadius.all(半径.圆形(2.0)), boxFit:boxFit.fit高度, 图像:[ 图像网络( “${snapshot.data[index].data[“driverImage”]}”), 图像网络( “${snapshot.data[index].data[“carImage”]}”) ], 自动播放:对, 动画曲线:Curves.FastOutSwowin, animationDuration:持续时间(毫秒:1000), dotSize:4.0, 指示符号RBGPAdd:6.0, dotBgColor:Colors.transparent, ), ); 回程卡( 孩子:ListTile( 标题:专栏( 儿童:[ 尺寸箱(高度:10), 正文( “状态:${snapshot.data[index].data[“Status”]}”, 样式:TextStyle(fontWeight:fontWeight.bold), ), 尺寸箱(高度:10), 图像传送带, 正文( “名称:${snapshot.data[index].data[“driverName”]}”), 尺寸箱(高度:10), 正文( “性别:${snapshot.data[index].data[“性别”]}”), 尺寸箱(高度:10), 正文( “体验:${snapshot.data[index].data[“体验”]}”), 尺寸箱(高度:10), 正文( 编号:${snapshot.data[index].data[“driverNumber”]}), 尺寸箱(高度:10), 正文( “时间:${snapshot.data[index].data[“Time”]}”), 尺寸箱(高度:10), 正文( “计划于:${snapshot.data[index].data[“rideOn”]}”), 尺寸箱(高度:10), 升起的按钮( 颜色:颜色,黑色, 已按下:(){ 导航器。推( 上下文 材料路线( 建造商:()=>新发行(); }, 子:文本( “有问题”, 样式:TextStyle(颜色:Colors.white), ), ), 尺寸箱(高度:10), 升起的按钮( 已按下:(){ 导航器。推( 上下文 材料路线( 建筑商:()=>rating1()); }, 子项:文本(“费率驱动因素”), ) ], ), ), ); }); }else if(快照==null){ 返回中心( 子项:文本(“未找到…”), ); } 返回中心( 子项:文本(“未找到2…”), ); }), ), ); } }
getPosts()指用于获取数据的firestore位置 我想使用Future Builder检查firestore是否包含数字作为文档。我该怎么做 编号->1包含更多详细信息 如果号码不存在,则显示firestore中的数据,否则显示“未找到…”。我如何才能做到这一点Flutter 检查firestore是否有文档,是否未使用Future Builder 完整代码 class yourBookings扩展StatefulWidget{ @凌驾 _yourBookingsState createState()=>\u yourBookingsState(); } 类_yourbookingstate扩展状态{ 状态模型appState; bool\u loadingVisible=false; @凌驾 小部件构建(构建上下文){ appState=StateWidget.of(context.state); 最终编号=appState?.user?.number??”; Future getPosts()异步{ var firestore=firestore.instance; QuerySnapshot qn=等待firestore .收款(“已确认的2”) .文件(编号) .托收(“1”) .getDocuments(); 返回qn文件; } 返回脚手架( appBar:appBar( 标题:文本(“您的预订:”), ), 主体:容器( 孩子:未来建设者( future:getPosts(), 构建器:(\uux,快照){ if(snapshot.connectionState==connectionState.waiting){ 返回中心( 子项:文本(“加载…”), ); }else if(snapshot.hasData){ 返回ListView.builder( itemCount:snapshot.data.length, itemBuilder:(\ux,索引){ Widget image_carousel=新容器( 高度:200.0, 儿童:新旋转木马( //borderRadius:borderRadius.all(半径.圆形(2.0)), boxFit:boxFit.fit高度, 图像:[ 图像网络( “${snapshot.data[index].data[“driverImage”]}”), 图像网络( “${snapshot.data[index].data[“carImage”]}”) ], 自动播放:对, 动画曲线:Curves.FastOutSwowin, animationDuration:持续时间(毫秒:1000), dotSize:4.0, 指示符号RBGPAdd:6.0, dotBgColor:Colors.transparent, ), ); 回程卡( 孩子:ListTile( 标题:专栏( 儿童:[ 尺寸箱(高度:10), 正文( “状态:${snapshot.data[index].data[“Status”]}”, 样式:TextStyle(fontWeight:fontWeight.bold), ), 尺寸箱(高度:10), 图像传送带, 正文( “名称:${snapshot.data[index].data[“driverName”]}”), 尺寸箱(高度:10), 正文( “性别:${snapshot.data[index].data[“性别”]}”), 尺寸箱(高度:10), 正文( “体验:${snapshot.data[index].data[“体验”]}”), 尺寸箱(高度:10), 正文( 编号:${snapshot.data[index].data[“driverNumber”]}), 尺寸箱(高度:10), 正文( “时间:${snapshot.data[index].data[“Time”]}”), 尺寸箱(高度:10), 正文( “计划于:${snapshot.data[index].data[“rideOn”]}”), 尺寸箱(高度:10), 升起的按钮( 颜色:颜色,黑色, 已按下:(){ 导航器。推( 上下文 材料路线( 建造商:()=>新发行(); }, 子:文本( “有问题”, 样式:TextStyle(颜色:Colors.white), ), ), 尺寸箱(高度:10), 升起的按钮( 已按下:(){ 导航器。推( 上下文 材料路线( 建筑商:()=>rating1()); }, 子项:文本(“费率驱动因素”), ) ], ), ), ); }); }else if(快照==null){ 返回中心( 子项:文本(“未找到…”), ); } 返回中心( 子项:文本(“未找到2…”), ); }), ), ); } },flutter,google-cloud-firestore,Flutter,Google Cloud Firestore,getPosts()指用于获取数据的firestore位置 我想使用Future Builder检查firestore是否包含数字作为文档。我该怎么做 编号->1包含更多详细信息 如果号码不存在,则显示firestore中的数据,否则显示“未找到…”。我如何才能做到这一点 Future builder用于流式firestore。您的帖子中没有问题。所以请在@Joao编辑它…检查我上面链接的链接。 class yourBookings extends StatefulWidget { @ove
Future builder用于流式firestore。您的帖子中没有问题。所以请在@Joao编辑它…检查我上面链接的链接。
class yourBookings extends StatefulWidget {
@override
_yourBookingsState createState() => _yourBookingsState();
}
class _yourBookingsState extends State<yourBookings> {
StateModel appState;
bool _loadingVisible = false;
@override
Widget build(BuildContext context) {
appState = StateWidget.of(context).state;
final number = appState?.user?.number ?? '';
Future getPosts() async {
var firestore = Firestore.instance;
QuerySnapshot qn = await firestore
.collection("confirmed_c_rides2")
.document(number)
.collection("1")
.getDocuments();
return qn.documents;
}
return Scaffold(
appBar: AppBar(
title: Text("Your Bookings :"),
),
body: Container(
child: FutureBuilder(
future: getPosts(),
builder: (_, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return Center(
child: Text("Loading ..."),
);
} else if (snapshot.hasData) {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (_, index) {
Widget image_carousel = new Container(
height: 200.0,
child: new Carousel(
//borderRadius: BorderRadius.all(Radius.circular(2.0)),
boxFit: BoxFit.fitHeight,
images: [
Image.network(
"${snapshot.data[index].data["driverImage"]}"),
Image.network(
"${snapshot.data[index].data["carImage"]}")
],
autoplay: true,
animationCurve: Curves.fastOutSlowIn,
animationDuration: Duration(milliseconds: 1000),
dotSize: 4.0,
indicatorBgPadding: 6.0,
dotBgColor: Colors.transparent,
),
);
return Card(
child: ListTile(
title: Column(
children: <Widget>[
SizedBox(height: 10),
Text(
"Status: ${snapshot.data[index].data["status"]}",
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(height: 10),
image_carousel,
Text(
"Name: ${snapshot.data[index].data["driverName"]}"),
SizedBox(height: 10),
Text(
"Gender: ${snapshot.data[index].data["gender"]}"),
SizedBox(height: 10),
Text(
"Experience: ${snapshot.data[index].data["experience"]}"),
SizedBox(height: 10),
Text(
"Number: ${snapshot.data[index].data["driverNumber"]}"),
SizedBox(height: 10),
Text(
"Time: ${snapshot.data[index].data["time"]}"),
SizedBox(height: 10),
Text(
"Scheduled on: ${snapshot.data[index].data["rideOn"]}"),
SizedBox(height: 10),
RaisedButton(
color: Colors.black,
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => new issue()));
},
child: Text(
"Having issue",
style: TextStyle(color: Colors.white),
),
),
SizedBox(height: 10),
RaisedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => rating1()));
},
child: Text("Rate driver"),
)
],
),
),
);
});
} else if (snapshot==null) {
return Center(
child: Text("not found..."),
);
}
return Center(
child: Text("not found 2..."),
);
}),
),
);
}
}