📜  没有为“对象”类型定义吸气剂“文档”.尝试导入定义“docs”的库,将名称更正为现有 getter 的名称,或定义名为“docs”的 getter 或字段 - 无论代码示例

📅  最后修改于: 2022-03-11 14:58:22.128000             🧑  作者: Mango

代码示例1
Stream collectionStream = FirebaseFirestore.instance.collection('users').snapshots();
Stream documentStream = FirebaseFirestore.instance.collection('users').doc('ABC123').snapshots();

class UserInformation extends StatefulWidget {
  @override
    _UserInformationState createState() => _UserInformationState();
}

class _UserInformationState extends State {
  final Stream _usersStream = FirebaseFirestore.instance.collection('users').snapshots();

  @override
  Widget build(BuildContext context) {
    return StreamBuilder(
      stream: _usersStream,
      builder: (BuildContext context, AsyncSnapshot snapshot) {
        if (snapshot.hasError) {
          return Text('Something went wrong');
        }

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

        return new ListView(
          children: snapshot.data.docs.map((DocumentSnapshot document) {
          Map data = document.data() as Map;
            return new ListTile(
              title: new Text(data['full_name']),
              subtitle: new Text(data['company']),
            );
          }).toList(),
        );
      },
    );
  }
}