firestore数据未显示在Flutter ListTile ListView中

发布于 2025-01-23 12:25:51 字数 2149 浏览 0 评论 0 原文

来自Firestore的数据并未显示在列表图中,列表视图之前的所有功能都可以正常工作,例如用于显示加载文本的IF语句,但是当它到达ListView时,什么也不会发生。 我有点新手Firebase。 任何帮助将不胜感激。

class _DoctorsState extends State<Doctors> {
  final Stream<QuerySnapshot> _userStream = 
  FirebaseFirestore.instance.collection('doctors').snapshots();

  @override
  Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text('Doctors'),
      backgroundColor: Colors.orange,
    ),
    body: SafeArea(
      child: StreamBuilder<QuerySnapshot>(
        stream: _userStream,
        builder:
            (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
          
          if (snapshot.hasError) {
            return Text('Something went wrong');
          }

          if (snapshot.connectionState == ConnectionState.waiting) {
            return Text("Loading");
          }

          return ListView(
            children: snapshot.data!.docs.map((DocumentSnapshot document) {
              Map<String, dynamic> doctors =
                  document.data()! as Map<String, dynamic>;
              return Padding(
                padding: EdgeInsets.all(5),
                child: Column(
                  children: [
                    SizedBox(
                      height: 10,
                    ),
                    Container(
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.all(Radius.circular(20)),
                          border: Border.all(color: Colors.grey)),
                      child: ListTile(
                          title: Text(doctors['name']),
                          subtitle: Text(doctors['speciality'])),
                    ),
                  ],
                ),
              );
            }).toList(),
          );
        },
      ),
    ),
  );
  }
}

我正在尝试显示的Firestore集合:

“我试图显示的firestore集合”

应用程序显示一个空白页(我正在从网络显示应用程序转换为移动视图)

data from the firestore are not displaying in the list tile, all functions before the ListView are working fine such as the if statement for showing loading text, but when it reaches ListView nothing happens.
I'm a little bit new to firebase.
any help would be appreciated.

class _DoctorsState extends State<Doctors> {
  final Stream<QuerySnapshot> _userStream = 
  FirebaseFirestore.instance.collection('doctors').snapshots();

  @override
  Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text('Doctors'),
      backgroundColor: Colors.orange,
    ),
    body: SafeArea(
      child: StreamBuilder<QuerySnapshot>(
        stream: _userStream,
        builder:
            (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
          
          if (snapshot.hasError) {
            return Text('Something went wrong');
          }

          if (snapshot.connectionState == ConnectionState.waiting) {
            return Text("Loading");
          }

          return ListView(
            children: snapshot.data!.docs.map((DocumentSnapshot document) {
              Map<String, dynamic> doctors =
                  document.data()! as Map<String, dynamic>;
              return Padding(
                padding: EdgeInsets.all(5),
                child: Column(
                  children: [
                    SizedBox(
                      height: 10,
                    ),
                    Container(
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.all(Radius.circular(20)),
                          border: Border.all(color: Colors.grey)),
                      child: ListTile(
                          title: Text(doctors['name']),
                          subtitle: Text(doctors['speciality'])),
                    ),
                  ],
                ),
              );
            }).toList(),
          );
        },
      ),
    ),
  );
  }
}

The firestore collection I'm trying to display:

the firestore collection I'm trying to display

app shows a blank page (I'm displaying the application from web the converting it mobile view)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

两相知 2025-01-30 12:25:51

您是否读过有关Firestore的索引:

我认为您应该为查询添加索引。
为了确保问题是什么,请查看日志。您会找到一个有用的链接,使您可以轻松地制作索引。

Did you read about indexing in firestore:
https://firebase.google.com/docs/firestore/query-data/indexing

I think you should add index for your query.
to make sure the problem what is,look at the log.you will find a helpful link that will allow you to easily make the index.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文