【问题标题】:I want to initialize the state. ( RiverPod : StateNotifier )我想初始化状态。 (RiverPod:StateNotifier)
【发布时间】:2021-02-12 15:13:08
【问题描述】:

我要初始化super的状态。

错误:没有为类型“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;
      });
}

【问题讨论】:

    标签: flutter riverpod


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2019-05-08
      • 1970-01-01
      • 2021-10-13
      • 2019-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-05
      • 2018-08-22
      相关资源
      最近更新 更多