StreamProvider.value 的初始数据应该是什么
我无法将其初始化为 null
Widget build(BuildContext context) {
return StreamProvider<QuerySnapshot>.value(
value: DatabaseService.withoutUID().brews,
initialData: null,
......
Run Code Online (Sandbox Code Playgroud)
initialData:null 显示错误:
The argument type 'Null' can't be assigned to the parameter type 'QuerySnapshot<Object?>'.
下面是 DatabaseService 辅助类
class DatabaseService{
final String uid;
DatabaseService(this.uid);
DatabaseService.withoutUID():uid="" ;
//collection reference
final CollectionReference brewCollection = FirebaseFirestore.instance.collection('brews');
Future updateUserData(String sugars, String name, int strength) async{
return await brewCollection.doc(uid).set({
"sugars": sugars,
"name" : name,
"strength" : strength,
});
}
//get brews stream
Stream<QuerySnapshot>? get brews{
return brewCollection.snapshots();
}
}
Run Code Online (Sandbox Code Playgroud)
我在这里调用该流
class …Run Code Online (Sandbox Code Playgroud)