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:
@@ -15,9 +15,7 @@ class FavoritesPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Favorites'),
|
||||
),
|
||||
appBar: AppBar(title: const Text('Favorites')),
|
||||
body: Consumer<Favorites>(
|
||||
builder: (context, value, child) => value.items.isNotEmpty
|
||||
? ListView.builder(
|
||||
@@ -26,9 +24,7 @@ class FavoritesPage extends StatelessWidget {
|
||||
itemBuilder: (context, index) =>
|
||||
FavoriteItemTile(value.items[index]),
|
||||
)
|
||||
: const Center(
|
||||
child: Text('No favorites added.'),
|
||||
),
|
||||
: const Center(child: Text('No favorites added.')),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -47,10 +43,7 @@ class FavoriteItemTile extends StatelessWidget {
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: Colors.primaries[itemNo % Colors.primaries.length],
|
||||
),
|
||||
title: Text(
|
||||
'Item $itemNo',
|
||||
key: Key('favorites_text_$itemNo'),
|
||||
),
|
||||
title: Text('Item $itemNo', key: Key('favorites_text_$itemNo')),
|
||||
trailing: IconButton(
|
||||
key: Key('remove_icon_$itemNo'),
|
||||
icon: const Icon(Icons.close),
|
||||
|
||||
@@ -54,10 +54,7 @@ class ItemTile extends StatelessWidget {
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: Colors.primaries[itemNo % Colors.primaries.length],
|
||||
),
|
||||
title: Text(
|
||||
'Item $itemNo',
|
||||
key: Key('text_$itemNo'),
|
||||
),
|
||||
title: Text('Item $itemNo', key: Key('text_$itemNo')),
|
||||
trailing: IconButton(
|
||||
key: Key('icon_$itemNo'),
|
||||
icon: favoritesList.items.contains(itemNo)
|
||||
@@ -69,9 +66,11 @@ class ItemTile extends StatelessWidget {
|
||||
: favoritesList.remove(itemNo);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(favoritesList.items.contains(itemNo)
|
||||
? 'Added to favorites.'
|
||||
: 'Removed from favorites.'),
|
||||
content: Text(
|
||||
favoritesList.items.contains(itemNo)
|
||||
? 'Added to favorites.'
|
||||
: 'Removed from favorites.',
|
||||
),
|
||||
duration: const Duration(seconds: 1),
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user