1
0
mirror of https://github.com/flutter/samples.git synced 2025-11-08 13:58:47 +00:00

Update for Flutter 3.10 beta (#1746)

## 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 `///`).
- [ ] All existing and new tests are passing.

---------

Co-authored-by: David Iglesias <ditman@gmail.com>
Co-authored-by: Mark Thompson <2554588+MarkTechson@users.noreply.github.com>
Co-authored-by: John Ryan <ryjohn@google.com>
This commit is contained in:
Brett Morgan
2023-05-11 06:16:31 +10:00
committed by GitHub
parent 474756ce04
commit 36e7a6ab04
188 changed files with 1779 additions and 1968 deletions

View File

@@ -30,14 +30,18 @@ class MyApp extends StatelessWidget {
debugShowCheckedModeBanner: false,
routerConfig: GoRouter(
routes: [
GoRoute(path: '/', builder: (_, __) => const ProductList(),
GoRoute(
path: '/',
builder: (_, __) => const ProductList(),
routes: [
GoRoute(path: ':id', builder: (_, __) => const ProductDetails()),
],
),
GoRoute(path: '/category/:category', builder: (_, __) => const ProductCategoryList()),
GoRoute(
path: '/category/:category',
builder: (_, __) => const ProductCategoryList()),
],
),
);
}
}
}

View File

@@ -264,18 +264,12 @@ class ProductsRepository {
}
}
String getCategoryTitle(Category category) {
switch(category) {
case Category.all:
return 'All';
case Category.accessories:
return 'Accessories';
case Category.clothing:
return 'Clothing';
case Category.home:
return 'Home Decorations';
}
}
String getCategoryTitle(Category category) => switch (category) {
Category.all => 'All',
Category.accessories => 'Accessories',
Category.clothing => 'Clothing',
Category.home => 'Home Decorations'
};
class Product {
const Product({

View File

@@ -26,18 +26,21 @@ class ProductCategoryList extends StatelessWidget {
Widget build(BuildContext context) {
final GoRouterState state = GoRouterState.of(context);
final Category category = Category.values.firstWhere(
(Category value) => value.toString().contains(state.params['category']!),
(Category value) =>
value.toString().contains(state.pathParameters['category']!),
orElse: () => Category.all,
);
final List<Widget> children = ProductsRepository.loadProducts(category: category)
.map<Widget>((Product p) => RowItem(product: p))
.toList();
final List<Widget> children =
ProductsRepository.loadProducts(category: category)
.map<Widget>((Product p) => RowItem(product: p))
.toList();
return Scaffold(
backgroundColor: Styles.scaffoldBackground,
body: CustomScrollView(
slivers: <Widget>[
SliverAppBar(
title: Text(getCategoryTitle(category), style: Styles.productListTitle),
title: Text(getCategoryTitle(category),
style: Styles.productListTitle),
backgroundColor: Styles.scaffoldAppBarBackground,
pinned: true,
),

View File

@@ -23,8 +23,9 @@ class ProductDetails extends StatelessWidget {
@override
Widget build(BuildContext context) {
final String currentId = GoRouterState.of(context).params['id']!;
final Product product = ProductsRepository.loadProduct(id: int.parse(currentId));
final String currentId = GoRouterState.of(context).pathParameters['id']!;
final Product product =
ProductsRepository.loadProduct(id: int.parse(currentId));
return Scaffold(
body: ListView(
children: <Widget>[
@@ -40,7 +41,7 @@ class ProductDetails extends StatelessWidget {
}
}
class ProductPicture extends StatelessWidget{
class ProductPicture extends StatelessWidget {
const ProductPicture({super.key, required this.product});
final Product product;
@@ -63,4 +64,4 @@ class ProductPicture extends StatelessWidget{
],
);
}
}
}

View File

@@ -24,8 +24,8 @@ class ProductList extends StatelessWidget {
@override
Widget build(BuildContext context) {
final List<Widget> children = ProductsRepository.loadProducts()
.map<Widget>((Product p) => RowItem(product: p))
.toList();
.map<Widget>((Product p) => RowItem(product: p))
.toList();
return Scaffold(
backgroundColor: Styles.scaffoldBackground,
body: CustomScrollView(

View File

@@ -19,7 +19,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
version: 1.0.0+1
environment:
sdk: '>=3.0.0-290.0.dev <4.0.0'
sdk: ^3.0.0-0
# Dependencies specify other packages that your package needs in order to work.
# To automatically upgrade your package dependencies to the latest versions
@@ -36,7 +36,7 @@ dependencies:
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
shrine_images: ^2.0.2
go_router: ^6.5.5
go_router: ^7.0.0
dev_dependencies:
flutter_test: