我在 Firestore 中有项目我正在使用此方法检索
class EntriesList extends StatefulWidget {
const EntriesList({Key key}) : super(key: key);
@override
_EntriesListState createState() => _EntriesListState();
}
class _EntriesListState extends State<EntriesList> {
final Stream _entryStream = FirebaseFirestore.instance
.collection('users')
.doc(FirebaseAuth.instance.currentUser.uid)
.snapshots();
@override
Widget build(BuildContext context) {
return StreamBuilder(
stream: _entryStream,
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasError) {
return Text("Something went wrong");
}
if (snapshot.connectionState == ConnectionState.waiting) {
return CircularProgressIndicator();
}
// this is where I am getting my error
return ListView(children: snapshot.data.map((DocumentSnapshot document) {
Map<String, dynamic> data = document.data() as Map<String, dynamic>;
return Text(data['text'])
}
)
);
},
);
}
}
我本质上是想从我的快照中获取数据,但它返回的是 _JsonDocumentSnapshot
的实例。我不确定如何从这里获取我的数据。
按照本指南了解如何从 Firestore 获取物品 https://firebase.flutter.dev/docs/firestore/usage/