【发布时间】: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;
});
}
【问题讨论】: