[英]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.