简体   繁体   中英

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

I want to initialize the state of super.

Error: The operator '<' isn't defined for the type 'Type'.

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

Provider

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

StateNotifier

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;
      });
}

List can be created by using <int>[] or using the constructor List<int>() , List<int>[] is not a valid format

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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