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

Warn against AsyncNotifier.update misuses #2205

Open
rrousselGit opened this issue Feb 19, 2023 · 1 comment
Open

Warn against AsyncNotifier.update misuses #2205

rrousselGit opened this issue Feb 19, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request linter

Comments

@rrousselGit
Copy link
Owner

class Example extends AsyncNotifier<int> {
 ...

  void fn() {
    state = AsyncLoading(); // KO, "update" will likely never complete
    update((data) => ...);
  }

  void fn() {
    update((data) {
      state = AsyncLoading(); // OK
       ...
    });
  }


  void fn() {
    update((unused) => ...); // the parameter should be used. Otherwise use AsyncValue.guard
  }

}
@rrousselGit rrousselGit added enhancement New feature or request linter labels Feb 19, 2023
@rrousselGit rrousselGit self-assigned this May 10, 2023
@rrousselGit rrousselGit added this to the Post 3.0 release milestone Oct 15, 2023
@yknevenky
Copy link

yknevenky commented Jun 1, 2024

@rrousselGit

I am trying to update the state of a FamilyAsyncNotifier partially, I just want to know whether I am doing it right. Also in this case of updating a asyncvalue partially, I want to know what's differences in using whenData, AsyncGuard.value and update method . It would be a immense help, if you provide some clarity on this.

Example

The state here is a freezed class and looks something like this

College(
name: "",
students: [],
faculties: [],
departments: []
)

All the above properties are not updated in a one go, for example the below code tries to update the students property while retaining the other values to its previous value.

update((state) async {
      List<Student> students =
          await getStudentsByCollegeId(id: this.arg);
      return state.copyWith(students: students);
});

Am I doing it right or it needs correction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request linter
Projects
None yet
Development

No branches or pull requests

2 participants