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

ValueNotifier should have an addValueListener method. #148171

Open
TimeLex opened this issue May 11, 2024 · 0 comments
Open

ValueNotifier should have an addValueListener method. #148171

TimeLex opened this issue May 11, 2024 · 0 comments
Labels
c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter framework flutter/packages/flutter repository. See also f: labels. P3 Issues that are less important to the Flutter project team-framework Owned by Framework team triaged-framework Triaged by Framework team

Comments

@TimeLex
Copy link

TimeLex commented May 11, 2024

Use case

A listener of a ValueNotifier often needs the value itself when it is called, but the addListener method does not return the value of the ValueNotifier. It is often easier to get the value within the listener, for example in this case:

ValueNotifier<bool> loadingNotifier = getLoadingNotifier();
loadingNotifier.addListener(() => print("isLoading: ${loadingNotifier.value}"));

Before adding the listener, a variable must be created that can then be called within the listener.

It would be easier to pass the variable to the listener as follows:

getLoadingNotifier().addValueListener((isLoading) => print("isLoading: $isLoading"));

Proposal

The ValueNotifier should have an addValueListener-Method which passes the value to its listeners.

void addValueListener(void Function(T value) listener);
@danagbemava-nc danagbemava-nc added in triage Presently being triaged by the triage team c: new feature Nothing broken; request for a new capability framework flutter/packages/flutter repository. See also f: labels. c: proposal A detailed proposal for a change to Flutter team-framework Owned by Framework team and removed in triage Presently being triaged by the triage team labels May 13, 2024
@goderbauer goderbauer added P3 Issues that are less important to the Flutter project triaged-framework Triaged by Framework team labels May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: new feature Nothing broken; request for a new capability c: proposal A detailed proposal for a change to Flutter framework flutter/packages/flutter repository. See also f: labels. P3 Issues that are less important to the Flutter project team-framework Owned by Framework team triaged-framework Triaged by Framework team
Projects
None yet
Development

No branches or pull requests

3 participants