mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Flutter 3.29 beta (#2571)
This commit is contained in:
@@ -39,8 +39,9 @@ class MyApp extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
GoRoute(
|
||||
path: '/category/:category',
|
||||
builder: (_, __) => const ProductCategoryList()),
|
||||
path: '/category/:category',
|
||||
builder: (_, __) => const ProductCategoryList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -12,12 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
enum Category {
|
||||
all,
|
||||
accessories,
|
||||
clothing,
|
||||
home,
|
||||
}
|
||||
enum Category { all, accessories, clothing, home }
|
||||
|
||||
class ProductsRepository {
|
||||
static const _allProducts = <Product>[
|
||||
@@ -75,12 +70,7 @@ class ProductsRepository {
|
||||
name: 'Shrug bag',
|
||||
price: 198,
|
||||
),
|
||||
Product(
|
||||
category: Category.home,
|
||||
id: 9,
|
||||
name: 'Gilt desk trio',
|
||||
price: 58,
|
||||
),
|
||||
Product(category: Category.home, id: 9, name: 'Gilt desk trio', price: 58),
|
||||
Product(
|
||||
category: Category.home,
|
||||
id: 10,
|
||||
@@ -99,18 +89,8 @@ class ProductsRepository {
|
||||
name: 'Hurrahs tea set',
|
||||
price: 34,
|
||||
),
|
||||
Product(
|
||||
category: Category.home,
|
||||
id: 13,
|
||||
name: 'Blue stone mug',
|
||||
price: 18,
|
||||
),
|
||||
Product(
|
||||
category: Category.home,
|
||||
id: 14,
|
||||
name: 'Rainwater tray',
|
||||
price: 27,
|
||||
),
|
||||
Product(category: Category.home, id: 13, name: 'Blue stone mug', price: 18),
|
||||
Product(category: Category.home, id: 14, name: 'Rainwater tray', price: 27),
|
||||
Product(
|
||||
category: Category.home,
|
||||
id: 15,
|
||||
@@ -123,12 +103,7 @@ class ProductsRepository {
|
||||
name: 'Succulent planters',
|
||||
price: 16,
|
||||
),
|
||||
Product(
|
||||
category: Category.home,
|
||||
id: 17,
|
||||
name: 'Quartet table',
|
||||
price: 175,
|
||||
),
|
||||
Product(category: Category.home, id: 17, name: 'Quartet table', price: 175),
|
||||
Product(
|
||||
category: Category.home,
|
||||
id: 18,
|
||||
@@ -141,12 +116,7 @@ class ProductsRepository {
|
||||
name: 'Clay sweater',
|
||||
price: 48,
|
||||
),
|
||||
Product(
|
||||
category: Category.clothing,
|
||||
id: 20,
|
||||
name: 'Sea tunic',
|
||||
price: 45,
|
||||
),
|
||||
Product(category: Category.clothing, id: 20, name: 'Sea tunic', price: 45),
|
||||
Product(
|
||||
category: Category.clothing,
|
||||
id: 21,
|
||||
@@ -265,11 +235,11 @@ class ProductsRepository {
|
||||
}
|
||||
|
||||
String getCategoryTitle(Category category) => switch (category) {
|
||||
Category.all => 'All',
|
||||
Category.accessories => 'Accessories',
|
||||
Category.clothing => 'Clothing',
|
||||
Category.home => 'Home Decorations'
|
||||
};
|
||||
Category.all => 'All',
|
||||
Category.accessories => 'Accessories',
|
||||
Category.clothing => 'Clothing',
|
||||
Category.home => 'Home Decorations',
|
||||
};
|
||||
|
||||
class Product {
|
||||
const Product({
|
||||
|
||||
@@ -31,22 +31,22 @@ class ProductCategoryList extends StatelessWidget {
|
||||
orElse: () => Category.all,
|
||||
);
|
||||
final List<Widget> children =
|
||||
ProductsRepository.loadProducts(category: category)
|
||||
.map<Widget>((Product p) => RowItem(product: p))
|
||||
.toList();
|
||||
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,
|
||||
),
|
||||
SliverList(
|
||||
delegate: SliverChildListDelegate(children),
|
||||
),
|
||||
SliverList(delegate: SliverChildListDelegate(children)),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -24,8 +24,9 @@ class ProductDetails extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final String currentId = GoRouterState.of(context).pathParameters['id']!;
|
||||
final Product product =
|
||||
ProductsRepository.loadProduct(id: int.parse(currentId));
|
||||
final Product product = ProductsRepository.loadProduct(
|
||||
id: int.parse(currentId),
|
||||
);
|
||||
return Scaffold(
|
||||
body: ListView(
|
||||
children: <Widget>[
|
||||
|
||||
@@ -23,9 +23,10 @@ class ProductList extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final List<Widget> children = ProductsRepository.loadProducts()
|
||||
.map<Widget>((Product p) => RowItem(product: p))
|
||||
.toList();
|
||||
final List<Widget> children =
|
||||
ProductsRepository.loadProducts()
|
||||
.map<Widget>((Product p) => RowItem(product: p))
|
||||
.toList();
|
||||
return Scaffold(
|
||||
backgroundColor: Styles.scaffoldBackground,
|
||||
body: CustomScrollView(
|
||||
@@ -35,9 +36,7 @@ class ProductList extends StatelessWidget {
|
||||
backgroundColor: Styles.scaffoldAppBarBackground,
|
||||
pinned: true,
|
||||
),
|
||||
SliverList(
|
||||
delegate: SliverChildListDelegate(children),
|
||||
),
|
||||
SliverList(delegate: SliverChildListDelegate(children)),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -19,10 +19,7 @@ import 'model/products_repository.dart';
|
||||
import 'styles.dart';
|
||||
|
||||
class RowItem extends StatelessWidget {
|
||||
const RowItem({
|
||||
required this.product,
|
||||
super.key,
|
||||
});
|
||||
const RowItem({required this.product, super.key});
|
||||
|
||||
final Product product;
|
||||
|
||||
@@ -42,14 +39,8 @@ class RowItem extends StatelessWidget {
|
||||
height: 68,
|
||||
),
|
||||
),
|
||||
title: Text(
|
||||
product.name,
|
||||
style: Styles.productRowItemName,
|
||||
),
|
||||
subtitle: Text(
|
||||
'\$${product.price}',
|
||||
style: Styles.productRowItemPrice,
|
||||
),
|
||||
title: Text(product.name, style: Styles.productRowItemName),
|
||||
subtitle: Text('\$${product.price}', style: Styles.productRowItemPrice),
|
||||
onTap: () => context.push('/${product.id}'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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.5.0
|
||||
sdk: ^3.7.0-0
|
||||
|
||||
# Dependencies specify other packages that your package needs in order to work.
|
||||
# To automatically upgrade your package dependencies to the latest versions
|
||||
|
||||
Reference in New Issue
Block a user