【发布时间】:2021-03-04 21:07:07
【问题描述】:
已经尝试了几乎所有堆栈溢出的解决方案 我可以在 firestore 中写入数据,但在实现 fetch 功能后,我无法获取我上传的数据
我期望做的是: 我已经在 firestore 中上传了一个表单用户输入数据,并想从 firestore 中获取这些数据
如果您愿意,可以找到完整代码的链接here
错误如下:
Closure call with mismatched arguments: function 'data'
Receiver: Closure: () => Map<String, dynamic> from Function 'data':.
Tried calling: data
Found: data() => Map<String, dynamic>
这是我迄今为止编写的所有方法的快速快照
String name, age, phone;
crudMethods crudObjs = crudMethods();
QuerySnapshot rideNow;
List userProfilesList = [];
@override
void initState() {
fetchDatabaseList();
super.initState();
}
fetchDatabaseList() async {
dynamic resultant = await crudMethods().getData();
if (resultant == null) {
print('Unable to retrieve');
} else {
setState(() {
userProfilesList = resultant;
});
}
}
body: Column(children[
Expanded(
child: ListView.builder(
itemCount: userProfilesList.length,
itemBuilder: (context, i) {
return ListTile(
title: Text(userProfilesList[i].data['name']),
subtitle: Text(userProfilesList[i].data['age']),
);
},
),
),
]);
获取数据方法如下:
Future getData() async {
List itemsList = [];
final CollectionReference profileList =
FirebaseFirestore.instance.collection('Ride Now Details');
try {
await profileList.get().then((querySnapshot) {
querySnapshot.docs.forEach((element) {
itemsList.add(element.data);
});
});
return itemsList;
} catch (e) {
print(e.toString());
return null;
}
}
如果您有更好的方法来获取数据,请帮我解决这个问题并帮助我解决这个错误。
【问题讨论】:
标签: flutter dart google-cloud-firestore widget