You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ValueNotifier does not notify listeners when modifying a list #29958
You answered your own question. ValueNotifier doesn't make all object down the object tree observables ValueNotifier<List<String>> numbers
That's your observable value only.
What it does is just create a setter like: set value(T newValue) { if (_value == newValue) return; _value = newValue; notifyListeners(); } notifyListeners(); will notify listeners when the reference of `numbers.value' changes and nothing else
Reacted by Noah Fleischmann, Paul Iluhin, Ethan Petuchowski, Sanjay Parajuli, Alexander Kremenchuk, Viet Nguyen Tran and om-ha
Reacted by FlutterKoda, Mariano Zorrilla and hussamDana92
This can be resolved by calling valueNotifier.notifyListeners() after updating the elements of the value.
However, notifyListeners() is annotated as @protected, triggering IDE warnings. It would be nice if the annotation was removed as this issue describes a valid use-case to include it in the public interface.
Reacted by Denis Kolodin, Shawn, Jonathan Cole, Tony , Ádám Urbán, Will Spencer, Quyen Anh Nguyen, Alexander Melnikov, Nimish Nandwana, Anirudh and 32 more
Reacted by Nimish Nandwana, Najib Ghadri, Rageh ElAzzazy, Shubham Soni, Anyanwu Nzubechi Godswill, storm265 and GyuHyeon Choi
Reacted by Nimish Nandwana, Najib Ghadri, Rageh ElAzzazy, Peter Musembi, Shubham Soni, Gabriel Corrêa, Anyanwu Nzubechi Godswill and storm265
This would be nice to enable. Since ValueNotifier does not watch nested objects, a method should be provided to allow a developer to trigger manual notifications, in cases where we know we've modified some properties on the underlying value object.
Reacted by Leland Jobson , Hugo Delaunay, Nguyễn Việt Dũng, Tony , Thomas Burkhart, clragon, Arthur Araruna, om-ha, Grant Hutchison and Kristin Newman
Came here looking for a solution. A nice alternative to solve this might be Property Change Notifier. Use a custom add/remove method for a class that contains your list, and notify your listeners in those methods.
@ianspryn Property Change Notifier seems very good, but depending on a third party package just because there is a little @protected annotation is a bit annoying for me.
I have this problem, I have a ValueNotifier<List> variable that stores image paths to make a slide but it fails with ValueNotifier but works with StreamController
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
jonahwilliams commentedon Mar 26, 2019
This class is a good candidate for better documentation
alecorsino commentedon Jun 7, 2019
You answered your own question. ValueNotifier doesn't make all object down the object tree observables
ValueNotifier<List<String>> numbersThat's your observable value only.
What it does is just create a setter like:
set value(T newValue) { if (_value == newValue) return; _value = newValue; notifyListeners(); }notifyListeners();will notify listeners when the reference of `numbers.value' changes and nothing elsedsjgordon commentedon Sep 6, 2019
This can be resolved by calling
valueNotifier.notifyListeners()after updating the elements of the value.However,
notifyListeners()is annotated as@protected, triggering IDE warnings. It would be nice if the annotation was removed as this issue describes a valid use-case to include it in the public interface.cgestes commentedon Nov 3, 2019
Or we could modify the list in an immutable manner to ensure notifyListeners is called.
For example:
esDotDev commentedon Dec 12, 2019
This would be nice to enable. Since ValueNotifier does not watch nested objects, a method should be provided to allow a developer to trigger manual notifications, in cases where we know we've modified some properties on the underlying value object.
ianspryn commentedon Apr 6, 2020
Came here looking for a solution. A nice alternative to solve this might be Property Change Notifier. Use a custom add/remove method for a class that contains your list, and notify your listeners in those methods.
Skyost commentedon Apr 26, 2020
@ianspryn Property Change Notifier seems very good, but depending on a third party package just because there is a little
@protectedannotation is a bit annoying for me.gybin02 commentedon May 26, 2020
This would be nice to enable valueNotifier.notifyListeners() for developer.
this is like ObseravbleField from databinding in Android。
Why not just refresh the widget associated with valueNotifier.
And dispose them automatically when call super.disponse.
eg:
ObservableField firstName = new ObservableField<>();
gskinner-shared commentedon May 26, 2020
The trick is to just extend ValueNotifier, and provide a public Notify fxn that calls NotifyListeners.
apgapg commentedon Oct 12, 2020
As per @gskinner-shared suggestion you can use this
clragon commentedon Jan 22, 2021
that's not a bad solution, though it would still be alot nicer if it was like this by default.
14 remaining items
clragon commentedon Feb 10, 2022
or, instead of writing that helperclass, you can use
List.unmodifiable,so you always have to modify your list in an immutable manner.
viniciusddrft commentedon Mar 28, 2022
I have this problem, I have a ValueNotifier<List> variable that stores image paths to make a slide but it fails with ValueNotifier but works with StreamController
Here I just set my list
And here I passed the values to the ValueListenableBuilder.
carman247 commentedon Apr 25, 2022
Not sure why but I had to use the spread operator
e.g.
github-actions commentedon Apr 6, 2023
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.