Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RxList extends List,not recommended #3133

Closed
YueLiXing opened this issue Jun 25, 2024 · 1 comment
Closed

RxList extends List,not recommended #3133

YueLiXing opened this issue Jun 25, 2024 · 1 comment
Labels
Improper use of GetX When the issue is caused by the user not using GetX properly

Comments

@YueLiXing
Copy link

class TempService extends GetxService {
  final message = <String>[].obs;
  
  setMessage(List<String> newMessages) {
    message.value = newMessages;
  }
  
  Future<void> loadMessage() async {
    final temp = ['123'].obs;
    setMessage(temp);
  }
}

When you use it this way, there will be no error or warning prompts, but exceptions will occur at runtime because assigning the value of one Rx object to another Rx value。

@jonataslaw jonataslaw added the Improper use of GetX When the issue is caused by the user not using GetX properly label Aug 11, 2024
@jonataslaw
Copy link
Owner

jonataslaw commented Aug 11, 2024

Hello, here are the docs about How to use Lists

You SHOULD NEVER use list.value = newValue.

Use AssignAll (or assign) methods.

Using your exemple:

class TempService extends GetxService {
  final message = <String>[].obs;
  
  setMessage(List<String> newMessages) {
    message.assignAll(newMessages);
  }
  
  Future<void> loadMessage() async {
    final temp = ['123'].obs;
    setMessage(temp);
  }
}

I hope it helps.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improper use of GetX When the issue is caused by the user not using GetX properly
Projects
None yet
Development

No branches or pull requests

2 participants