【发布时间】:2021-02-24 11:27:58
【问题描述】:
我已经创建了 createRecord() 方法:
CollectionReference addBlog = FirebaseFirestore.instance.collection('blogAddress');
Future<void> createRecord() {
// Call the user's CollectionReference to add a new user
return addBlog
.add({
'blogAddress': IfUserProfile.blog, // Stokes and Sons
})
.then((value) => print("Blog Added"))
.catchError((error) => print("Failed to add Blog: $error"));
}
从 textformField 创建记录:
onChanged: (value) {
IfUserProfile.blog = value;
},
它可以正常工作,它会在 Firestore 上正确添加集合:
现在我正在尝试将这些数据放入另一个屏幕并调用实例:
CollectionReference blogAddress =
FirebaseFirestore.instance.collection('blogAddress');
然后我用 FutureBuilder 将包含数据的列包装起来:
FutureBuilder<DocumentSnapshot>(
future: blogAddress.doc().get(),
builder: (BuildContext context,
AsyncSnapshot<DocumentSnapshot> snapshot) {
if (snapshot.hasError) {
return Text("Something went wrong");
}
if (snapshot.connectionState == ConnectionState.done) {
Map<String, dynamic> data = snapshot.data.data();
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SizedBox(
height: 30,
),
Text("Full Name: ${data['blogAddress']}"),
但我无法获得我得到的数据:
在 null 上调用了方法“[]”。 接收方:空 尝试调用:
【问题讨论】:
标签: flutter google-cloud-firestore