Patrick SINT
Patrick SINT

Reputation: 600

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

Upvotes: 2

Views: 2188

Answers (1)

EdwynZN
EdwynZN

Reputation: 5601

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

Upvotes: 1

Related Questions