繁体   English   中英

我想初始化 state。 (RiverPod:StateNotifier)

[英]I want to initialize the state. ( RiverPod : StateNotifier )

我想初始化super的state。

错误:未为类型“Type”定义运算符“<”。

super(state ?? List<UserModel> [])

提供者

  final userProvider = StateNotifierProvider<UserNotifier>((ref) {
      return UserNotifier();
    });

状态通知器

class UserNotifier extends StateNotifier<List<UserModel>> {
  UserNotifier([List<UserModel>? state])
      : super(state ?? List<UserModel> []) { // << Error 
    fatchData(); // It's same as initState();
  }
  String collection = "Users";


  Future<List<UserModel>> fatchData() async =>
      firebaseFirestore.collection(collection).get().then((result) {
        final List<UserModel> users = [];
        for (final DocumentSnapshot user in result.docs) {
          users.add(UserModel.fromSnapshot(user));
        }
        return users;
      });
}

可以使用<int>[]或使用构造函数List<int>()创建列表, List<int>[]不是有效格式

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM