【发布时间】:2021-07-09 21:25:11
【问题描述】:
我想从 Firebase 检索数据到 Listview。
这是我的 firebase 云火存储Image of Firebase Database
我尝试了很多方法,所有代码都没有任何错误,但是当我运行应用程序并打开活动时,数据无法显示它们将为空,
这是我的代码:
class _ListPageState extends State<ListPage> {
Future _getTaxi() async {
QuerySnapshot querySnapshot = await FirebaseFirestore.instance.collection('taxi').get();
return querySnapshot.docs;
}
@override
Widget build(BuildContext context) {
return Container(
child: FutureBuilder(
future: _getTaxi(),
builder: (context, snapshot){
if(snapshot.connectionState == ConnectionState.waiting){
return Center(
child: CircularProgressIndicator(),
);
} else {
return ListView.builder(
itemCount: snapshot.data.length,
itemBuilder: (context, index){
return Card(
child: ListTile(
title: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(snapshot.data[index].data()["name"], //taxi driver name
style: TextStyle(
fontSize: 25,
fontFamily: 'krmanj',
),
),
Text(snapshot.data[index].data()["line"],
style: TextStyle(
color: Colors.grey,
fontSize: 20,
fontFamily: 'krmanj',
),
),
],
),
],
),
),
);
});
}
}),
);
}
}
运行应用程序并打开调试控制台显示的活动后
>Restarted application in 974ms.
W/DynamiteModule( 8359): Local module descriptor class for providerinstaller not found.
I/DynamiteModule( 8359): Considering local module providerinstaller:0 and remote module providerinstaller:0
W/ProviderInstaller( 8359): Failed to load providerinstaller module: No acceptable module found. Local version is 0 and remote version is 0.
W/Firestore( 8359): (22.1.2) [WatchStream]: (5cf536b) Stream closed with status: Status{code=PERMISSION_DENIED, description=Permission denied on resource project bardarash-city., cause=null}.
W/Firestore( 8359): (22.1.2) [OnlineStateTracker]: Could not reach Cloud Firestore backend. Connection failed 1 times. Most recent error: Status{code=PERMISSION_DENIED, description=Permission denied on resource project bardarash-city., cause=null}
W/Firestore( 8359): This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.
【问题讨论】:
-
这表示您的互联网连接目前不健康,请确保您的连接稳定。您没有获取数据的原因是由于 Internet 连接不佳,您没有连接到 Cloud Firestore。
-
我的网络非常好,我在模拟器中的网络没有任何问题
标签: firebase flutter dart google-cloud-firestore