Get immediate access to this and over 1,500+ other videos and books.

Boost your skills with a raywenderlich.com Beginner subscription. With over 60+ video courses and our core foundational programming books bundled in one subscription, it’s simply the best investment you can make in your development career.

Add a Value Notifier

This video was last updated on Sep 22 2022

In this episode, you’ll be introduced to the ValueNotifier. You’ll learn how it works and how to use it to manage your state.

Contributors

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.

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;
},

Reviews

Comments