What is Provider in Flutter?
Provider is a wrapper around InheritedWidget that helps manage and share app state efficiently.
Example:
In main:
Use in UI:
Provider is a wrapper around InheritedWidget that helps manage and share app state efficiently.
Example:
class Counter with ChangeNotifier { int count = 0; void increment() { count++; notifyListeners(); // UI refreshes } }
In main:
ChangeNotifierProvider( create: (_) => Counter(), child: MyApp(), );
Use in UI:
Consumer<Counter>( builder: (context, counter, child) => Text('${counter.count}'), );
Comments
Post a Comment