You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
samples/provider_shopper
Brett Morgan 63235a729a
Update `pubspec.lock` and friends (#1076)
3 years ago
..
android Updated Android files (#1013) 3 years ago
fonts/Corben Add provider_shopper (#87) 5 years ago
ios Update `pubspec.lock` and friends (#1076) 3 years ago
lib rename constants (#1047) 3 years ago
linux Update `pubspec.lock` and friends (#1076) 3 years ago
macos Update `pubspec.lock` and friends (#1076) 3 years ago
test Updates for 2.8! (#961) 3 years ago
web Setup to handle app window on desktop (#1028) 3 years ago
windows Remove git:// url, update deps, fix `destop_photo_search` (#1052) 3 years ago
.gitignore Maintenance for provider_shopper (#168) 5 years ago
.metadata flutter pub update & various fixes (#627) 4 years ago
README.md Add provider_shopper (#87) 5 years ago
analysis_options.yaml Centralize analysis options (#957) 3 years ago
pubspec.lock Remove git:// url, update deps, fix `destop_photo_search` (#1052) 3 years ago
pubspec.yaml Remove git:// url, update deps, fix `destop_photo_search` (#1052) 3 years ago

README.md

provider_shopper

A Flutter sample app that shows a state management approach using the Provider package. This is the app discussed in the Simple app state management section of flutter.dev.

An animated gif of the app in action

Goals for this sample

  • Show simple use of Provider for providing an immutable value to a subtree
  • Illustrate a simple state management approach using the ChangeNotifier class
  • Show use of ProxyProvider for provided objects that depend on other provided objects

The important bits

lib/main.dart

Here the app sets up objects it needs to track state: a catalog and a shopping cart. It builds a MultiProvider to provide both objects at once to widgets further down the tree.

The CartModel instance is provided using a ChangeNotifierProxyProvider, which combines two types of functionality:

  1. It will automatically subscribe to changes in CartModel (if you only want this functionality simply use ChangeNotifierProvider).
  2. It takes the value of a previously provided object (in this case, CatalogModel, provided just above), and uses it to build the value of CartModel (if you only want this functionality, simply use ProxyProvider).

lib/models/*

This directory contains the model classes that are provided in main.dart. These classes represent the app state.

lib/screens/*

This directory contains widgets used to construct the two screens of the app: the catalog and the cart. These widgets have access to the current state of both the catalog and the cart via Provider.of.

Questions/issues

If you have a general question about Provider, the best places to go are:

If you run into an issue with the sample itself, please file an issue in the main Flutter repo.