📱 Flutter
Intermediate
What is ValueNotifier in Flutter?
Answer
ValueNotifier is a specialized ChangeNotifier that holds a single value and automatically notifies its listeners whenever the value changes. Set the new value with notifier.value = newValue. It is a lightweight alternative to Provider for simple, local state: final counter = ValueNotifier<int>(0);. Use it with ValueListenableBuilder to rebuild only the widget that needs to react, avoiding unnecessary rebuilds of the full widget tree.