Dart:未为类型 'Object? Function()' 定义运算符“[]”。尝试定义运算符 '[]'
Dart: The operator '[]' isn't defined for the type 'Object? Function()'. Try defining the operator '[]'
我正在创建一个 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 应用程序,但在实施 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'),