The member 'value' can only be used within instance members of subclasses with flutter GetX
Asked Answered
S

1

-1

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

Sherrell answered 6/10, 2021 at 5:15 Comment(2)
You generally subscribe to observables, not access the value raw.Soap
but it is work without any problem except this warningSherrell
C
1

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));
Counterstatement answered 11/10, 2021 at 8:25 Comment(3)
without .value it doesn't work correctly and as expected.... and with final authData = RxList([]); it also show me same problemSherrell
Check the updated answerCounterstatement
Thanks pal ..... it workedSherrell

© 2022 - 2024 — McMap. All rights reserved.