Moving from setState to Riverpod in Flutter Part 1
Vložit
- čas přidán 9. 07. 2024
- If you're interested in learning Riverpod, you've probably already learned a little bit about Provider. Riverpod was created by the same guy that created the Provider package. Also if you haven't notice, Riverpod is an anagram of Provider. This video will get you started with Riverpod and show you why it's a major upgrade from Provider.
00:00 - Intro
00:24 - Overview with the basic setState approach
04:09 - Creating a Provider, FutureProvider, and StreamProvider
08:29 - Showing a value using context.read()
10:00 - The Consumer widget and FutureProvider
15:47 - Using a StateNotifier to hold state
21:35 - Creating the StateNotifierProvider
23:05 - Adding list state
25:50 - Watching the list state
27:23 - Deleting list items and testing
30:28 - Use StreamProvider to display a stream of values
💻Follow along here with the initial code: github.com/theflutterfactory/...
⚡Connect on Facebook: / flutterfactory
⚡Connect on Twitter: / flutterfactory
🎷Music: www.bensound.com
Thanks man for the vid 🔥
You're welcome.
Thanks man,
Finally i found how to create and use StateNotifier effectively from this video
thanks a lot for this 🤞
Thank you so much, i really appreciate your work, it helps me a lot on my current project. Keep up the good work Master....
Great in depth, and to the point video!
Very nice tutorial! Thank you.
Great video. simply explained
Good work.thank you😀
I'm just looking for a way to manage state. I've tried bloc which I didn't like. Riverpod looks much more promising. This video definitely helped.
pls part 2
thaaaaankssss !!!
Thank you! Finally understood the basics thanks to this video! Now I can build my first app with the Future provider :)
In case userList is not working, add "as List" to userList-
final userList = ref.watch(userListProvider) as List;
awesome! my problem is solved.thank you so much
i love youuuuuuuuuuuuuu
Hello. Very useful video. Is it possible to make global provider (for example: when user tap on listview item, this value i want to show on every further screen. I tried make global provider inside OnTap method, but a i can't get access to it in another screen anyway )in one screen and get it's value on another screen? P:S: Sorry for my english )
thanks a lot for this amazing tutor. please how can someone use a boolean with either StateProvider or StateNotifierProvider, i have tried something like this "final isPro = StateProvider((ref) => false);" and tries to watch like this " bool test = watch(isPro);". . . so i got the error. "The argument type 'StateProvider' can't be assigned to the parameter type 'ProviderBase
26:30 they have changed something in the Matrix or just editing error😅
Weird, when I restart the application, it shows me this instead
Restarted application in 278ms.
flutter: Home rebuilding...
flutter: UserList rebuilding...
flutter: Home rebuilding...
flutter: UserList rebuilding...
I follow your video step by step, any idea?
I didn't optimize for rebuilds. That was my fault. I was too focused on the riverpod funcationality itself. One thing to note is that watching a provider at the top of your build function will rebuild the entire widget (and any child widgets)
Finally figured out "Why doesn't it work when I try it?" There are breaking code changes between the version of riverpod in the video (mid 2021) and v1.0.0 which came out in August 2021. It's almost impossible for video tutorials to stay up-to-date in the flutter world. Poor guy now has the choice: Reshoot the video so that it is once again a top tutorial for this package, or simply accept that it's "mostly correct, but won't actually run" if you install the latest version of riverpod.
Need more tutorial on flutter_riverpod.
Thank you.
soon
@@TheFlutterFactory hope you will share more series flutter_riverpod very soon and we are excting too much❤️
Your use of context.read() early in the screencast (around 8:30) to get the Cheetah Coding value is probably misleading. If the provider of that value ever changes the value, your view would *not* be updated. It should have used a "watch" instead. Remi has commented on this "fear of watch" behavior, even referencing it in the official docs.
For a constant value, it's ok here since the output will be the same. I get your point though. Old habits from Provider.
I appreciate all your input on this. I know you've been a big advocate for RiverPod online.
github link error
Thanks for letting me know. I just corrected the link