What method notifies widgets to rebuild in Provider?
ChangeNotifier.notifyListeners() tells all listening widgets to rebuild.
Use Provider for scalable state management
You can read this lesson publicly. Sign in to unlock exercises, quiz, and FX progress tracking.
Having trouble? AI is here to help
Ask context-aware questions about this lesson. Free plan: 5 questions/day. Upgrade to Premium for higher daily limits.
Use the AI button at the bottom of the screen
Provider is the recommended way to manage app state in Flutter. It wraps InheritedWidget behind a simple API so that any widget in the tree can access shared state without manual prop drilling through constructors.
1// 1. Create a state class with ChangeNotifier2class CartProvider extends ChangeNotifier {3List<String> _items = [];45List<String> get items => _items;6int get itemCount => _items.length;78void addItem(String item) {9_items.add(item);10notifyListeners(); // Notify widgets to rebuild11}1213void removeItem(String item) {14_items.remove(item);15notifyListeners();16}17}
1// 2. Provide it at the app level2void main() {3runApp(4ChangeNotifierProvider(5create: (context) => CartProvider(),6child: MyApp(),7),8);9}1011// Or multiple providers12runApp(13MultiProvider(14providers: [15ChangeNotifierProvider(create: (_) => CartProvider()),16ChangeNotifierProvider(create: (_) => AuthProvider()),17],18child: MyApp(),19),20);
1// 3. Consume the state in any widget2class CartScreen extends StatelessWidget {3@override4Widget build(BuildContext context) {5// Read state6final cart = Provider.of<CartProvider>(context);78// Or use Consumer for targeted rebuilds9return Consumer<CartProvider>(10builder: (context, cart, child) {11return Text('Items: ${cart.itemCount}');12},13);14}15}1617// Modify state18ElevatedButton(19onPressed: () {20Provider.of<CartProvider>(context, listen: false)21.addItem('Product');22},23child: Text('Add to Cart'),24)
Use listen: false when you only need to call methods and do not need the widget to rebuild on state changes. This avoids unnecessary rebuilds and is more efficient.
Keep provider classes focused on business state, not UI details.
This separation keeps provider logic unit-testable and prevents UI coupling inside state classes.
Use Provider for scalable state management. State is data that changes over time and controls what users see on the screen.
Connect each concept to real app features you can build.
Keep state as close as possible to where it is used, then lift it only when sharing is required.
State management is the difference between predictable apps and hard-to-debug UI behavior.
ChangeNotifier.notifyListeners() tells all listening widgets to rebuild.
Use listen: false when you do not need the widget to rebuild on state changes.
ChangeNotifier provides notifyListeners() method to trigger rebuilds in listening widgets.
MultiProvider wraps multiple ChangeNotifierProvider instances for cleaner code.
Something seems incorrect, unclear, or missing? Let us know.
FlutterCraft editorial lessons are reviewed by experienced Flutter developers and updated to stay aligned with modern Flutter and Dart best practices.
Reference docs: Flutter Documentation, Dart Language Tour, and official package documentation where relevant.
Sign in to continue with exercises and quiz for this lesson.
Sign In to Continue