我正在为我的数据库工作使用/学习 Firebase。我的快照就像 _jsonQuerySnapshot 或 _jsonDocumentSnapshot 一样。但它必须是 QuerySnapshot 或 DocumentSnapshot。因此,我必须对我的快照进行编码和解码以使用我的数据。如果我不使用 encode decode json 我总是会收到 null 或 object 错误。这是我的课程从状态扩展
class _MyHomePageState extends State<MyHomePage> {
final _firestore = FirebaseFirestore.instance;
@override
Widget build(BuildContext context) {
CollectionReference moviesRef=_firestore.collection('movies');
DocumentReference babaRef = _firestore.collection('movies').doc('Baba');
return Scaffold(
backgroundColor: Colors.grey,
appBar: AppBar(
title: Text('FireStore Crud'),
),
body: Center(
child: Container(
child: Column(
children: [
StreamBuilder<QuerySnapshot>(
stream: moviesRef.snapshots(),
builder: (BuildContext context,AsyncSnapshot asyncSnapshot){
List<DocumentSnapshot>listOfDocumentSnapshot=asyncSnapshot.data.docs;
return Flexible(
child: ListView.builder(
itemCount: listOfDocumentSnapshot.length,
itemBuilder: (context,index){
Text('${listOfDocumentSnapshot[index].data()['name']}' ,style: TextStyle(fontSize: 24),);
},
),
);
},
),
],
),
),
),
);
}
}
这是我的错误。