mirror of
https://github.com/flutter/samples.git
synced 2026-05-13 10:27:09 +00:00
Follow best practice of ProxyProvider updating (#298)
* Upgrade to pkg:provider 4.0 * Follow best practice of ProxyProvider updating The addresses feedback from https://github.com/flutter/samples/issues/245. Instead of constructing a new `CartModel`, we merely update the `catalog` field. We no longer need a fancy constructor, and `CartModel._catalog` cannot be final any more.
This commit is contained in:
@@ -27,9 +27,11 @@ class MyApp extends StatelessWidget {
|
||||
// of ChangeNotifierProvider. Moreover, CartModel depends
|
||||
// on CatalogModel, so a ProxyProvider is needed.
|
||||
ChangeNotifierProxyProvider<CatalogModel, CartModel>(
|
||||
create: (context) => CartModel.empty(),
|
||||
update: (context, catalog, previousCart) =>
|
||||
CartModel(catalog, previousCart),
|
||||
create: (context) => CartModel(),
|
||||
update: (context, catalog, cart) {
|
||||
cart.catalog = catalog;
|
||||
return cart;
|
||||
},
|
||||
),
|
||||
],
|
||||
child: MaterialApp(
|
||||
|
||||
Reference in New Issue
Block a user