我有一个问题与我的类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
尝试将您的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(),