小编Adi*_*VSM的帖子

StreamProvider<QuerySnapshot>.value flutter 的初始数据

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)

dart firebase flutter google-cloud-firestore

6
推荐指数
2
解决办法
6810
查看次数

标签 统计

dart ×1

firebase ×1

flutter ×1

google-cloud-firestore ×1