【问题标题】:cannot retrieve data from firestore into listview flutter无法将数据从 firestore 检索到 listview 扑扑
【发布时间】: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


【解决方案1】:

OP 编辑​​后: 它说permission denied,您无法连接到您的firestore 数据库。在 Firebase 控制台中仔细检查您的规则\权限。


你必须使用data()

像这样:

 Text(snapshot.data[index].data()["name"]
 Text(snapshot.data[index].data()["line"]

【讨论】:

  • 你得到什么错误。回复 isn't solved 并不能真正帮助调试。
  • 另外,你为什么在 itemBuilder: (_,index) 中忽略 context ?试试itemBuilder: (context , index)
  • 你告诉我的所有事情我都做了,但活动仍然是空的。
  • 显示调试控制台的输出,可能是 renderFlex 错误,你怎么确定你得到了数据,但没有显示?
  • 看答案2我写的
猜你喜欢
  • 2020-12-23
  • 2021-03-13
  • 2021-02-20
  • 1970-01-01
  • 1970-01-01
  • 2019-09-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多