提问者:小点点

参数类型“Stream<QuerySnapshot<Map<String,动态>>>”不能分配给参数类型“Stream<QuerySnapshot>?”


我有一个问题与我的类GetInfo:

class GetInfo extends StatelessWidget {
  const GetInfo({Key? key}) : super(key: key);
 
  @override
  Widget build(BuildContext context) {
    return Material(
      child: StreamBuilder<QuerySnapshot>(
          stream: FirebaseFirestore.instance.collection('stories').snapshots(),
          builder: (context, 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) {
                return new ListTile(
                  title: Text(document.get('display_name')),
                  subtitle: Text(document.get('profession')),
                );
              }).toList(),
            );
          }),
    );
  }
}

线路有问题:

stream: FirebaseFirestore.instance.collection('stories').snapshots(),

我收到消息:

参数类型'Stream

在控制台中:

错误:参数类型'Stream

  • 'Stream'来自'dart: async'。
  • 'QuerySnapshot/1/'来自cloud_firestore/cloud_firestore. dart'

共1个答案

匿名用户

尝试将您的listview子代码更改为:

children: snapshot.data!.docs.map((DocumentSnapshot document) {
 Map<String, dynamic> data = document.data()! as Map<String, dynamic>;
                return new ListTile(
                  title: Text(data['display_name']),
                  subtitle: Text(data['profession']),
                );
              }).toList(),