Problem Statement
How do you implement state management using Provider with ChangeNotifier? Explain the complete pattern.
Explanation
Start by creating a model class extending ChangeNotifier that holds your app state. Define properties for state data, methods to modify state, and call notifyListeners() after any state changes. For example, a CounterModel might have a count property and increment() method that increments count then calls notifyListeners() to notify listeners about the change.
Provide the model to your widget tree using ChangeNotifierProvider at an appropriate level - usually near the root for app-wide state or at a specific subtree root for feature-specific state. ChangeNotifierProvider creates the model instance, makes it available to descendants, and automatically disposes it when removed from the tree. Use the create parameter with a factory function to instantiate your model.
Consume the model in widgets using Consumer<CounterModel> for rebuilding when state changes, context.watch<CounterModel>() in build methods for convenient access with automatic rebuilds, or context.read<CounterModel>() in event handlers for accessing without listening. Consumer is best when only part of the widget needs rebuilding - pass non-dependent widgets as the child parameter to prevent rebuilding them.
For multiple models, use MultiProvider with a list of providers. For models depending on other models, use ProxyProvider to create a model based on another provider's value. This pattern separates business logic from UI, makes state testable by testing model classes independently, enables sharing state across multiple screens, and follows the MVVM architecture where models contain logic and views consume models reactively.

