【发布时间】:2022-01-03 08:23:09
【问题描述】:
我正在使用 Firebase 和 Flutter 来读取对象列表 (EspecieModel)。它在 IOS 和 Android 上运行完美,但在 Web 上无法运行(检索到空列表)。
我正在阅读 Firebase 如下...
Future<List<EspecieModel>> cargarTipoEspecie() async {
final List<EspecieModel> tipoEspecie = [];
Query resp = db.child('PATH/tipoespecie');
resp.onChildAdded.forEach((element) {
final temp = EspecieModel.fromJson(Map<String,dynamic>.from(element.snapshot.value));
temp.idEspecie = element.snapshot.key;
tipoEspecie.add(temp);
});
await resp.once().then((snapshot) {
print("Loaded - ${tipoEspecie.length}");
});
return tipoEspecie;
}
我正在使用 Future Builder 来显示信息...
FutureBuilder(
future: _tipoEspecieBloc.cargarTipoEspecie(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
// print(snapshot.connectionState);
if (snapshot.connectionState == ConnectionState.done && snapshot.hasData{
// print(snapshot.data);
final _especies = snapshot.data;
return Stack(
children: <Widget>[
ListView.builder(
itemCount: _especies!.length,
itemBuilder: (context, i) {
return _crearItem(context, _especies[i], i);
},
),
],
);
} else if (snapshot.hasError) {
print(snapshot.error);
return Text(snapshot.error.toString());
}
else {
return //CircleProgressIndicator Code
);
}
},
),
我无法确定自己做错了什么
如何做一个在 IOS、Android 和 Web 上都运行良好的一次性 Firebase 查询??
【问题讨论】:
标签: flutter firebase-realtime-database flutter-web