我正在创建一个 Flutter 应用程序,但在实现 Firebase 时陷入困境。
enter return Container(
child: StreamBuilder<QuerySnapshot>(
stream: quizStream.snapshots(),
builder: (context, snapshot) {
return snapshot.data != null
? Container()
: ListView.builder(
itemCount: snapshot.data!.docs.length,
itemBuilder: (context, index) {
return QuizTile(
ImgUrl: snapshot.data!.docs[index].data()["imgdesc"] ,
);
});
}));
}
ImgUrl: snapshot.data!.docs[index].data()["imgdesc"]
这是我收到错误的行,它告诉我:
the operator '[]' isn't defined for the type 'Object? Function()'. Try defining the operator '[]'.
最佳答案
您需要将其转换为 Map<String,dynamic>
ImgUrl: snapshot.data!.docs[index].data() as Map<String,dynamic>["imgdesc"],
或者使用这个:
ImgUrl: snapshot.data!.docs[index].get('imgdesc'),
关于flutter - Dart:未为类型 '[]' 定义运算符 'Object? Function()' 。尝试定义运算符 '[]',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72157400/