1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 13:58:47 +00:00
Files
samples/provider_shopper
Brett Morgan 0ccc283a4e Fixup for failing Beta CI (#2092)
Turns out, we shipped a new Flutter beta as well. 

Commenting out `experimental/varfont_shader_puzzle` from beta CI

Everything else is just cleanup.

## Pre-launch Checklist

- [x] I read the [Flutter Style Guide] _recently_, and have followed its
advice.
- [x] I signed the [CLA].
- [x] I read the [Contributors Guide].
- [x] I updated/added relevant documentation (doc comments with `///`).
- [x] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-devrel
channel on [Discord].

<!-- Links -->
[Flutter Style Guide]:
https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo
[CLA]: https://cla.developers.google.com/
[Discord]: https://github.com/flutter/flutter/wiki/Chat
[Contributors Guide]:
https://github.com/flutter/samples/blob/main/CONTRIBUTING.md
2023-11-16 14:48:50 +10:00
..
2023-11-16 08:55:44 +10:00
2019-07-23 15:40:43 -07:00
2023-11-16 08:55:44 +10:00
2023-11-16 08:55:44 +10:00
2023-08-17 06:26:43 +10:00
2023-08-17 06:26:43 +10:00
2023-11-16 08:55:44 +10:00
2022-10-04 22:38:07 +10:00
2023-11-16 14:48:50 +10:00
2023-11-16 14:48:50 +10:00
2023-06-28 19:16:30 +10:00

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.