Flutter / Firebase:尝试从Firebase集合中获取数据

时间:2019-02-27 02:26:14

标签: firebase flutter google-cloud-firestore

我正在尝试从Firebase上的集合中获取数据,但它一直返回“没有数据”。该代码用于我的构建,该链接是我的Firebase控制台的图片。

Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Friends'),
      ),
      body: StreamBuilder(
        stream: Firestore.instance.collection('users').snapshots(),
        builder: (context, snapshot) {
          if(!snapshot.hasData) return const Text('There Is NO DATA');
          return ListView.separated(
              separatorBuilder: (context, i) =>
                  Divider(
                    color: Colors.black,
                  ),
              itemCount: snapshot.data.documents.length,
              itemBuilder: (context, i) {
                return _buildRow(snapshot.data.documents[i]);
              });
        }),
    );
  }

Widget _buildRow(DocumentSnapshot document) {
    return ListTile(
        contentPadding: EdgeInsets.only(left: 15.0),
        title: Text(
          document['name'],
        ),
        onTap:(){
          messenger = document;
          Navigator.of(context).push(MaterialPageRoute<void>(builder: (context) => Chat()));
        }
    );

Firebase控制台:

Firebase Console

0 个答案:

没有答案