* add samples_index to web/ directory Co-authored-by: Thea Flowers <theaflowers@google.com> * add pub_get.dart script * build sample index in peanut post build * re-generate sample index with web demos * print more details in peanut_post_build.dart * add images for demos * run generator * update README * add animations and provider shopper as symlinks * add links to symlinked web demos * use relative paths * update cookbook images, urls, and description CSS * use relative URL for navbar link * unstage HTML files * .gitignore generated HTML files * add margin to toolbar * rename escape functions * add and update copyright headers Co-authored-by: Thea Flowers <theaflowers@google.com>
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
Providerfor providing an immutable value to a subtree - Illustrate a simple state management approach using the ChangeNotifier class
- Show use of
ProxyProviderfor 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:
- It will automatically subscribe to changes in
CartModel(if you only want this functionality simply useChangeNotifierProvider). - It takes the value of a previously provided object (in this case,
CatalogModel, provided just above), and uses it to build the value ofCartModel(if you only want this functionality, simply useProxyProvider).
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.