mirror of
https://github.com/flutter/samples.git
synced 2026-04-20 14:03:38 +00:00
Landing beta changes in master for the new stable release (#747)
This commit is contained in:
@@ -30,6 +30,7 @@ class MyApp extends StatelessWidget {
|
||||
ChangeNotifierProxyProvider<CatalogModel, CartModel>(
|
||||
create: (context) => CartModel(),
|
||||
update: (context, catalog, cart) {
|
||||
if (cart == null) throw ArgumentError.notNull('cart');
|
||||
cart.catalog = catalog;
|
||||
return cart;
|
||||
},
|
||||
|
||||
@@ -7,7 +7,7 @@ import 'package:provider_shopper/models/catalog.dart';
|
||||
|
||||
class CartModel extends ChangeNotifier {
|
||||
/// The private field backing [catalog].
|
||||
CatalogModel _catalog;
|
||||
late CatalogModel _catalog;
|
||||
|
||||
/// Internal, private state of the cart. Stores the ids of each item.
|
||||
final List<int> _itemIds = [];
|
||||
@@ -16,9 +16,6 @@ class CartModel extends ChangeNotifier {
|
||||
CatalogModel get catalog => _catalog;
|
||||
|
||||
set catalog(CatalogModel newCatalog) {
|
||||
assert(newCatalog != null);
|
||||
assert(_itemIds.every((id) => newCatalog.getById(id) != null),
|
||||
'The catalog $newCatalog does not have one of $_itemIds in it.');
|
||||
_catalog = newCatalog;
|
||||
// Notify listeners, in case the new catalog provides information
|
||||
// different from the previous one. For example, availability of an item
|
||||
|
||||
@@ -65,7 +65,7 @@ class _CartTotal extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var hugeStyle =
|
||||
Theme.of(context).textTheme.headline1.copyWith(fontSize: 48);
|
||||
Theme.of(context).textTheme.headline1!.copyWith(fontSize: 48);
|
||||
|
||||
return SizedBox(
|
||||
height: 200,
|
||||
@@ -85,7 +85,7 @@ class _CartTotal extends StatelessWidget {
|
||||
SizedBox(width: 24),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Scaffold.of(context).showSnackBar(
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Buying not supported yet.')));
|
||||
},
|
||||
style: TextButton.styleFrom(primary: Colors.white),
|
||||
|
||||
@@ -28,7 +28,7 @@ class MyCatalog extends StatelessWidget {
|
||||
class _AddButton extends StatelessWidget {
|
||||
final Item item;
|
||||
|
||||
const _AddButton({Key key, @required this.item}) : super(key: key);
|
||||
const _AddButton({required this.item, Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -55,7 +55,7 @@ class _AddButton extends StatelessWidget {
|
||||
cart.add(item);
|
||||
},
|
||||
style: ButtonStyle(
|
||||
overlayColor: MaterialStateProperty.resolveWith<Color>((states) {
|
||||
overlayColor: MaterialStateProperty.resolveWith<Color?>((states) {
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
return Theme.of(context).primaryColor;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ class _MyAppBar extends StatelessWidget {
|
||||
class _MyListItem extends StatelessWidget {
|
||||
final int index;
|
||||
|
||||
_MyListItem(this.index, {Key key}) : super(key: key);
|
||||
_MyListItem(this.index, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
@@ -7,49 +7,49 @@ packages:
|
||||
name: async
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.5.0-nullsafety.3"
|
||||
version: "2.5.0"
|
||||
boolean_selector:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: boolean_selector
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0-nullsafety.3"
|
||||
version: "2.1.0"
|
||||
characters:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: characters
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.0-nullsafety.5"
|
||||
version: "1.1.0"
|
||||
charcode:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: charcode
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0-nullsafety.3"
|
||||
version: "1.2.0"
|
||||
clock:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: clock
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.0-nullsafety.3"
|
||||
version: "1.1.0"
|
||||
collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: collection
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.15.0-nullsafety.5"
|
||||
version: "1.15.0"
|
||||
fake_async:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: fake_async
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0-nullsafety.3"
|
||||
version: "1.2.0"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
@@ -66,42 +66,42 @@ packages:
|
||||
name: matcher
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.12.10-nullsafety.3"
|
||||
version: "0.12.10"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: meta
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.0-nullsafety.6"
|
||||
version: "1.3.0"
|
||||
nested:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: nested
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.0.4"
|
||||
version: "1.0.0"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.8.0-nullsafety.3"
|
||||
version: "1.8.0"
|
||||
pedantic:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: pedantic
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.9.2"
|
||||
version: "1.10.0"
|
||||
provider:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: provider
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "4.3.3"
|
||||
version: "5.0.0-nullsafety.5"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
@@ -113,56 +113,56 @@ packages:
|
||||
name: source_span
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.8.0-nullsafety.4"
|
||||
version: "1.8.0"
|
||||
stack_trace:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stack_trace
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.10.0-nullsafety.6"
|
||||
version: "1.10.0"
|
||||
stream_channel:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stream_channel
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0-nullsafety.3"
|
||||
version: "2.1.0"
|
||||
string_scanner:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: string_scanner
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.1.0-nullsafety.3"
|
||||
version: "1.1.0"
|
||||
term_glyph:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: term_glyph
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.2.0-nullsafety.3"
|
||||
version: "1.2.0"
|
||||
test_api:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: test_api
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.19-nullsafety.6"
|
||||
version: "0.2.19"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: typed_data
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.0-nullsafety.5"
|
||||
version: "1.3.0"
|
||||
vector_math:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: vector_math
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.0-nullsafety.5"
|
||||
version: "2.1.0"
|
||||
sdks:
|
||||
dart: ">=2.12.0-0.0 <3.0.0"
|
||||
dart: ">=2.12.0-259.16.beta <3.0.0"
|
||||
flutter: ">=1.16.0"
|
||||
|
||||
@@ -4,19 +4,19 @@ description: A shopping app sample that uses Provider for state management.
|
||||
version: 1.0.0+1
|
||||
|
||||
environment:
|
||||
sdk: ">=2.5.0 <3.0.0"
|
||||
sdk: '>=2.12.0-259.16.beta <3.0.0'
|
||||
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
|
||||
# Import the provider package.
|
||||
provider: ^4.3.2
|
||||
provider: '>=5.0.0-nullsafety.5 <6.0.0'
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
sdk: flutter
|
||||
pedantic: ^1.9.0
|
||||
pedantic: ^1.10.0
|
||||
|
||||
flutter:
|
||||
uses-material-design: true
|
||||
|
||||
@@ -9,8 +9,8 @@ import 'package:provider_shopper/models/cart.dart';
|
||||
import 'package:provider_shopper/models/catalog.dart';
|
||||
import 'package:provider_shopper/screens/cart.dart';
|
||||
|
||||
CartModel cartModel;
|
||||
CatalogModel catalogModel;
|
||||
CartModel? cartModel;
|
||||
CatalogModel? catalogModel;
|
||||
Widget createCartScreen() => MultiProvider(
|
||||
providers: [
|
||||
Provider(create: (context) => CatalogModel()),
|
||||
@@ -19,7 +19,7 @@ Widget createCartScreen() => MultiProvider(
|
||||
update: (context, catalog, cart) {
|
||||
catalogModel = catalog;
|
||||
cartModel = cart;
|
||||
cart.catalog = catalogModel;
|
||||
cart!.catalog = catalogModel!;
|
||||
return cart;
|
||||
},
|
||||
),
|
||||
@@ -48,8 +48,8 @@ void main() {
|
||||
|
||||
// Adding five items in the cart and testing.
|
||||
for (var i = 0; i < 5; i++) {
|
||||
var item = catalogModel.getByPosition(i);
|
||||
cartModel.add(item);
|
||||
var item = catalogModel!.getByPosition(i);
|
||||
cartModel!.add(item);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text(item.name), findsOneWidget);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ Widget createCatalogScreen() => MultiProvider(
|
||||
ChangeNotifierProxyProvider<CatalogModel, CartModel>(
|
||||
create: (context) => CartModel(),
|
||||
update: (context, catalog, cart) {
|
||||
cart.catalog = catalog;
|
||||
cart!.catalog = catalog;
|
||||
return cart;
|
||||
},
|
||||
),
|
||||
|
||||
@@ -18,7 +18,7 @@ void main() {
|
||||
ChangeNotifierProxyProvider<CatalogModel, CartModel>(
|
||||
create: (context) => CartModel(),
|
||||
update: (context, catalog, cart) {
|
||||
cart.catalog = catalog;
|
||||
cart!.catalog = catalog;
|
||||
return cart;
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user