Ade*_*Jr. 1 firebase flutter google-cloud-firestore
我刚刚更新到 Dart2 和 Flutter sdk: '>=2.12.0 <3.0.0' 现在出现错误:
return Scaffold(
body: FutureBuilder(
future: usersRef.doc(widget.accountiD).get(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return buildLoading();
}
UserAccount currentUser = UserAccount.fromDocument(snapshot.data);
return ListView(
children: []
);
}
),
);
Run Code Online (Sandbox Code Playgroud)
错误出现在snapshot.data上,显示参数类型“对象?” 无法分配给参数类型“DocumentSnapshot”。 该怎么办?我需要帮助。
改成这样:
return Scaffold(
body: FutureBuilder<DocumentSnapshot>(
future: usersRef.doc(widget.accountiD).get(),
builder: (context, snapshot) {
if (!snapshot.hasData) {
return buildLoading();
}
UserAccount currentUser = UserAccount.fromDocument(snapshot.data.data()); //you need to add "data()" to access the map of objects inside snapshot.data
return ListView(
children: []
);
}
),
);
Run Code Online (Sandbox Code Playgroud)
不久前我遇到了同样的问题,然后又遇到了这个问题,并且忘记了将我带到这里的解决方案。
我找到的解决方案是使用“as”关键字
snapshot.data as int
Run Code Online (Sandbox Code Playgroud)
或者
snapshot.data as String
Run Code Online (Sandbox Code Playgroud)
对任何其他数据类型执行相同的操作。希望能帮助到你。答复由 发送。
| 归档时间: |
|
| 查看次数: |
3156 次 |
| 最近记录: |