Managing state in Flutter with Provider (Version 3)

preview_player
Показать описание
There are several ways to manage state in Flutter. My personal favorite is a package called Provider. It allows you to inject the state into a widget and its children. This video will explain how to selectively rebuild widgets in a widget tree using the Provider, Consumer, and Selector classes. There is a lot more that isn't covered in this video, but this should get you comfortable with basics of the Provider package.

*Error around 14:50. I meant "enclosing widget", not "surrounding widget"

00:00 - Intro
00:40 - Reviewing the current code
02:11 Creating the first ChangeNotifier class (FoodNotifier)
04:25 Using ChangeNotifierProvider to register the FoodNotifier
05:34 Refactoring the home page to use the FoodNotifier
08:30 Showing the FoodNotifier list in the list page
10:27 Creating a 2nd Change Notifier (UserNotifier)
12:26 Using MultiProvider for multiple providers
14:00 Adding the UserNotifier to the List page
18:02 Using the Consumer widget
20:37 Explaining the very important 'listen' flag
21:42 Using the Selector widget
25:03 Using both the Consumer and Selector with the same ChangeNotifier

Рекомендации по теме
Комментарии
Автор

I'll be doing more Flutter videos on state in the future, including Bloc. Are there any issues you had with this video? I'm always looking for ways to improve so leave a comment with any criticisms.

TheFlutterFactory
Автор

Thank you for your up-to-date provider explanation! This was very helpful and easy to understand.

tarkkoprulu
Автор

Thank you a lot, the clearest explanaition, and you are also covered handling of multiple providers. Very helpful

SunFoxx_
Автор

The best video on provider for sure! Thanks!

tusharchander
Автор

I've recently started using provider package. This video is very helpful for me. Thanks a lot ❤️

TirthPatel
Автор

Best explanation. Finally understood the package, Thank You! ❤️

AamirKhan-zyyt
Автор

That was concise, clear and very helpful. Thanks

chrisogonas
Автор

This video is good. Helped me a lot.
Love from india

purushottampk
Автор

This is super helpful. Thanks for the effort!

rahulrvp
Автор

wow thanks man this really is starting to make sense

senayb
Автор

I enjoyed your video. Please do a follow up using the FutureBuilder. I'm trying to load in a json file to be used later on in the tree but it isn't rebuilding the children after the future completes. Thank you.

AlanTuringWannabe
Автор

Hi, thank for the video.
One question. do we really need a StatefulWidget around the form? wouldn't a Stateless + ChangeNotifierProvider be enough to track the state of a form ?

cvgaviao
Автор

7:17 setState() is unnecessary. ChangeNotifierProvider will listen for changes in the model object and it will rebuild widget.

dartcode
Автор

thanks this video really help me so much as beginner, compared to bloc, which is better? can we use both in same project?

ibnukhaldun
Автор

If you've read the Provider docs and provider counter-example from flutter on Github and you still in some doubt. I highly recommend this video (Y)

blockchainacademy.community
Автор

Thanks this video is so helpful, keep throwing info

monkeygames
Автор

Widget A.
Widget B.
Widget C.




Here when I update a state in Widget A with provider, the Widgets B and C rebuilds too.
So how to avoid unnecessary rebuilds in B and C ?

belqisshida
Автор

I wish this video can be part two, part 1 could be UI I would like to follow up from scratch

abdallahhussein
Автор

Is provider + stateless widget a good alternative to using stateful widgets ? Any suggestions ?

luckie
Автор

Great examples... "but wait people, there is more!"

GK-puyp