Flutter Provider: The Essential Guide

Andrea Bizzotto · 70K views · 2019 · 17:12

Open on YouTube

Software architecture & designSoftware (other)tutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering Flutter state management questions, as a clear walkthrough of Provider and Consumer for sharing and rebuilding state across widgets.

Recommended by 3 people across 3 different months, 2019 to 2021.

What it is

A 17-minute Flutter tutorial by Andrea Bizzotto that refactors the default counter app to use the Provider package. It walks through ChangeNotifier, ChangeNotifierProvider, Provider.of, Consumer and ValueNotifier, including how ValueNotifier works under the hood.

What people said

Recommends serg · 2019-12 · Stack Overflow · on “Passing data between screens in Flutter”

Answers above are useful for a small app, but if you want to remove the headache of continuously worrying about a widgets state, Google presented the Provider package. [LINK] Have a look into that one, or watch these videos from Andrea Bizzotto: [this video] // Provider: The Essential Guide [LINK] // Provider: Introduction Learn how to use the Provider package, and you are set for life :)

Recommends Derence · 2020-04 · Stack Overflow · on “Should screens be Stateless or Stateful?”

And if you ever need to update something within a Stateless widget, you can use the Provider class and Consumer widget to update just the part you need updated, without having to use a Stateless widget. This video explains it well: [this video]

Recommends Derence · 2020-04 · Stack Overflow · on “Is it good practice to wrap StatefulWidgets inside StatelessWidgets?”

Thank you for your good question! The answer is to use the Provider [LINK] package and wrap the widget that needs to be changed in a Consumer widget. It listens for changes and rebuilds just what you need, without rebuilding the entire widget tree. This video explains it well: [this video]

Recommends Vofch · 2020-05 · Stack Overflow · on “Is there any way to share same data for multiple widgets?”

The best and easiest solution is to use the Provider [LINK] Package, where you can add on the top of your widgets list and using notifyListeners you can share the data all over your app. You can check here [this video] how to use it the right way.

Cites user15782390 · 2021-04 · Stack Overflow · on “Save values of variables while navigation in Flutter”

I am not sure if you specifically you need it to reset when the app relaunches or not but if it is fine if the value is preserved when you relaunch the app then here are a few options. Either way, you can reset the value when the app launches manually by setting it back to 0. The first and simplest way is to use the answer in this comment [LINK] . If you have both widgets in an IndexedStack (read more here [LINK] ) and then have the button change the stack index that would work but you would lose the benefit of page transition animations and this is a less performant option as your app grows because flutter has to run both widgets at the same time even if one isn't being used. A second more