【发布时间】:2020-08-06 17:52:33
【问题描述】:
当我的应用程序运行时,我使用确切的文档名称调用 firestore 集合。 我的要求是,如果 documentId 已经存在,那么它将返回一个空白容器 如果它不存在,那么它将返回一个 Raised Button ,可以在其中添加详细信息。目前我正在使用流生成器,但它不起作用。
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: SafeArea(
child: Scaffold(
appBar: AppBar(title: Text('KartOfill',),backgroundColor: Colors.red,),
body: StreamBuilder<Object>(
stream: Firestore.instance.collection('users').document('9954603381').snapshots(),
builder: (context, snapshot) {
if(snapshot.hasData){
return Container();
}
return Container(
child: RaisedButton(
onPressed: () async{
var firebaseUser = await FirebaseAuth.instance.currentUser();
firestore.collection("users").document('9954603381').setData(
{
"name" : "john",
"age" : 50,
"email" : "example@example.com",
"address" : {
"street" : "street 24",
"city" : "new york"
}
}).then((_){
print("success!");
});
},
),
);
}
),
),
),
);
}
【问题讨论】:
-
你应该在这里使用未来的构建器
-
在下面给你写了一个例子。如果这解决了您的问题,请接受答案
标签: firebase flutter google-cloud-firestore