ChangeNotifierProvider

Consumer

ChangeNotifier

ChangeNotifier is a simple class included in the Flutter SDK which provides
change notification to its listeners. In other words, if something is
a ChangeNotifier, you can subscribe to its changes. (It is a form of
Observable, for those familiar with the term.)

In our shopping app example, we want to manage the state of the cart in a
ChangeNotifier. We create a new class that extends it, like so:

ChangeNotifier {
  /// Internal, private state of the cart.
  final List<Item> _items = [];

  /// An unmodifiable view of the items in the cart.
  UnmodifiableListView<Item> get items => UnmodifiableListView(_items);

  /// The current total price of all items (assuming all items cost $42).
  int get totalPrice => _items.length * 42;