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
Eric Windmill 3172aff8f8
Updates for 3.22 (#2266)
8 months ago
..
android Update Samples for 3.16 (#2085) 1 year ago
fonts/Corben Add provider_shopper (#87) 6 years ago
ios Update Samples for 3.16 (#2085) 1 year ago
lib Updates for 3.22 (#2266) 8 months ago
linux Update Samples for 3.16 (#2085) 1 year ago
macos Flutter beta (#1952) 1 year ago
test migrate provider_shopper to go_router (#1540) 2 years ago
web Flutter beta (#1952) 1 year ago
windows Update Samples for 3.16 (#2085) 1 year ago
.gitignore Update `provider_shopper` (#1445) 2 years ago
.metadata Fixup for failing Beta CI (#2092) 1 year ago
README.md Drop broken link (#1925) 2 years ago
analysis_options.yaml Create `analysis_defaults` package (#1654) 2 years ago
codelab_rebuild.yaml Update Samples for 3.16 (#2085) 1 year ago
pubspec.yaml Bump go_router from 13.2.5 to 14.0.0 in /provider_shopper (#2257) 8 months 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.

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.