State Management With Provider
See how to architect your Flutter app using Provider, letting you readily handle app state to update your UI when the app state changes. By Jonathan Sande.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
State Management With Provider
30 mins
- Getting Started
- Architecting Your App
- State Management and Provider
- Communicating With the Business Logic
- Creating the Core Business Logic
- Models
- View Models
- Services
- Creating an Abstract Service Class
- Using Fake Data
- Adding a Service Locator
- Registering FakeWebApi
- Concrete Web API Implementation
- Implementing Provider
- Becoming a Millionaire
- Using Provider in Large-Scale Apps
- Other Architectural and State Management Options
- Where to Go From Here?
Becoming a Millionaire
At the beginning, this tutorial promised to help you become a millionaire. The secret is to visit the right country. Use Moola X to check out various currencies. Then consider visiting the beautiful country of Indonesia, whose currency is the Rupiah.
According to Moola X at the time of this writing, you can be a millionaire there for only $72 US dollars. :]
Using Provider in Large-Scale Apps
You can follow the same architectural pattern in this tutorial to build apps with many, many different screens. Once you're comfortable making view models for each screen, you might want to create base classes to reduce the boilerplate code. This tutorial didn't do that because it makes it more difficult to understand what's happening.
Other Architectural and State Management Options
If you don't like the architecture this tutorial demonstrated, consider checking out the BLoC pattern. Our tutorial, Getting Started with the BLoC Pattern is, well, a good place to start. You'll probably find that BLoC isn't as hard as it sounds.
There are others, too, but Provider and BLoC are the two most popular.
Where to Go From Here?
Download the final project using the Download Materials button at the top or bottom of this tutorial.
If you want to learn more about architecture, state management and Provider, check out the following links:
- FilledStacks provided inspiration for the architecture in this tutorial. You'll find it helpful to check out their video, Flutter Architecture – My Provider Implementation Guide. The provider_architecture package just came out and you can learn more about it in the Medium article, A Beginner's Guide to Architecting a Flutter App.
- Learn as much as you can about clean code, design patterns, and architecture. Flutter TDD Clean Architecture Course by Reso Coder provides great examples of that.
- The official Flutter site's guide, Simple App State Management is a good read for understanding Provider.
- Watch the Manage State with Provider video series from raywenderlich.com. It explains Provider in much more depth.
- The Medium article, Making Sense of All Those Flutter Providers compares and explains the different types of Providers. If you want some simple copy-and-paste code to demonstrate how Provider works, that's the place to go.
Please leave a comment below if you have a question, find a problem or disagree with the architectural pattern that this tutorial used. Even if you don't have your own comment or question, you can check out what others are saying.