简体   繁体   English

firestore 数据未显示在 Flutter listtile ListView 中

[英]firestore data not displaying in Flutter listtile ListView

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.来自 firestore 的数据未显示在列表图块中,ListView 之前的所有功能都正常工作,例如用于显示加载文本的 if 语句,但是当它到达 ListView 时没有任何反应。 I'm a little bit new to firebase. any help would be appreciated.我对 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(),
          );
        },
      ),
    ),
  );
  }
}

The firestore collection I'm trying to display:我要显示的 firestore 集合:

我要展示的 firestore 系列

app shows a blank page (I'm displaying the application from web the converting it mobile view)应用程序显示一个空白页面(我正在显示来自 web 的应用程序并将其转换为移动视图)

Did you read about indexing in firestore: https://firebase.google.com/docs/firestore/query-data/indexing您是否阅读过有关在 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.要确定问题是什么,请查看日志。您会找到一个有用的链接,可以让您轻松创建索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM