Issue
i have encounterd this problem in this example:
class AuthController extends GetxController {
final storage = const FlutterSecureStorage();
var authData = [].obs;
var isLoading = false.obs;
var authLoading = false.obs;
@override
onInit() {
authUser();
super.onInit();
}
authUser() async {
var all = await storage.readAll();
authData.value = all.entries
.map((e) => AuthModel(key: e.key, value: e.value)).toList(growable: false);
}
bool isAuth() {
var a = isLoading.value.isBlank;
return authData.value.isNotEmpty;
}
here in this line:
return authData.value.isNotEmpty;
IDE add line under (value) and warning like this:
The member 'value' can only be used within instance members of subclasses of 'package:get/get_rx/src/rx_types/rx_iterables/rx_list.dart'.
how can i solve this problem? or just work around it? >>> Thank you in advace
Solution
Lists are reactive by default. Therefore unlike other observables, you don't need to use .value
to access the list. But you need to use .obs
when declaring them.
Or you can use something like this if you want to use .value
too with lists:
final authData = RxList([]);
Update
The reason why it doesn't work correctly and as expected because of this:
authData.value = all.entries
.map((e) => AuthModel(key: e.key, value: e.value)).toList(growable: false);
In case of setting the value of RxLists you should use assignAll
method on the RxList like this:
authData.assignAll(all.entries
.map((e) => AuthModel(key: e.key, value: e.value)).toList(growable: false));
Answered By - S. M. JAHANGIR
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.