Managing State in Flutter

Sep 22 2022 · Dart 2.17, Flutter 3.0, Android Studio Chipmunk

Part 1: Understand State Management

05. Add a Value Notifier

Episode complete

Play next episode

Next
About this episode
Leave a rating/review
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 04. Use Set State Next episode: 06. Extend a Value Notifier

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

As you know, setState is the method we call to let Flutter know that our state has changed. But in the previous example, our user interface only changed in one area when we want it change everywhere.

late ValueNotifier<int> valueNotifier;
@override
void initState() {
  super.initState();
}
void initState() {
  super.initState();
  valueNotifier = ValueNotifier<int>(pillarData.articleCount);
}
final ValueNotifier<int> valueNotifier;
const TutorialWidget(
      {required this.pillar, required this.valueNotifier, super.key});
final ValueNotifier<int> valueNotifier;
const TutorialsPage(
      {required this.pillar, required this.valueNotifier, super.key});
TutorialWidget(
              pillar: widget.pillar, valueNotifier: widget.valueNotifier),
TutorialsPage(pillar: pillarData, valueNotifier: valueNotifier),
valueNotifier.addListener(() {

});
setState(() {
  final increaseAmount = valueNotifier.value - pillarData.articleCount;
});
pillarData.increaseArticleCount(by: increaseAmount);
@override
void dispose() {
    valueNotifier.dispose();
    super.dispose();
}
onTap: () {
    widget.valueNotifier.value += 1;
},