mirror of
https://github.com/flutter/samples.git
synced 2026-03-22 04:17:50 +00:00
Maintenance for provider_shopper (#168)
This commit is contained in:
@@ -27,8 +27,10 @@ class MyApp extends StatelessWidget {
|
||||
// of ChangeNotifierProvider. Moreover, CartModel depends
|
||||
// on CatalogModel, so a ProxyProvider is needed.
|
||||
ChangeNotifierProxyProvider<CatalogModel, CartModel>(
|
||||
builder: (context, catalog, previousCart) =>
|
||||
CartModel(catalog, previousCart)),
|
||||
initialBuilder: (context) => CartModel.empty(),
|
||||
builder: (context, catalog, previousCart) =>
|
||||
CartModel(catalog, previousCart),
|
||||
),
|
||||
],
|
||||
child: MaterialApp(
|
||||
title: 'Provider Demo',
|
||||
|
||||
@@ -15,12 +15,17 @@ class CartModel extends ChangeNotifier {
|
||||
/// Construct a CartModel instance that is backed by a [CatalogModel] and
|
||||
/// an optional previous state of the cart.
|
||||
///
|
||||
/// If [previous] is not `null`, it's items are copied to the newly
|
||||
/// If [previous] is not `null`, its items are copied to the newly
|
||||
/// constructed instance.
|
||||
CartModel(this._catalog, CartModel previous)
|
||||
: assert(_catalog != null),
|
||||
_itemIds = previous?._itemIds ?? [];
|
||||
|
||||
/// An empty cart with no Catalog.
|
||||
CartModel.empty()
|
||||
: _catalog = null,
|
||||
_itemIds = [];
|
||||
|
||||
/// List of items in the cart.
|
||||
List<Item> get items => _itemIds.map((id) => _catalog.getById(id)).toList();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user