Exp 5b State Management in Flutter
Exp 5b State Management in Flutter
Example: setState
class CounterApp extends StatefulWidget {
int _count = 0;
Limitations of setState
1. Inefficient for sharing state across widgets.
2. Not scalable for large applications.
ChangeNotifier
• It is a class that provides notifications for changes
to its listeners.
ChangeNotifierProvider
• ChangeNotifierProvider is just a widget that
provides the instance of a ChangeNotifier.
Consumer
• It is a widget that contains a builder function and is
used to build the UI based on changes in the model.
Provider Example
class Counter with ChangeNotifier {
int _count = 0;
Conclusion
• Choose the right state management solution
based on app complexity and requirements: