1
0
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:
Eric Windmill
2025-02-12 18:08:01 -05:00
committed by GitHub
parent d62c784789
commit 719fd72c38
685 changed files with 76244 additions and 53721 deletions

View File

@@ -18,10 +18,7 @@ void main() {
final itemFinder = find.byKey(const ValueKey('text_25'));
// Scroll until the item to be found appears.
await tester.scrollUntilVisible(
itemFinder,
500.0,
);
await tester.scrollUntilVisible(itemFinder, 500.0);
// Check if the item contains the correct text.
expect(tester.widget<Text>(itemFinder).data, 'Item 25');
@@ -52,8 +49,9 @@ void main() {
expect(find.text('Removed from favorites.'), findsOneWidget);
});
testWidgets('Verifying whether item gets added to favorites',
(tester) async {
testWidgets('Verifying whether item gets added to favorites', (
tester,
) async {
await tester.pumpWidget(const TestingApp());
// Add item to favorites.

View File

@@ -55,11 +55,7 @@ void main() {
await binding.watchPerformance(
() async {
// Create a list of icon keys.
final iconKeys = [
'icon_0',
'icon_1',
'icon_2',
];
final iconKeys = ['icon_0', 'icon_1', 'icon_2'];
// Add first three items to favorites.
for (var icon in iconKeys) {

View File

@@ -16,9 +16,7 @@ Widget createFavoritesScreen() => ChangeNotifierProvider<Favorites>(
favoritesList = Favorites();
return favoritesList;
},
child: const MaterialApp(
home: FavoritesPage(),
),
child: const MaterialApp(home: FavoritesPage()),
);
void main() {

View File

@@ -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),

View File

@@ -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),
),
);

View File

@@ -4,7 +4,7 @@ description: A sample that shows testing in Flutter.
version: 1.0.0+1
environment:
sdk: ^3.5.0
sdk: ^3.6.0
dependencies:
flutter:

View File

@@ -15,9 +15,7 @@ Widget createFavoritesScreen() => ChangeNotifierProvider<Favorites>(
favoritesList = Favorites();
return favoritesList;
},
child: const MaterialApp(
home: FavoritesPage(),
),
child: const MaterialApp(home: FavoritesPage()),
);
void addItems() {
@@ -28,8 +26,9 @@ void addItems() {
void main() {
group('Favorites Page Widget Tests', () {
testWidgets('Test if Placeholder shows in case of empty list',
(tester) async {
testWidgets('Test if Placeholder shows in case of empty list', (
tester,
) async {
await tester.pumpWidget(createFavoritesScreen());
// Verify if the placeholder text shows up.

View File

@@ -10,9 +10,7 @@ import 'package:testing_app/models/favorites.dart';
Widget createHomeScreen() => ChangeNotifierProvider<Favorites>(
create: (context) => Favorites(),
child: MaterialApp.router(
routerConfig: router(),
),
child: MaterialApp.router(routerConfig: router()),
);
void main() {