Auto-format Framework (#160545)

This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
Michael Goderbauer
2024-12-19 12:06:21 -08:00
committed by GitHub
parent 8e0993eda8
commit 5491c8c146
4411 changed files with 455108 additions and 415991 deletions

View File

@@ -3,12 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/about/about_list_tile.0.dart'
as example;
import 'package:flutter_api_samples/material/about/about_list_tile.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('It should show the about dialog after clicking on the button', (WidgetTester tester) async {
testWidgets('It should show the about dialog after clicking on the button', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.AboutListTileExampleApp());
expect(find.widgetWithText(AppBar, 'Show About Example'), findsOne);
@@ -33,7 +34,9 @@ void main() {
);
});
testWidgets('It should show the about dialog after clicking on about list tile in the drawer', (WidgetTester tester) async {
testWidgets('It should show the about dialog after clicking on about list tile in the drawer', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.AboutListTileExampleApp());
expect(find.widgetWithText(AppBar, 'Show About Example'), findsOne);

View File

@@ -12,10 +12,7 @@ void main() {
expect(find.byType(DrawerButton), findsOneWidget);
final Icon drawerButtonIcon = tester.widget(
find.descendant(
of: find.byType(DrawerButton),
matching: find.byType(Icon),
),
find.descendant(of: find.byType(DrawerButton), matching: find.byType(Icon)),
);
expect(drawerButtonIcon.icon, Icons.segment);
@@ -25,19 +22,13 @@ void main() {
expect(find.byType(EndDrawerButton), findsOneWidget);
final Icon endDrawerButtonIcon = tester.widget(
find.descendant(
of: find.byType(EndDrawerButton),
matching: find.byType(Icon),
),
find.descendant(of: find.byType(EndDrawerButton), matching: find.byType(Icon)),
);
expect(endDrawerButtonIcon.icon, Icons.more_horiz);
expect(find.byType(BackButton), findsOneWidget);
final Icon backButtonIcon = tester.widget(
find.descendant(
of: find.byType(BackButton),
matching: find.byType(Icon),
),
find.descendant(of: find.byType(BackButton), matching: find.byType(Icon)),
);
expect(backButtonIcon.icon, Icons.arrow_back_ios_new_rounded);
});

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('ActionChip updates avatar when tapped', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ChipApp(),
);
await tester.pumpWidget(const example.ChipApp());
expect(find.byIcon(Icons.favorite_border), findsOneWidget);

View File

@@ -3,15 +3,12 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/animated_icon/animated_icon.0.dart'
as example;
import 'package:flutter_api_samples/material/animated_icon/animated_icon.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('AnimatedIcon animates', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AnimatedIconApp(),
);
await tester.pumpWidget(const example.AnimatedIconApp());
// Test the AnimatedIcon size.
final Size iconSize = tester.getSize(find.byType(AnimatedIcon));

View File

@@ -3,15 +3,12 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/animated_icon/animated_icons_data.0.dart'
as example;
import 'package:flutter_api_samples/material/animated_icon/animated_icons_data.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Show all the animated icons', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AnimatedIconApp(),
);
await tester.pumpWidget(const example.AnimatedIconApp());
// Check if the total number of AnimatedIcons matches the icons list.
expect(find.byType(AnimatedIcon, skipOffstage: false), findsNWidgets(example.iconsList.length));

View File

@@ -3,21 +3,19 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/app/app.0.dart'
as example;
import 'package:flutter_api_samples/material/app/app.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Theme animation can be customized using AnimationStyle', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MaterialAppExample(),
);
testWidgets('Theme animation can be customized using AnimationStyle', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.MaterialAppExample());
Material getScaffoldMaterial() {
return tester.widget<Material>(find.descendant(
of: find.byType(Scaffold),
matching: find.byType(Material).first,
));
return tester.widget<Material>(
find.descendant(of: find.byType(Scaffold), matching: find.byType(Material).first),
);
}
final ThemeData lightTheme = ThemeData(colorSchemeSeed: Colors.green);
@@ -29,7 +27,7 @@ void main() {
// Test the default animation.
expect(getScaffoldMaterial().color, lightTheme.colorScheme.surface);
await tester.tap(find.text( 'Switch Theme Mode'));
await tester.tap(find.text('Switch Theme Mode'));
await tester.pump();
// Advance the animation by half of the default duration.
await tester.pump(const Duration(milliseconds: 100));

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Appbar updates on navigation', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AppBarApp(),
);
await tester.pumpWidget(const example.AppBarApp());
expect(find.widgetWithText(AppBar, 'AppBar Demo'), findsOneWidget);
expect(find.text('This is the home page'), findsOneWidget);

View File

@@ -10,9 +10,7 @@ const Offset _kOffset = Offset(0.0, -100.0);
void main() {
testWidgets('Appbar Material 3 test', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AppBarApp()
);
await tester.pumpWidget(const example.AppBarApp());
expect(find.widgetWithText(AppBar, 'AppBar Demo'), findsOneWidget);
Material appbarMaterial = _getAppBarMaterial(tester);
@@ -47,9 +45,6 @@ void main() {
Material _getAppBarMaterial(WidgetTester tester) {
return tester.widget<Material>(
find.descendant(
of: find.byType(AppBar),
matching: find.byType(Material),
),
find.descendant(of: find.byType(AppBar), matching: find.byType(Material)),
);
}

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Appbar and actions', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AppBarApp(),
);
await tester.pumpWidget(const example.AppBarApp());
expect(find.byType(AppBar), findsOneWidget);
expect(find.widgetWithText(TextButton, 'Action 1'), findsOneWidget);

View File

@@ -7,25 +7,22 @@ import 'package:flutter_api_samples/material/app_bar/app_bar.3.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'AppBar elevates when nested scroll view is scrolled underneath the AppBar',
(WidgetTester tester) async {
Material getMaterial() => tester.widget<Material>(find.descendant(
of: find.byType(AppBar),
matching: find.byType(Material),
));
testWidgets('AppBar elevates when nested scroll view is scrolled underneath the AppBar', (
WidgetTester tester,
) async {
Material getMaterial() => tester.widget<Material>(
find.descendant(of: find.byType(AppBar), matching: find.byType(Material)),
);
await tester.pumpWidget(
const example.AppBarApp(),
);
await tester.pumpWidget(const example.AppBarApp());
// Starts with the base elevation.
expect(getMaterial().elevation, 0.0);
// Starts with the base elevation.
expect(getMaterial().elevation, 0.0);
await tester.fling(find.text('Beach 3'), const Offset(0.0, -600.0), 2000.0);
await tester.pumpAndSettle();
await tester.fling(find.text('Beach 3'), const Offset(0.0, -600.0), 2000.0);
await tester.pumpAndSettle();
// After scrolling it should be the scrolledUnderElevation.
expect(getMaterial().elevation, 4.0);
// After scrolling it should be the scrolledUnderElevation.
expect(getMaterial().elevation, 4.0);
});
}

View File

@@ -8,21 +8,16 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('AppBar uses custom shape', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AppBarExampleApp(),
);
await tester.pumpWidget(const example.AppBarExampleApp());
Material getMaterial() => tester.widget<Material>(find.descendant(
of: find.byType(AppBar),
matching: find.byType(Material),
));
Material getMaterial() => tester.widget<Material>(
find.descendant(of: find.byType(AppBar), matching: find.byType(Material)),
);
expect(getMaterial().shape, const example.CustomAppBarShape());
});
testWidgets('AppBar bottom contains TextField', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AppBarExampleApp(),
);
await tester.pumpWidget(const example.AppBarExampleApp());
final Finder textFieldFinder = find.descendant(
of: find.byType(AppBar),

View File

@@ -10,9 +10,7 @@ const Offset _kOffset = Offset(0.0, -200.0);
void main() {
testWidgets('SliverAppbar can be pinned', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AppBarApp(),
);
await tester.pumpWidget(const example.AppBarApp());
expect(find.widgetWithText(SliverAppBar, 'SliverAppBar'), findsOneWidget);
expect(tester.getBottomLeft(find.text('SliverAppBar')).dy, 144.0);

View File

@@ -12,15 +12,18 @@ void main() {
const String title = 'Medium App Bar';
expect(find.descendant(
of: find.byType(CustomScrollView),
matching: find.widgetWithText(SliverAppBar, title),
), findsOne);
expect(
find.descendant(
of: find.byType(CustomScrollView),
matching: find.widgetWithText(SliverAppBar, title),
),
findsOne,
);
expect(find.descendant(
of: find.byType(SliverAppBar),
matching: find.byType(IconButton),
), findsExactly(2));
expect(
find.descendant(of: find.byType(SliverAppBar), matching: find.byType(IconButton)),
findsExactly(2),
);
// Based on https://m3.material.io/components/top-app-bar/specs the title of
// the SliverAppBar.medium widget is formatted with the headlineSmall style.

View File

@@ -12,15 +12,18 @@ void main() {
const String title = 'Large App Bar';
expect(find.descendant(
of: find.byType(CustomScrollView),
matching: find.widgetWithText(SliverAppBar, title),
), findsOne);
expect(
find.descendant(
of: find.byType(CustomScrollView),
matching: find.widgetWithText(SliverAppBar, title),
),
findsOne,
);
expect(find.descendant(
of: find.byType(SliverAppBar),
matching: find.byType(IconButton),
), findsExactly(2));
expect(
find.descendant(of: find.byType(SliverAppBar), matching: find.byType(IconButton)),
findsExactly(2),
);
// Based on https://m3.material.io/components/top-app-bar/specs the title of
// the SliverAppBar.large widget is formatted with the headlineMedium style.

View File

@@ -3,17 +3,14 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/app_bar/sliver_app_bar.4.dart'
as example;
import 'package:flutter_api_samples/material/app_bar/sliver_app_bar.4.dart' as example;
import 'package:flutter_test/flutter_test.dart';
const Offset _kOffset = Offset(0.0, 200.0);
void main() {
testWidgets('SliverAppbar can be stretched', (WidgetTester tester) async {
await tester.pumpWidget(
const example.StretchableSliverAppBar(),
);
await tester.pumpWidget(const example.StretchableSliverAppBar());
final Finder switchFinder = find.byType(Switch);
Switch materialSwitch = tester.widget<Switch>(switchFinder);
@@ -22,21 +19,18 @@ void main() {
expect(find.widgetWithText(SliverAppBar, 'SliverAppBar'), findsOneWidget);
expect(tester.getBottomLeft(find.text('SliverAppBar')).dy, 184.0);
await tester.drag(find.text('0'), _kOffset,
touchSlopY: 0, warnIfMissed: false);
await tester.drag(find.text('0'), _kOffset, touchSlopY: 0, warnIfMissed: false);
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
expect(find.widgetWithText(SliverAppBar, 'SliverAppBar'), findsOneWidget);
expect(
tester.getBottomLeft(find.text('SliverAppBar')).dy, 187.63506380825314);
expect(tester.getBottomLeft(find.text('SliverAppBar')).dy, 187.63506380825314);
await tester.tap(switchFinder);
await tester.pumpAndSettle();
materialSwitch = tester.widget<Switch>(switchFinder);
expect(materialSwitch.value, false);
await tester.drag(find.text('0'), _kOffset,
touchSlopY: 0, warnIfMissed: false);
await tester.drag(find.text('0'), _kOffset, touchSlopY: 0, warnIfMissed: false);
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));

View File

@@ -7,7 +7,9 @@ import 'package:flutter_api_samples/material/autocomplete/autocomplete.2.dart' a
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('can search and find options after waiting for fake network delay', (WidgetTester tester) async {
testWidgets('can search and find options after waiting for fake network delay', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.AutocompleteExampleApp());
expect(find.text('aardvark'), findsNothing);

View File

@@ -7,34 +7,37 @@ import 'package:flutter_api_samples/material/autocomplete/autocomplete.3.dart' a
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('can search and find options after waiting for fake network delay and debounce delay', (WidgetTester tester) async {
await tester.pumpWidget(const example.AutocompleteExampleApp());
testWidgets(
'can search and find options after waiting for fake network delay and debounce delay',
(WidgetTester tester) async {
await tester.pumpWidget(const example.AutocompleteExampleApp());
expect(find.text('aardvark'), findsNothing);
expect(find.text('bobcat'), findsNothing);
expect(find.text('chameleon'), findsNothing);
expect(find.text('aardvark'), findsNothing);
expect(find.text('bobcat'), findsNothing);
expect(find.text('chameleon'), findsNothing);
await tester.enterText(find.byType(TextFormField), 'a');
await tester.pump(example.fakeAPIDuration);
await tester.enterText(find.byType(TextFormField), 'a');
await tester.pump(example.fakeAPIDuration);
// No results yet, need to also wait for the debounce duration.
expect(find.text('aardvark'), findsNothing);
expect(find.text('bobcat'), findsNothing);
expect(find.text('chameleon'), findsNothing);
// No results yet, need to also wait for the debounce duration.
expect(find.text('aardvark'), findsNothing);
expect(find.text('bobcat'), findsNothing);
expect(find.text('chameleon'), findsNothing);
await tester.pump(example.debounceDuration);
await tester.pump(example.debounceDuration);
expect(find.text('aardvark'), findsOneWidget);
expect(find.text('bobcat'), findsOneWidget);
expect(find.text('chameleon'), findsOneWidget);
expect(find.text('aardvark'), findsOneWidget);
expect(find.text('bobcat'), findsOneWidget);
expect(find.text('chameleon'), findsOneWidget);
await tester.enterText(find.byType(TextFormField), 'aa');
await tester.pump(example.debounceDuration + example.fakeAPIDuration);
await tester.enterText(find.byType(TextFormField), 'aa');
await tester.pump(example.debounceDuration + example.fakeAPIDuration);
expect(find.text('aardvark'), findsOneWidget);
expect(find.text('bobcat'), findsNothing);
expect(find.text('chameleon'), findsNothing);
});
expect(find.text('aardvark'), findsOneWidget);
expect(find.text('bobcat'), findsNothing);
expect(find.text('chameleon'), findsNothing);
},
);
testWidgets('debounce is reset each time a character is entered', (WidgetTester tester) async {
await tester.pumpWidget(const example.AutocompleteExampleApp());

View File

@@ -7,34 +7,37 @@ import 'package:flutter_api_samples/material/autocomplete/autocomplete.4.dart' a
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('can search and find options after waiting for fake network delay and debounce delay', (WidgetTester tester) async {
await tester.pumpWidget(const example.AutocompleteExampleApp());
testWidgets(
'can search and find options after waiting for fake network delay and debounce delay',
(WidgetTester tester) async {
await tester.pumpWidget(const example.AutocompleteExampleApp());
expect(find.text('aardvark'), findsNothing);
expect(find.text('bobcat'), findsNothing);
expect(find.text('chameleon'), findsNothing);
expect(find.text('aardvark'), findsNothing);
expect(find.text('bobcat'), findsNothing);
expect(find.text('chameleon'), findsNothing);
await tester.enterText(find.byType(TextFormField), 'a');
await tester.pump(example.fakeAPIDuration);
await tester.enterText(find.byType(TextFormField), 'a');
await tester.pump(example.fakeAPIDuration);
// No results yet, need to also wait for the debounce duration.
expect(find.text('aardvark'), findsNothing);
expect(find.text('bobcat'), findsNothing);
expect(find.text('chameleon'), findsNothing);
// No results yet, need to also wait for the debounce duration.
expect(find.text('aardvark'), findsNothing);
expect(find.text('bobcat'), findsNothing);
expect(find.text('chameleon'), findsNothing);
await tester.pump(example.debounceDuration);
await tester.pump(example.debounceDuration);
expect(find.text('aardvark'), findsOneWidget);
expect(find.text('bobcat'), findsOneWidget);
expect(find.text('chameleon'), findsOneWidget);
expect(find.text('aardvark'), findsOneWidget);
expect(find.text('bobcat'), findsOneWidget);
expect(find.text('chameleon'), findsOneWidget);
await tester.enterText(find.byType(TextFormField), 'aa');
await tester.pump(example.debounceDuration + example.fakeAPIDuration);
await tester.enterText(find.byType(TextFormField), 'aa');
await tester.pump(example.debounceDuration + example.fakeAPIDuration);
expect(find.text('aardvark'), findsOneWidget);
expect(find.text('bobcat'), findsNothing);
expect(find.text('chameleon'), findsNothing);
});
expect(find.text('aardvark'), findsOneWidget);
expect(find.text('bobcat'), findsNothing);
expect(find.text('chameleon'), findsNothing);
},
);
testWidgets('debounce is reset each time a character is entered', (WidgetTester tester) async {
await tester.pumpWidget(const example.AutocompleteExampleApp());

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Verify Badges have label and count', (WidgetTester tester) async {
await tester.pumpWidget(
const example.BadgeExampleApp(),
);
await tester.pumpWidget(const example.BadgeExampleApp());
// Verify that two Badge(s) are present
expect(find.byType(Badge), findsNWidgets(2));

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Shows all elements', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MaterialBannerExampleApp(),
);
await tester.pumpWidget(const example.MaterialBannerExampleApp());
expect(find.byType(MaterialBanner), findsOneWidget);
expect(find.byType(AppBar), findsOneWidget);
@@ -23,9 +21,7 @@ void main() {
});
testWidgets('BottomNavigationBar Updates Screen Content', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MaterialBannerExampleApp(),
);
await tester.pumpWidget(const example.MaterialBannerExampleApp());
expect(find.byType(MaterialBanner), findsOne);
expect(find.text('Hello, I am a Material Banner'), findsOne);
@@ -35,9 +31,7 @@ void main() {
});
testWidgets('The banner is below the text saying so', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MaterialBannerExampleApp(),
);
await tester.pumpWidget(const example.MaterialBannerExampleApp());
expect(find.byType(MaterialBanner), findsOneWidget);
expect(find.text('The MaterialBanner is below'), findsOneWidget);

View File

@@ -3,8 +3,7 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/banner/material_banner.1.dart'
as example;
import 'package:flutter_api_samples/material/banner/material_banner.1.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
@@ -23,16 +22,12 @@ void main() {
expect(find.text('DISMISS'), findsOneWidget);
expect(find.byIcon(Icons.agriculture_outlined), findsOneWidget);
final MaterialBanner banner = tester.widget<MaterialBanner>(
find.byType(MaterialBanner),
);
final MaterialBanner banner = tester.widget<MaterialBanner>(find.byType(MaterialBanner));
expect(banner.backgroundColor, Colors.green);
});
testWidgets('BottomNavigationBar Updates Screen Content', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MaterialBannerExampleApp(),
);
await tester.pumpWidget(const example.MaterialBannerExampleApp());
expect(find.byType(MaterialBanner), findsNothing);
await tester.tap(find.widgetWithText(ElevatedButton, 'Show MaterialBanner'));

View File

@@ -3,25 +3,23 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/bottom_app_bar/bottom_app_bar.1.dart'
as example;
import 'package:flutter_api_samples/material/bottom_app_bar/bottom_app_bar.1.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'BottomAppBarDemo shows FloatingActionButton and responds to toggle',
(WidgetTester tester) async {
await tester.pumpWidget(const example.BottomAppBarDemo());
testWidgets('BottomAppBarDemo shows FloatingActionButton and responds to toggle', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.BottomAppBarDemo());
expect(find.byType(FloatingActionButton), findsOneWidget);
expect(find.byType(FloatingActionButton), findsOneWidget);
// Tap the 'Floating Action Button' switch to hide the FAB.
await tester.tap(find.byType(SwitchListTile).first);
await tester.pumpAndSettle();
// Tap the 'Floating Action Button' switch to hide the FAB.
await tester.tap(find.byType(SwitchListTile).first);
await tester.pumpAndSettle();
expect(find.byType(FloatingActionButton), findsNothing);
},
);
expect(find.byType(FloatingActionButton), findsNothing);
});
testWidgets('Notch can be toggled on and off', (WidgetTester tester) async {
await tester.pumpWidget(const example.BottomAppBarDemo());
@@ -41,26 +39,18 @@ void main() {
testWidgets('FAB location can be changed', (WidgetTester tester) async {
await tester.pumpWidget(const example.BottomAppBarDemo());
final Offset initialPosition =
tester.getCenter(find.byType(FloatingActionButton));
final Offset initialPosition = tester.getCenter(find.byType(FloatingActionButton));
// Verify the initial position is near the right side (docked to the end).
final Size screenSize = tester.getSize(
find.byType(Scaffold),
);
expect(
initialPosition.dx,
greaterThan(screenSize.width * 0.5),
);
final Size screenSize = tester.getSize(find.byType(Scaffold));
expect(initialPosition.dx, greaterThan(screenSize.width * 0.5));
// Tap the radio button to move the FAB to centerDocked.
await tester.tap(find.text('Docked - Center'));
await tester.pumpAndSettle();
// Get the new FAB position (centerDocked).
final Offset newPosition = tester.getCenter(
find.byType(FloatingActionButton),
);
final Offset newPosition = tester.getCenter(find.byType(FloatingActionButton));
expect(
newPosition.dx,

View File

@@ -3,93 +3,71 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/bottom_app_bar/bottom_app_bar.2.dart'
as example;
import 'package:flutter_api_samples/material/bottom_app_bar/bottom_app_bar.2.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'Floating Action Button visibility can be toggled',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.BottomAppBarDemo(),
);
testWidgets('Floating Action Button visibility can be toggled', (WidgetTester tester) async {
await tester.pumpWidget(const example.BottomAppBarDemo());
expect(find.byType(FloatingActionButton), findsOneWidget);
expect(find.byType(FloatingActionButton), findsOneWidget);
// Tap the switch to hide the FAB.
await tester.tap(find.byType(SwitchListTile).first);
await tester.pumpAndSettle();
// Tap the switch to hide the FAB.
await tester.tap(find.byType(SwitchListTile).first);
await tester.pumpAndSettle();
expect(find.byType(FloatingActionButton), findsNothing);
},
);
expect(find.byType(FloatingActionButton), findsNothing);
});
testWidgets('BottomAppBar elevation can be toggled',
(WidgetTester tester) async {
testWidgets('BottomAppBar elevation can be toggled', (WidgetTester tester) async {
// Build the app.
await tester.pumpWidget(const example.BottomAppBarDemo());
// Verify the BottomAppBar has elevation initially.
BottomAppBar bottomAppBar = tester.widget(
find.byType(BottomAppBar),
);
BottomAppBar bottomAppBar = tester.widget(find.byType(BottomAppBar));
expect(bottomAppBar.elevation, isNot(0.0));
await tester.tap(find.text('Bottom App Bar Elevation'));
await tester.pumpAndSettle();
bottomAppBar = tester.widget(
find.byType(BottomAppBar),
);
bottomAppBar = tester.widget(find.byType(BottomAppBar));
expect(bottomAppBar.elevation, equals(0.0));
});
testWidgets(
'BottomAppBar hides on scroll down and shows on scroll up',
(WidgetTester tester) async {
await tester.pumpWidget(const example.BottomAppBarDemo());
testWidgets('BottomAppBar hides on scroll down and shows on scroll up', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.BottomAppBarDemo());
// Ensure the BottomAppBar is visible initially.
expect(find.byType(BottomAppBar), findsOneWidget);
// Ensure the BottomAppBar is visible initially.
expect(find.byType(BottomAppBar), findsOneWidget);
// Scroll down to hide the BottomAppBar.
await tester.drag(
find.byType(ListView),
const Offset(0, -300),
);
await tester.pumpAndSettle();
// Scroll down to hide the BottomAppBar.
await tester.drag(find.byType(ListView), const Offset(0, -300));
await tester.pumpAndSettle();
// Verify the BottomAppBar is hidden.
final Size hiddenSize = tester.getSize(
find.byType(AnimatedContainer),
);
expect(hiddenSize.height, equals(0.0)); // AnimatedContainer's height
// Verify the BottomAppBar is hidden.
final Size hiddenSize = tester.getSize(find.byType(AnimatedContainer));
expect(hiddenSize.height, equals(0.0)); // AnimatedContainer's height
// Scroll up to show the BottomAppBar again.
await tester.drag(find.byType(ListView), const Offset(0, 300));
await tester.pumpAndSettle();
// Scroll up to show the BottomAppBar again.
await tester.drag(find.byType(ListView), const Offset(0, 300));
await tester.pumpAndSettle();
// Verify the BottomAppBar is visible again.
final Size visibleSize = tester.getSize(
find.byType(AnimatedContainer),
);
expect(visibleSize.height, equals(80.0));
},
);
// Verify the BottomAppBar is visible again.
final Size visibleSize = tester.getSize(find.byType(AnimatedContainer));
expect(visibleSize.height, equals(80.0));
});
testWidgets(
'SnackBar is shown when Open popup menu is pressed',
(WidgetTester tester) async {
await tester.pumpWidget(const example.BottomAppBarDemo());
testWidgets('SnackBar is shown when Open popup menu is pressed', (WidgetTester tester) async {
await tester.pumpWidget(const example.BottomAppBarDemo());
// Trigger the SnackBar.
await tester.tap(find.byTooltip('Open popup menu'));
await tester.pump();
// Trigger the SnackBar.
await tester.tap(find.byTooltip('Open popup menu'));
await tester.pump();
expect(find.text('Yay! A SnackBar!'), findsOneWidget);
expect(find.text('Yay! A SnackBar!'), findsOneWidget);
expect(find.text('Undo'), findsOneWidget);
},
);
expect(find.text('Undo'), findsOneWidget);
});
}

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/bottom_navigation_bar/bottom_navigation_bar.0.dart' as example;
import 'package:flutter_api_samples/material/bottom_navigation_bar/bottom_navigation_bar.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('BottomNavigationBar Updates Screen Content', (WidgetTester tester) async {
await tester.pumpWidget(
const example.BottomNavigationBarExampleApp(),
);
await tester.pumpWidget(const example.BottomNavigationBarExampleApp());
expect(find.widgetWithText(AppBar, 'BottomNavigationBar Sample'), findsOneWidget);
expect(find.byType(BottomNavigationBar), findsOneWidget);

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/bottom_navigation_bar/bottom_navigation_bar.1.dart' as example;
import 'package:flutter_api_samples/material/bottom_navigation_bar/bottom_navigation_bar.1.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('BottomNavigationBar Updates Screen Content', (WidgetTester tester) async {
await tester.pumpWidget(
const example.BottomNavigationBarExampleApp(),
);
await tester.pumpWidget(const example.BottomNavigationBarExampleApp());
expect(find.widgetWithText(AppBar, 'BottomNavigationBar Sample'), findsOneWidget);
expect(find.byType(BottomNavigationBar), findsOneWidget);

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/bottom_navigation_bar/bottom_navigation_bar.2.dart' as example;
import 'package:flutter_api_samples/material/bottom_navigation_bar/bottom_navigation_bar.2.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('BottomNavigationBar Updates Screen Content', (WidgetTester tester) async {
await tester.pumpWidget(
const example.BottomNavigationBarExampleApp(),
);
await tester.pumpWidget(const example.BottomNavigationBarExampleApp());
expect(find.widgetWithText(AppBar, 'BottomNavigationBar Sample'), findsOneWidget);
expect(find.byType(BottomNavigationBar), findsOneWidget);

View File

@@ -7,10 +7,10 @@ import 'package:flutter_api_samples/material/bottom_sheet/show_bottom_sheet.0.da
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Bottom sheet animation can be customized using AnimationStyle', (WidgetTester tester) async {
await tester.pumpWidget(
const example.BottomSheetExampleApp(),
);
testWidgets('Bottom sheet animation can be customized using AnimationStyle', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.BottomSheetExampleApp());
// Show the bottom sheet with default animation style.
await tester.tap(find.widgetWithText(ElevatedButton, 'showBottomSheet'));

View File

@@ -3,7 +3,8 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/bottom_sheet/show_modal_bottom_sheet.0.dart' as example;
import 'package:flutter_api_samples/material/bottom_sheet/show_modal_bottom_sheet.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
@@ -11,9 +12,7 @@ void main() {
const String titleText = 'Modal BottomSheet';
const String closeText = 'Close BottomSheet';
await tester.pumpWidget(
const example.BottomSheetApp(),
);
await tester.pumpWidget(const example.BottomSheetApp());
expect(find.text(titleText), findsNothing);
expect(find.text(closeText), findsNothing);

View File

@@ -3,7 +3,8 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/bottom_sheet/show_modal_bottom_sheet.1.dart' as example;
import 'package:flutter_api_samples/material/bottom_sheet/show_modal_bottom_sheet.1.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
@@ -11,9 +12,7 @@ void main() {
const String titleText = 'Modal BottomSheet';
const String closeText = 'Close BottomSheet';
await tester.pumpWidget(
const example.BottomSheetApp(),
);
await tester.pumpWidget(const example.BottomSheetApp());
expect(find.text(titleText), findsNothing);
expect(find.text(closeText), findsNothing);

View File

@@ -3,14 +3,15 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/bottom_sheet/show_modal_bottom_sheet.2.dart' as example;
import 'package:flutter_api_samples/material/bottom_sheet/show_modal_bottom_sheet.2.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Modal bottom sheet animation can be customized using AnimationStyle', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ModalBottomSheetApp(),
);
testWidgets('Modal bottom sheet animation can be customized using AnimationStyle', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.ModalBottomSheetApp());
// Show the bottom sheet with default animation style.
await tester.tap(find.widgetWithText(ElevatedButton, 'showModalBottomSheet'));

View File

@@ -3,72 +3,72 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/button_style/button_style.0.dart'
as example;
import 'package:flutter_api_samples/material/button_style/button_style.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'Shows ElevatedButtons, FilledButtons, OutlinedButtons and TextButtons in enabled and disabled states',
(WidgetTester tester) async {
await tester.pumpWidget(const example.ButtonApp());
'Shows ElevatedButtons, FilledButtons, OutlinedButtons and TextButtons in enabled and disabled states',
(WidgetTester tester) async {
await tester.pumpWidget(const example.ButtonApp());
expect(
find.byWidgetPredicate((Widget widget) {
return widget is ElevatedButton && widget.onPressed == null;
}),
findsOne,
);
expect(
find.byWidgetPredicate((Widget widget) {
return widget is ElevatedButton && widget.onPressed == null;
}),
findsOne,
);
expect(
find.byWidgetPredicate((Widget widget) {
return widget is ElevatedButton && widget.onPressed != null;
}),
findsOne,
);
expect(
find.byWidgetPredicate((Widget widget) {
return widget is ElevatedButton && widget.onPressed != null;
}),
findsOne,
);
// One OutlinedButton with onPressed null.
expect(
find.byWidgetPredicate((Widget widget) {
return widget is OutlinedButton && widget.onPressed == null;
}),
findsOne,
);
// One OutlinedButton with onPressed null.
expect(
find.byWidgetPredicate((Widget widget) {
return widget is OutlinedButton && widget.onPressed == null;
}),
findsOne,
);
// One OutlinedButton with onPressed not null.
expect(
find.byWidgetPredicate((Widget widget) {
return widget is OutlinedButton && widget.onPressed != null;
}),
findsOne,
);
// One OutlinedButton with onPressed not null.
expect(
find.byWidgetPredicate((Widget widget) {
return widget is OutlinedButton && widget.onPressed != null;
}),
findsOne,
);
expect(
find.byWidgetPredicate((Widget widget) {
return widget is TextButton && widget.onPressed == null;
}),
findsOne,
);
expect(
find.byWidgetPredicate((Widget widget) {
return widget is TextButton && widget.onPressed == null;
}),
findsOne,
);
expect(
find.byWidgetPredicate((Widget widget) {
return widget is TextButton && widget.onPressed != null;
}),
findsOne,
);
expect(
find.byWidgetPredicate((Widget widget) {
return widget is TextButton && widget.onPressed != null;
}),
findsOne,
);
expect(
find.byWidgetPredicate((Widget widget) {
return widget is FilledButton && widget.onPressed != null;
}),
findsNWidgets(2),
);
expect(
find.byWidgetPredicate((Widget widget) {
return widget is FilledButton && widget.onPressed != null;
}),
findsNWidgets(2),
);
expect(
find.byWidgetPredicate((Widget widget) {
return widget is FilledButton && widget.onPressed == null;
}),
findsNWidgets(2),
);
});
expect(
find.byWidgetPredicate((Widget widget) {
return widget is FilledButton && widget.onPressed == null;
}),
findsNWidgets(2),
);
},
);
}

View File

@@ -3,20 +3,18 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/button_style_button/button_style_button.icon_alignment.0.dart' as example;
import 'package:flutter_api_samples/material/button_style_button/button_style_button.icon_alignment.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('ButtonStyleButton.iconAlignment updates button icons alignment', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ButtonStyleButtonIconAlignmentApp(),
);
testWidgets('ButtonStyleButton.iconAlignment updates button icons alignment', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.ButtonStyleButtonIconAlignmentApp());
Finder findButtonMaterial(String text) {
return find.ancestor(
of: find.text(text),
matching: find.byType(Material),
).first;
return find.ancestor(of: find.text(text), matching: find.byType(Material)).first;
}
void expectedLeftIconPosition({

View File

@@ -8,13 +8,14 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Card Smoke Test', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CardExampleApp(),
);
await tester.pumpWidget(const example.CardExampleApp());
expect(find.byType(Card), findsOneWidget);
expect(find.widgetWithIcon(Card, Icons.album), findsOneWidget);
expect(find.widgetWithText(Card, 'The Enchanted Nightingale'), findsOneWidget);
expect(find.widgetWithText(Card, 'Music by Julie Gable. Lyrics by Sidney Stein.'), findsOneWidget);
expect(
find.widgetWithText(Card, 'Music by Julie Gable. Lyrics by Sidney Stein.'),
findsOneWidget,
);
expect(find.widgetWithText(Card, 'BUY TICKETS'), findsOneWidget);
expect(find.widgetWithText(Card, 'LISTEN'), findsOneWidget);
});

View File

@@ -18,19 +18,17 @@ void main() {
Material getCardMaterial(WidgetTester tester, int cardIndex) {
return tester.widget<Material>(
find.descendant(
of: find.byType(Card).at(cardIndex),
matching: find.byType(Material),
),
find.descendant(of: find.byType(Card).at(cardIndex), matching: find.byType(Material)),
);
}
final Material defaultCard = getCardMaterial(tester, 0);
expect(defaultCard.clipBehavior, Clip.none);
expect(defaultCard.elevation, 1.0);
expect(defaultCard.shape, const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
));
expect(
defaultCard.shape,
const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(12.0))),
);
expect(defaultCard.color, const Color(0xfff7f2fa));
expect(defaultCard.shadowColor, const Color(0xff000000));
expect(defaultCard.surfaceTintColor, Colors.transparent);
@@ -38,9 +36,10 @@ void main() {
final Material filledCard = getCardMaterial(tester, 1);
expect(filledCard.clipBehavior, Clip.none);
expect(filledCard.elevation, 0.0);
expect(filledCard.shape, const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(12.0)),
));
expect(
filledCard.shape,
const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(12.0))),
);
expect(filledCard.color, const Color(0xffe6e0e9));
expect(filledCard.shadowColor, const Color(0xff000000));
expect(filledCard.surfaceTintColor, const Color(0x00000000));
@@ -48,10 +47,13 @@ void main() {
final Material outlinedCard = getCardMaterial(tester, 2);
expect(outlinedCard.clipBehavior, Clip.none);
expect(outlinedCard.elevation, 0.0);
expect(outlinedCard.shape, const RoundedRectangleBorder(
side: BorderSide(color: Color(0xffcac4d0)),
borderRadius: BorderRadius.all(Radius.circular(12.0)),
));
expect(
outlinedCard.shape,
const RoundedRectangleBorder(
side: BorderSide(color: Color(0xffcac4d0)),
borderRadius: BorderRadius.all(Radius.circular(12.0)),
),
);
expect(outlinedCard.color, const Color(0xfffef7ff));
expect(outlinedCard.shadowColor, const Color(0xff000000));
expect(outlinedCard.surfaceTintColor, Colors.transparent);

View File

@@ -9,7 +9,6 @@ import 'package:flutter_api_samples/material/carousel/carousel.0.dart' as exampl
import 'package:flutter_test/flutter_test.dart';
void main() {
// The app being tested loads images via HTTP which the test
// framework defeats by default.
setUpAll(() {
@@ -17,9 +16,7 @@ void main() {
});
testWidgets('Carousel Smoke Test', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CarouselExampleApp(),
);
await tester.pumpWidget(const example.CarouselExampleApp());
expect(find.widgetWithText(example.HeroLayoutCard, 'Through the Pane'), findsOneWidget);
final Finder firstCarousel = find.byType(CarouselView).first;

View File

@@ -3,15 +3,12 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/checkbox/checkbox.0.dart'
as example;
import 'package:flutter_api_samples/material/checkbox/checkbox.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Checkbox can be checked', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CheckboxExampleApp(),
);
await tester.pumpWidget(const example.CheckboxExampleApp());
Checkbox checkbox = tester.widget(find.byType(Checkbox));
expect(checkbox.value, isFalse);
@@ -30,30 +27,13 @@ void main() {
});
testWidgets('Checkbox color can be changed', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CheckboxExampleApp(),
);
await tester.pumpWidget(const example.CheckboxExampleApp());
final Checkbox checkbox = tester.widget(find.byType(Checkbox));
expect(
checkbox.checkColor,
Colors.white,
);
expect(
checkbox.fillColor!.resolve(<MaterialState>{}),
Colors.red,
);
expect(
checkbox.fillColor!.resolve(<MaterialState>{MaterialState.pressed}),
Colors.blue,
);
expect(
checkbox.fillColor!.resolve(<MaterialState>{MaterialState.hovered}),
Colors.blue,
);
expect(
checkbox.fillColor!.resolve(<MaterialState>{MaterialState.focused}),
Colors.blue,
);
expect(checkbox.checkColor, Colors.white);
expect(checkbox.fillColor!.resolve(<MaterialState>{}), Colors.red);
expect(checkbox.fillColor!.resolve(<MaterialState>{MaterialState.pressed}), Colors.blue);
expect(checkbox.fillColor!.resolve(<MaterialState>{MaterialState.hovered}), Colors.blue);
expect(checkbox.fillColor!.resolve(<MaterialState>{MaterialState.focused}), Colors.blue);
});
}

View File

@@ -3,15 +3,12 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/checkbox/checkbox.1.dart'
as example;
import 'package:flutter_api_samples/material/checkbox/checkbox.1.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Checkbox can be checked', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CheckboxExampleApp(),
);
await tester.pumpWidget(const example.CheckboxExampleApp());
expect(find.byType(Checkbox), findsNWidgets(3));
Checkbox checkbox = tester.widget(find.byType(Checkbox).first);

View File

@@ -4,14 +4,13 @@
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_api_samples/material/checkbox_list_tile/checkbox_list_tile.0.dart' as example;
import 'package:flutter_api_samples/material/checkbox_list_tile/checkbox_list_tile.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('CheckboxListTile can be checked', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CheckboxListTileApp(),
);
await tester.pumpWidget(const example.CheckboxListTileApp());
CheckboxListTile checkboxListTile = tester.widget(find.byType(CheckboxListTile));
expect(checkboxListTile.value, isFalse);

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/checkbox_list_tile/checkbox_list_tile.1.dart' as example;
import 'package:flutter_api_samples/material/checkbox_list_tile/checkbox_list_tile.1.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Checkbox aligns appropriately', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CheckboxListTileApp(),
);
await tester.pumpWidget(const example.CheckboxListTileApp());
expect(find.byType(CheckboxListTile), findsNWidgets(3));
@@ -34,9 +33,7 @@ void main() {
});
testWidgets('Checkboxes can be checked', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CheckboxListTileApp(),
);
await tester.pumpWidget(const example.CheckboxListTileApp());
expect(find.byType(CheckboxListTile), findsNWidgets(3));

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/checkbox_list_tile/custom_labeled_checkbox.0.dart' as example;
import 'package:flutter_api_samples/material/checkbox_list_tile/custom_labeled_checkbox.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('LinkedLabelCheckbox contains RichText and Checkbox', (WidgetTester tester) async {
await tester.pumpWidget(
const example.LabeledCheckboxApp(),
);
await tester.pumpWidget(const example.LabeledCheckboxApp());
// Label text is in a RichText widget with the correct text.
final RichText richText = tester.widget(find.byType(RichText).first);

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/checkbox_list_tile/custom_labeled_checkbox.1.dart' as example;
import 'package:flutter_api_samples/material/checkbox_list_tile/custom_labeled_checkbox.1.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Tapping LabeledCheckbox toggles the checkbox', (WidgetTester tester) async {
await tester.pumpWidget(
const example.LabeledCheckboxApp(),
);
await tester.pumpWidget(const example.LabeledCheckboxApp());
// Checkbox is initially unchecked.
Checkbox checkbox = tester.widget(find.byType(Checkbox));

View File

@@ -3,52 +3,56 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/chip/chip_attributes.avatar_box_constraints.0.dart' as example;
import 'package:flutter_api_samples/material/chip/chip_attributes.avatar_box_constraints.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('RawChip.avatarBoxConstraints updates avatar size constraints', (WidgetTester tester) async {
testWidgets('RawChip.avatarBoxConstraints updates avatar size constraints', (
WidgetTester tester,
) async {
const double border = 1.0;
const double iconSize = 18.0;
const double padding = 8.0;
await tester.pumpWidget(
const example.AvatarBoxConstraintsApp(),
);
await tester.pumpWidget(const example.AvatarBoxConstraintsApp());
expect(tester.getSize(find.byType(RawChip).at(0)).width, equals(202.0));
expect(tester.getSize(find.byType(RawChip).at(0)).height, equals(58.0));
Offset chipTopLeft = tester.getTopLeft(find.byWidget(tester.widget<Material>(
find.descendant(
of: find.byType(RawChip).at(0),
matching: find.byType(Material),
Offset chipTopLeft = tester.getTopLeft(
find.byWidget(
tester.widget<Material>(
find.descendant(of: find.byType(RawChip).at(0), matching: find.byType(Material)),
),
),
)));
);
Offset avatarCenter = tester.getCenter(find.byIcon(Icons.star).at(0));
expect(chipTopLeft.dx, avatarCenter.dx - (iconSize / 2) - padding - border);
expect(tester.getSize(find.byType(RawChip).at(1)).width, equals(202.0));
expect(tester.getSize(find.byType(RawChip).at(1)).height, equals(78.0));
chipTopLeft = tester.getTopLeft(find.byWidget(tester.widget<Material>(
find.descendant(
of: find.byType(RawChip).at(1),
matching: find.byType(Material),
chipTopLeft = tester.getTopLeft(
find.byWidget(
tester.widget<Material>(
find.descendant(of: find.byType(RawChip).at(1), matching: find.byType(Material)),
),
),
)));
);
avatarCenter = tester.getCenter(find.byIcon(Icons.star).at(1));
expect(chipTopLeft.dx, avatarCenter.dx - (iconSize / 2) - padding - border);
expect(tester.getSize(find.byType(RawChip).at(2)).width, equals(202.0));
expect(tester.getSize(find.byType(RawChip).at(2)).height, equals(78.0));
chipTopLeft = tester.getTopLeft(find.byWidget(tester.widget<Material>(
find.descendant(
of: find.byType(RawChip).at(2),
matching: find.byType(Material),
chipTopLeft = tester.getTopLeft(
find.byWidget(
tester.widget<Material>(
find.descendant(of: find.byType(RawChip).at(2), matching: find.byType(Material)),
),
),
)));
);
avatarCenter = tester.getCenter(find.byIcon(Icons.star).at(2));
expect(chipTopLeft.dx, avatarCenter.dx - (iconSize / 2) - padding - border);
});

View File

@@ -3,14 +3,15 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/chip/chip_attributes.chip_animation_style.0.dart' as example;
import 'package:flutter_api_samples/material/chip/chip_attributes.chip_animation_style.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('ChipAnimationStyle.enableAnimation overrides chip enable animation', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ChipAnimationStyleExampleApp(),
);
testWidgets('ChipAnimationStyle.enableAnimation overrides chip enable animation', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.ChipAnimationStyleExampleApp());
final RenderBox materialBox = tester.firstRenderObject<RenderBox>(
find.descendant(
@@ -42,10 +43,10 @@ void main() {
expect(materialBox, paints..rrect(color: const Color(0xffffc107)));
});
testWidgets('ChipAnimationStyle.selectAnimation overrides chip select animation', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ChipAnimationStyleExampleApp(),
);
testWidgets('ChipAnimationStyle.selectAnimation overrides chip select animation', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.ChipAnimationStyleExampleApp());
final RenderBox materialBox = tester.firstRenderObject<RenderBox>(
find.descendant(
@@ -77,10 +78,10 @@ void main() {
expect(materialBox, paints..rrect(color: const Color(0xffffc107)));
});
testWidgets('ChipAnimationStyle.avatarDrawerAnimation overrides chip checkmark animation', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ChipAnimationStyleExampleApp(),
);
testWidgets('ChipAnimationStyle.avatarDrawerAnimation overrides chip checkmark animation', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.ChipAnimationStyleExampleApp());
expect(tester.getSize(find.widgetWithText(RawChip, 'Checked')).width, closeTo(152.6, 0.1));
@@ -105,10 +106,10 @@ void main() {
expect(tester.getSize(find.widgetWithText(RawChip, 'Checked')).width, closeTo(152.6, 0.1));
});
testWidgets('ChipAnimationStyle.deleteDrawerAnimation overrides chip delete icon animation', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ChipAnimationStyleExampleApp(),
);
testWidgets('ChipAnimationStyle.deleteDrawerAnimation overrides chip delete icon animation', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.ChipAnimationStyleExampleApp());
expect(tester.getSize(find.widgetWithText(RawChip, 'Deletable')).width, closeTo(180.9, 0.1));

View File

@@ -3,52 +3,56 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/chip/deletable_chip_attributes.delete_icon_box_constraints.0.dart' as example;
import 'package:flutter_api_samples/material/chip/deletable_chip_attributes.delete_icon_box_constraints.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('RawChip.deleteIconBoxConstraints updates delete icon size constraints', (WidgetTester tester) async {
testWidgets('RawChip.deleteIconBoxConstraints updates delete icon size constraints', (
WidgetTester tester,
) async {
const double border = 1.0;
const double iconSize = 18.0;
const double padding = 8.0;
await tester.pumpWidget(
const example.DeleteIconBoxConstraintsApp(),
);
await tester.pumpWidget(const example.DeleteIconBoxConstraintsApp());
expect(tester.getSize(find.byType(RawChip).at(0)).width, equals(202.0));
expect(tester.getSize(find.byType(RawChip).at(0)).height, equals(58.0));
Offset chipToRight = tester.getTopRight(find.byWidget(tester.widget<Material>(
find.descendant(
of: find.byType(RawChip).at(0),
matching: find.byType(Material),
Offset chipToRight = tester.getTopRight(
find.byWidget(
tester.widget<Material>(
find.descendant(of: find.byType(RawChip).at(0), matching: find.byType(Material)),
),
),
)));
);
Offset deleteIconCenter = tester.getCenter(find.byIcon(Icons.cancel).at(0));
expect(chipToRight.dx, deleteIconCenter.dx + (iconSize / 2) + padding + border);
expect(tester.getSize(find.byType(RawChip).at(1)).width, equals(202.0));
expect(tester.getSize(find.byType(RawChip).at(1)).height, equals(78.0));
chipToRight = tester.getTopRight(find.byWidget(tester.widget<Material>(
find.descendant(
of: find.byType(RawChip).at(1),
matching: find.byType(Material),
chipToRight = tester.getTopRight(
find.byWidget(
tester.widget<Material>(
find.descendant(of: find.byType(RawChip).at(1), matching: find.byType(Material)),
),
),
)));
);
deleteIconCenter = tester.getCenter(find.byIcon(Icons.cancel).at(1));
expect(chipToRight.dx, deleteIconCenter.dx + (iconSize / 2) + padding + border);
expect(tester.getSize(find.byType(RawChip).at(2)).width, equals(202.0));
expect(tester.getSize(find.byType(RawChip).at(2)).height, equals(78.0));
chipToRight = tester.getTopRight(find.byWidget(tester.widget<Material>(
find.descendant(
of: find.byType(RawChip).at(2),
matching: find.byType(Material),
chipToRight = tester.getTopRight(
find.byWidget(
tester.widget<Material>(
find.descendant(of: find.byType(RawChip).at(2), matching: find.byType(Material)),
),
),
)));
);
deleteIconCenter = tester.getCenter(find.byIcon(Icons.cancel).at(2));
expect(chipToRight.dx, deleteIconCenter.dx + (iconSize / 2) + padding + border);
});

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/chip/deletable_chip_attributes.on_deleted.0.dart' as example;
import 'package:flutter_api_samples/material/chip/deletable_chip_attributes.on_deleted.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Chip.onDeleted can be used to delete chips', (WidgetTester tester) async {
await tester.pumpWidget(
const example.OnDeletedExampleApp(),
);
await tester.pumpWidget(const example.OnDeletedExampleApp());
expect(find.widgetWithText(AppBar, 'DeletableChipAttributes.onDeleted Sample'), findsOne);
expect(find.widgetWithText(Chip, 'Aaron Burr'), findsOne);

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can choose an item using ChoiceChip', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ChipApp(),
);
await tester.pumpWidget(const example.ChipApp());
ChoiceChip chosenChip = tester.widget(find.byType(ChoiceChip).at(1));
expect(chosenChip.selected, true);

View File

@@ -8,27 +8,24 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('ColorScheme Smoke Test', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ColorSchemeExample(),
);
await tester.pumpWidget(const example.ColorSchemeExample());
expect(find.text('tonalSpot (Default)'), findsOneWidget);
expect(find.byType(example.ColorChip), findsNWidgets(43 * 9));
});
testWidgets('Change color seed', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ColorSchemeExample(),
);
await tester.pumpWidget(const example.ColorSchemeExample());
ColoredBox coloredBox() {
return tester.widget<ColoredBox>(
find.descendant(
of: find.widgetWithText(example.ColorChip, 'primary').first,
matching: find.byType(ColoredBox)
)
matching: find.byType(ColoredBox),
),
);
}
expect(coloredBox().color, const Color(0xff65558f));
await tester.tap(find.byType(example.SettingsButton));
await tester.pumpAndSettle();

View File

@@ -10,9 +10,13 @@ import 'package:flutter_api_samples/material/color_scheme/dynamic_content_color.
import 'package:flutter_test/flutter_test.dart';
void main() {
final List<(ImageProvider<Object>, Brightness)> loadColorSchemeCalls = <(ImageProvider<Object>, Brightness)>[];
final List<(ImageProvider<Object>, Brightness)> loadColorSchemeCalls =
<(ImageProvider<Object>, Brightness)>[];
Future<ColorScheme> fakeColorSchemeLoader(ImageProvider<Object> provider, Brightness brightness) async {
Future<ColorScheme> fakeColorSchemeLoader(
ImageProvider<Object> provider,
Brightness brightness,
) async {
loadColorSchemeCalls.add((provider, brightness));
final int index = example.DynamicColorExample.images.indexOf(provider);
final int seedColor = 0xf * pow(0x10, index).toInt();
@@ -30,17 +34,10 @@ void main() {
});
testWidgets('The content is visible', (WidgetTester tester) async {
await tester.pumpWidget(
example.DynamicColorExample(
loadColorScheme: fakeColorSchemeLoader,
),
);
await tester.pumpWidget(example.DynamicColorExample(loadColorScheme: fakeColorSchemeLoader));
await tester.pump();
expect(
find.widgetWithText(AppBar, 'Content Based Dynamic Color'),
findsOne,
);
expect(find.widgetWithText(AppBar, 'Content Based Dynamic Color'), findsOne);
expect(find.byType(Switch), findsOne);
expect(find.byIcon(Icons.light_mode), findsOne);
@@ -74,43 +71,31 @@ void main() {
expect(loadColorSchemeCalls, hasLength(1));
expect(
loadColorSchemeCalls.single.$1,
isA<NetworkImage>()
.having(
(NetworkImage provider) => provider.url,
'url',
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_1.png',
),
);
expect(
loadColorSchemeCalls.single.$2,
Brightness.light,
isA<NetworkImage>().having(
(NetworkImage provider) => provider.url,
'url',
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_1.png',
),
);
expect(loadColorSchemeCalls.single.$2, Brightness.light);
await tester.pumpAndSettle(); // Clears the timers from image loading.
});
testWidgets('The brightness can be changed', (WidgetTester tester) async {
await tester.pumpWidget(
example.DynamicColorExample(
loadColorScheme: fakeColorSchemeLoader,
),
);
await tester.pumpWidget(example.DynamicColorExample(loadColorScheme: fakeColorSchemeLoader));
await tester.pump();
expect(loadColorSchemeCalls, hasLength(1));
expect(
loadColorSchemeCalls.single.$1,
isA<NetworkImage>()
.having(
(NetworkImage provider) => provider.url,
'url',
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_1.png',
),
);
expect(
loadColorSchemeCalls.single.$2,
Brightness.light,
isA<NetworkImage>().having(
(NetworkImage provider) => provider.url,
'url',
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_1.png',
),
);
expect(loadColorSchemeCalls.single.$2, Brightness.light);
await tester.pump();
await tester.pump(kThemeChangeDuration);
@@ -125,17 +110,13 @@ void main() {
expect(loadColorSchemeCalls, hasLength(2));
expect(
loadColorSchemeCalls.last.$1,
isA<NetworkImage>()
.having(
(NetworkImage provider) => provider.url,
'url',
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_1.png',
),
);
expect(
loadColorSchemeCalls.last.$2,
Brightness.dark,
isA<NetworkImage>().having(
(NetworkImage provider) => provider.url,
'url',
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_1.png',
),
);
expect(loadColorSchemeCalls.last.$2, Brightness.dark);
await tester.pump(kThemeChangeDuration);
@@ -146,11 +127,7 @@ void main() {
});
testWidgets('Tapping an image loads a new color scheme', (WidgetTester tester) async {
await tester.pumpWidget(
example.DynamicColorExample(
loadColorScheme: fakeColorSchemeLoader,
),
);
await tester.pumpWidget(example.DynamicColorExample(loadColorScheme: fakeColorSchemeLoader));
await tester.pump();
await tester.tapAt(tester.getCenter(find.byType(Image).at(3)));
@@ -159,17 +136,13 @@ void main() {
expect(loadColorSchemeCalls, hasLength(2));
expect(
loadColorSchemeCalls.last.$1,
isA<NetworkImage>()
.having(
(NetworkImage provider) => provider.url,
'url',
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_4.png',
),
);
expect(
loadColorSchemeCalls.last.$2,
Brightness.light,
isA<NetworkImage>().having(
(NetworkImage provider) => provider.url,
'url',
'https://flutter.github.io/assets-for-api-docs/assets/material/content_based_color_scheme_4.png',
),
);
expect(loadColorSchemeCalls.last.$2, Brightness.light);
await tester.pump(kThemeChangeDuration);

View File

@@ -6,14 +6,15 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_api_samples/material/context_menu/context_menu_controller.0.dart' as example;
import 'package:flutter_api_samples/material/context_menu/context_menu_controller.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('showing and hiding the custom context menu in the whole app', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ContextMenuControllerExampleApp(),
);
testWidgets('showing and hiding the custom context menu in the whole app', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.ContextMenuControllerExampleApp());
expect(BrowserContextMenu.enabled, !kIsWeb);

View File

@@ -6,14 +6,15 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_api_samples/material/context_menu/editable_text_toolbar_builder.0.dart' as example;
import 'package:flutter_api_samples/material/context_menu/editable_text_toolbar_builder.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('showing and hiding the context menu in TextField with custom buttons', (WidgetTester tester) async {
await tester.pumpWidget(
const example.EditableTextToolbarBuilderExampleApp(),
);
testWidgets('showing and hiding the context menu in TextField with custom buttons', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.EditableTextToolbarBuilderExampleApp());
expect(BrowserContextMenu.enabled, !kIsWeb);

View File

@@ -6,14 +6,15 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_api_samples/material/context_menu/editable_text_toolbar_builder.1.dart' as example;
import 'package:flutter_api_samples/material/context_menu/editable_text_toolbar_builder.1.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('showing and hiding the custom context menu in TextField with a specific selection', (WidgetTester tester) async {
await tester.pumpWidget(
const example.EditableTextToolbarBuilderExampleApp(),
);
testWidgets('showing and hiding the custom context menu in TextField with a specific selection', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.EditableTextToolbarBuilderExampleApp());
expect(BrowserContextMenu.enabled, !kIsWeb);
@@ -40,14 +41,15 @@ void main() {
expect(find.byType(AdaptiveTextSelectionToolbar), findsNothing);
// Select the email address.
final EditableTextState state =
tester.state<EditableTextState>(find.byType(EditableText));
state.updateEditingValue(state.textEditingValue.copyWith(
selection: TextSelection(
baseOffset: example.text.indexOf(example.emailAddress),
extentOffset: example.text.length,
final EditableTextState state = tester.state<EditableTextState>(find.byType(EditableText));
state.updateEditingValue(
state.textEditingValue.copyWith(
selection: TextSelection(
baseOffset: example.text.indexOf(example.emailAddress),
extentOffset: example.text.length,
),
),
));
);
await tester.pump();
// Right clicking the Text in the TextField shows the custom context menu

View File

@@ -6,14 +6,15 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_api_samples/material/context_menu/editable_text_toolbar_builder.2.dart' as example;
import 'package:flutter_api_samples/material/context_menu/editable_text_toolbar_builder.2.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('showing and hiding the context menu in TextField with a custom toolbar', (WidgetTester tester) async {
await tester.pumpWidget(
const example.EditableTextToolbarBuilderExampleApp(),
);
testWidgets('showing and hiding the context menu in TextField with a custom toolbar', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.EditableTextToolbarBuilderExampleApp());
expect(BrowserContextMenu.enabled, !kIsWeb);

View File

@@ -6,14 +6,15 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_api_samples/material/context_menu/selectable_region_toolbar_builder.0.dart' as example;
import 'package:flutter_api_samples/material/context_menu/selectable_region_toolbar_builder.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('showing and hiding the custom context menu on SelectionArea', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SelectableRegionToolbarBuilderExampleApp(),
);
testWidgets('showing and hiding the custom context menu on SelectionArea', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.SelectableRegionToolbarBuilderExampleApp());
expect(BrowserContextMenu.enabled, !kIsWeb);

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('DataTable Smoke Test', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DataTableExampleApp(),
);
await tester.pumpWidget(const example.DataTableExampleApp());
expect(find.widgetWithText(AppBar, 'DataTable Sample'), findsOneWidget);
expect(find.byType(DataTable), findsOneWidget);
final DataTable dataTable = tester.widget<DataTable>(find.byType(DataTable));

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('DataTable is scrollable', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DataTableExampleApp(),
);
await tester.pumpWidget(const example.DataTableExampleApp());
expect(find.byType(SingleChildScrollView), findsOneWidget);

View File

@@ -3,29 +3,30 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/date_picker/date_picker_theme_day_shape.0.dart' as example;
import 'package:flutter_api_samples/material/date_picker/date_picker_theme_day_shape.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('DatePickerThemeData.dayShape updates day selection shape decoration', (WidgetTester tester) async {
testWidgets('DatePickerThemeData.dayShape updates day selection shape decoration', (
WidgetTester tester,
) async {
final ThemeData theme = ThemeData();
final OutlinedBorder dayShape = RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.0));
final OutlinedBorder dayShape = RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
);
const Color todayBackgroundColor = Colors.amber;
const Color todayForegroundColor = Colors.black;
const BorderSide todayBorder = BorderSide(width: 2);
ShapeDecoration? findDayDecoration(WidgetTester tester, String day) {
return tester.widget<Ink>(
find.ancestor(
of: find.text(day),
matching: find.byType(Ink)
),
).decoration as ShapeDecoration?;
return tester
.widget<Ink>(find.ancestor(of: find.text(day), matching: find.byType(Ink)))
.decoration
as ShapeDecoration?;
}
await tester.pumpWidget(
const example.DatePickerApp(),
);
await tester.pumpWidget(const example.DatePickerApp());
await tester.tap(find.text('Open Date Picker'));
await tester.pumpAndSettle();
@@ -33,7 +34,10 @@ void main() {
// Test the current day shape decoration.
ShapeDecoration dayShapeDecoration = findDayDecoration(tester, '15')!;
expect(dayShapeDecoration.color, todayBackgroundColor);
expect(dayShapeDecoration.shape, dayShape.copyWith(side: todayBorder.copyWith(color: todayForegroundColor)));
expect(
dayShapeDecoration.shape,
dayShape.copyWith(side: todayBorder.copyWith(color: todayForegroundColor)),
);
// Test the selected day shape decoration.
dayShapeDecoration = findDayDecoration(tester, '20')!;
@@ -47,6 +51,9 @@ void main() {
// Test the selected day shape decoration.
dayShapeDecoration = findDayDecoration(tester, '15')!;
expect(dayShapeDecoration.color, todayBackgroundColor);
expect(dayShapeDecoration.shape, dayShape.copyWith(side: todayBorder.copyWith(color: todayForegroundColor)));
expect(
dayShapeDecoration.shape,
dayShape.copyWith(side: todayBorder.copyWith(color: todayForegroundColor)),
);
});
}

View File

@@ -11,9 +11,7 @@ void main() {
const String datePickerTitle = 'Select date';
const String initialDate = 'Sun, Jul 25';
await tester.pumpWidget(
const example.DatePickerApp(),
);
await tester.pumpWidget(const example.DatePickerApp());
// The date picker is not shown initially.
expect(find.text(datePickerTitle), findsNothing);

View File

@@ -36,7 +36,7 @@ void main() {
expect(find.text(datePickerTitle), findsOneWidget);
expect(find.text('Fri, Jul 30'), findsOneWidget);
// Tap OK to confirm the selection and close the date picker.
// Tap OK to confirm the selection and close the date picker.
await tester.tap(find.text('OK'));
await tester.pumpAndSettle();

View File

@@ -10,9 +10,7 @@ void main() {
testWidgets('Can show date range picker', (WidgetTester tester) async {
const String datePickerTitle = 'Select range';
await tester.pumpWidget(
const example.DatePickerApp(),
);
await tester.pumpWidget(const example.DatePickerApp());
// The date range picker is not shown initially.
expect(find.text(datePickerTitle), findsNothing);

View File

@@ -9,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Show Adaptive Alert dialog', (WidgetTester tester) async {
const String dialogTitle = 'AlertDialog Title';
await tester.pumpWidget(
const example.AdaptiveAlertDialogApp(),
);
await tester.pumpWidget(const example.AdaptiveAlertDialogApp());
expect(find.text(dialogTitle), findsNothing);

View File

@@ -9,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Show Alert dialog', (WidgetTester tester) async {
const String dialogTitle = 'AlertDialog Title';
await tester.pumpWidget(
const example.AlertDialogExampleApp(),
);
await tester.pumpWidget(const example.AlertDialogExampleApp());
expect(find.text(dialogTitle), findsNothing);

View File

@@ -9,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Show Alert dialog', (WidgetTester tester) async {
const String dialogTitle = 'AlertDialog Title';
await tester.pumpWidget(
const example.AlertDialogExampleApp(),
);
await tester.pumpWidget(const example.AlertDialogExampleApp());
expect(find.text(dialogTitle), findsNothing);

View File

@@ -9,9 +9,7 @@ void main() {
testWidgets('Show Dialog', (WidgetTester tester) async {
const String dialogText = 'This is a typical dialog.';
await tester.pumpWidget(
const example.DialogExampleApp(),
);
await tester.pumpWidget(const example.DialogExampleApp());
expect(find.text(dialogText), findsNothing);
@@ -27,9 +25,7 @@ void main() {
testWidgets('Show Dialog.fullscreen', (WidgetTester tester) async {
const String dialogText = 'This is a fullscreen dialog.';
await tester.pumpWidget(
const example.DialogExampleApp(),
);
await tester.pumpWidget(const example.DialogExampleApp());
expect(find.text(dialogText), findsNothing);

View File

@@ -9,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Show dialog', (WidgetTester tester) async {
const String dialogTitle = 'Basic dialog title';
await tester.pumpWidget(
const example.ShowDialogExampleApp(),
);
await tester.pumpWidget(const example.ShowDialogExampleApp());
expect(find.text(dialogTitle), findsNothing);

View File

@@ -9,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Show dialog', (WidgetTester tester) async {
const String dialogTitle = 'Basic dialog title';
await tester.pumpWidget(
const example.ShowDialogExampleApp(),
);
await tester.pumpWidget(const example.ShowDialogExampleApp());
expect(find.text(dialogTitle), findsNothing);

View File

@@ -9,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Show dialog', (WidgetTester tester) async {
const String dialogTitle = 'Basic dialog title';
await tester.pumpWidget(
const example.ShowDialogExampleApp(),
);
await tester.pumpWidget(const example.ShowDialogExampleApp());
expect(find.text(dialogTitle), findsNothing);

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Horizontal Divider', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DividerExampleApp(),
);
await tester.pumpWidget(const example.DividerExampleApp());
expect(find.byType(Divider), findsOneWidget);

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Horizontal Divider', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DividerExampleApp(),
);
await tester.pumpWidget(const example.DividerExampleApp());
expect(find.byType(Divider), findsOneWidget);

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Vertical Divider', (WidgetTester tester) async {
await tester.pumpWidget(
const example.VerticalDividerExampleApp(),
);
await tester.pumpWidget(const example.VerticalDividerExampleApp());
expect(find.byType(VerticalDivider), findsOneWidget);

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Vertical Divider', (WidgetTester tester) async {
await tester.pumpWidget(
const example.VerticalDividerExampleApp(),
);
await tester.pumpWidget(const example.VerticalDividerExampleApp());
expect(find.byType(VerticalDivider), findsOneWidget);

View File

@@ -3,16 +3,12 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/drawer/drawer.0.dart'
as example;
import 'package:flutter_api_samples/material/drawer/drawer.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Navigation bar updates destination on tap',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.DrawerApp(),
);
testWidgets('Navigation bar updates destination on tap', (WidgetTester tester) async {
await tester.pumpWidget(const example.DrawerApp());
await tester.tap(find.byIcon(Icons.menu));
await tester.pumpAndSettle();

View File

@@ -7,9 +7,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Select an item from DropdownButton', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DropdownButtonApp(),
);
await tester.pumpWidget(const example.DropdownButtonApp());
expect(find.text('One'), findsOneWidget);

View File

@@ -2,14 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_api_samples/material/dropdown/dropdown_button.selected_item_builder.0.dart' as example;
import 'package:flutter_api_samples/material/dropdown/dropdown_button.selected_item_builder.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Select an item from DropdownButton', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DropdownButtonApp(),
);
await tester.pumpWidget(const example.DropdownButtonApp());
expect(find.text('NYC'), findsOneWidget);

View File

@@ -7,9 +7,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Select an item from DropdownButton', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DropdownButtonApp(),
);
await tester.pumpWidget(const example.DropdownButtonApp());
expect(find.text('One'), findsOneWidget);
expect(find.text('One', skipOffstage: false), findsNWidgets(4));

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('DropdownMenu', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DropdownMenuExample(),
);
await tester.pumpWidget(const example.DropdownMenuExample());
expect(find.text('You selected a Blue Smile'), findsNothing);
@@ -54,9 +52,7 @@ void main() {
});
testWidgets('DropdownMenu has focus when tapping on the text field', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DropdownMenuExample(),
);
await tester.pumpWidget(const example.DropdownMenuExample());
// Make sure the dropdown menus are there.
final Finder colorMenu = find.byType(DropdownMenu<example.ColorLabel>);

View File

@@ -7,42 +7,41 @@ import 'package:flutter_api_samples/material/dropdown_menu/dropdown_menu.1.dart'
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('The DropdownMenu should display a menu with the list of entries the user can select', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DropdownMenuApp(),
);
testWidgets(
'The DropdownMenu should display a menu with the list of entries the user can select',
(WidgetTester tester) async {
await tester.pumpWidget(const example.DropdownMenuApp());
expect(find.widgetWithText(TextField, 'One'), findsOne);
final Finder menu = find.byType(DropdownMenu<String>);
expect(menu, findsOne);
expect(find.widgetWithText(TextField, 'One'), findsOne);
final Finder menu = find.byType(DropdownMenu<String>);
expect(menu, findsOne);
Finder findMenuItem(String label) {
return find.widgetWithText(MenuItemButton, label).last;
}
Finder findMenuItem(String label) {
return find.widgetWithText(MenuItemButton, label).last;
}
await tester.tap(menu);
await tester.pumpAndSettle();
expect(findMenuItem('One'), findsOne);
expect(findMenuItem('Two'), findsOne);
expect(findMenuItem('Three'), findsOne);
expect(findMenuItem('Four'), findsOne);
await tester.tap(menu);
await tester.pumpAndSettle();
expect(findMenuItem('One'), findsOne);
expect(findMenuItem('Two'), findsOne);
expect(findMenuItem('Three'), findsOne);
expect(findMenuItem('Four'), findsOne);
await tester.tap(findMenuItem('Two'));
await tester.tap(findMenuItem('Two'));
// The DropdownMenu's onSelected callback is delayed
// with SchedulerBinding.instance.addPostFrameCallback
// to give the focus a chance to return to where it was
// before the menu appeared. The pumpAndSettle()
// give the callback a chance to run.
await tester.pumpAndSettle();
// The DropdownMenu's onSelected callback is delayed
// with SchedulerBinding.instance.addPostFrameCallback
// to give the focus a chance to return to where it was
// before the menu appeared. The pumpAndSettle()
// give the callback a chance to run.
await tester.pumpAndSettle();
expect(find.widgetWithText(TextField, 'Two'), findsOne);
});
expect(find.widgetWithText(TextField, 'Two'), findsOne);
},
);
testWidgets('DropdownMenu has focus when tapping on the text field', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DropdownMenuApp(),
);
await tester.pumpWidget(const example.DropdownMenuApp());
// Make sure the dropdown menus are there.
final Finder menu = find.byType(DropdownMenu<String>);

View File

@@ -11,33 +11,46 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('DropdownMenu cursor behavior', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DropdownMenuApp(),
);
await tester.pumpWidget(const example.DropdownMenuApp());
Finder textFieldFinder(int index) {
return find.byType(TextField).at(index);
}
// Hover over the "enabled and requestFocusOnTap set to true" text field.
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
final TestGesture gesture = await tester.createGesture(
kind: PointerDeviceKind.mouse,
pointer: 1,
);
await gesture.moveTo(tester.getCenter(textFieldFinder(0)));
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.text);
expect(
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
SystemMouseCursors.text,
);
// Hover over the "enabled and requestFocusOnTap set to false" text field.
await gesture.moveTo(tester.getCenter(textFieldFinder(1)));
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
expect(
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
SystemMouseCursors.click,
);
// Hover over the "disabled and requestFocusOnTap set to true" text field.
await gesture.moveTo(tester.getCenter(textFieldFinder(2)));
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
expect(
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
SystemMouseCursors.basic,
);
// Hover over the "disabled and requestFocusOnTap set to false" text field.
await gesture.moveTo(tester.getCenter(textFieldFinder(3)));
await gesture.moveTo(tester.getCenter(textFieldFinder(3)));
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
expect(
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
SystemMouseCursors.basic,
);
});
}

View File

@@ -3,22 +3,24 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/dropdown_menu/dropdown_menu_entry_label_widget.0.dart' as example;
import 'package:flutter_api_samples/material/dropdown_menu/dropdown_menu_entry_label_widget.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('DropdownEntryLabelWidget appears', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DropdownMenuEntryLabelWidgetExampleApp(),
);
await tester.pumpWidget(const example.DropdownMenuEntryLabelWidgetExampleApp());
const String longText = 'is a color that sings of hope, A hue that shines like gold. It is the color of dreams, A shade that never grows old.';
const String longText =
'is a color that sings of hope, A hue that shines like gold. It is the color of dreams, A shade that never grows old.';
Finder findMenuItemText(String label) {
final String labelText = '$label $longText\n';
return find.descendant(
of: find.widgetWithText(MenuItemButton, labelText),
matching: find.byType(Text),
).last;
return find
.descendant(
of: find.widgetWithText(MenuItemButton, labelText),
matching: find.byType(Text),
)
.last;
}
// Open the menu

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('ElevatedButton Smoke Test', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ElevatedButtonExampleApp(),
);
await tester.pumpWidget(const example.ElevatedButtonExampleApp());
expect(find.widgetWithText(AppBar, 'ElevatedButton Sample'), findsOneWidget);
final Finder disabledButton = find.widgetWithText(ElevatedButton, 'Disabled');

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/expansion_panel/expansion_panel_list.0.dart' as example;
import 'package:flutter_api_samples/material/expansion_panel/expansion_panel_list.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('ExpansionPanel can be expanded', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ExpansionPanelListExampleApp(),
);
await tester.pumpWidget(const example.ExpansionPanelListExampleApp());
// Verify the first tile is collapsed.
expect(tester.widget<ExpandIcon>(find.byType(ExpandIcon).first).isExpanded, false);
@@ -26,9 +25,7 @@ void main() {
testWidgets('Tap to delete a ExpansionPanel', (WidgetTester tester) async {
const int index = 3;
await tester.pumpWidget(
const example.ExpansionPanelListExampleApp(),
);
await tester.pumpWidget(const example.ExpansionPanelListExampleApp());
expect(find.widgetWithText(ListTile, 'Panel $index'), findsOneWidget);
expect(tester.widget<ExpandIcon>(find.byType(ExpandIcon).at(index)).isExpanded, false);
@@ -48,9 +45,7 @@ void main() {
});
testWidgets('ExpansionPanelList is scrollable', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ExpansionPanelListExampleApp(),
);
await tester.pumpWidget(const example.ExpansionPanelListExampleApp());
expect(find.byType(SingleChildScrollView), findsOneWidget);

View File

@@ -3,14 +3,15 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0.dart' as example;
import 'package:flutter_api_samples/material/expansion_panel/expansion_panel_list.expansion_panel_list_radio.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('ExpansionPanelList.radio can expand one item at the time', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ExpansionPanelListRadioExampleApp(),
);
testWidgets('ExpansionPanelList.radio can expand one item at the time', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.ExpansionPanelListRadioExampleApp());
expect(find.widgetWithText(AppBar, 'ExpansionPanelList.radio Sample'), findsOne);
expect(find.byType(ExpansionPanelList), findsOne);

View File

@@ -7,12 +7,12 @@ import 'package:flutter_api_samples/material/expansion_tile/expansion_tile.0.dar
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('When expansion tiles are expanded tile numbers are revealed', (WidgetTester tester) async {
testWidgets('When expansion tiles are expanded tile numbers are revealed', (
WidgetTester tester,
) async {
const int totalTiles = 3;
await tester.pumpWidget(
const example.ExpansionTileApp(),
);
await tester.pumpWidget(const example.ExpansionTileApp());
expect(find.byType(ExpansionTile), findsNWidgets(totalTiles));

View File

@@ -7,9 +7,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Test the basics of ExpansionTileControllerApp', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ExpansionTileControllerApp(),
);
await tester.pumpWidget(const example.ExpansionTileControllerApp());
expect(find.text('ExpansionTile Contents'), findsNothing);
expect(find.text('Collapse This Tile'), findsNothing);

View File

@@ -7,10 +7,10 @@ import 'package:flutter_api_samples/material/expansion_tile/expansion_tile.2.dar
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('ExpansionTile animation can be customized using AnimationStyle', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ExpansionTileAnimationStyleApp(),
);
testWidgets('ExpansionTile animation can be customized using AnimationStyle', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.ExpansionTileAnimationStyleApp());
double getHeight(WidgetTester tester) {
return tester.getSize(find.byType(ExpansionTile)).height;

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('FilledButton Smoke Test', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FilledButtonApp(),
);
await tester.pumpWidget(const example.FilledButtonApp());
expect(find.widgetWithText(AppBar, 'FilledButton Sample'), findsOneWidget);
final Finder disabledButton = find.widgetWithText(FilledButton, 'Disabled');

View File

@@ -10,9 +10,7 @@ void main() {
testWidgets('Filter exercises using FilterChip', (WidgetTester tester) async {
const String baseText = 'Looking for: ';
await tester.pumpWidget(
const example.ChipApp(),
);
await tester.pumpWidget(const example.ChipApp());
expect(find.text(baseText), findsOneWidget);

View File

@@ -5,7 +5,8 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/flexible_space_bar/flexible_space_bar.0.dart' as example;
import 'package:flutter_api_samples/material/flexible_space_bar/flexible_space_bar.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
@@ -16,9 +17,7 @@ void main() {
});
testWidgets('The app bar stretches when over-scrolled', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FlexibleSpaceBarExampleApp(),
);
await tester.pumpWidget(const example.FlexibleSpaceBarExampleApp());
expect(find.text('Flight Report'), findsOne);

View File

@@ -9,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('FloatingActionButton', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FloatingActionButtonExampleApp(),
);
await tester.pumpWidget(const example.FloatingActionButtonExampleApp());
expect(find.byType(FloatingActionButton), findsOneWidget);
expect(find.byIcon(Icons.navigation), findsOneWidget);

View File

@@ -13,9 +13,7 @@ void main() {
return tester.widget<RawMaterialButton>(finder);
}
await tester.pumpWidget(
const example.FloatingActionButtonExampleApp(),
);
await tester.pumpWidget(const example.FloatingActionButtonExampleApp());
final ThemeData theme = ThemeData(useMaterial3: true);
@@ -25,25 +23,49 @@ void main() {
final Finder smallFabMaterialButton = find.byType(RawMaterialButton).at(0);
final RenderBox smallFabRenderBox = tester.renderObject(smallFabMaterialButton);
expect(smallFabRenderBox.size, const Size(48.0, 48.0));
expect(getRawMaterialButtonWidget(smallFabMaterialButton).fillColor, theme.colorScheme.primaryContainer);
expect(getRawMaterialButtonWidget(smallFabMaterialButton).shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)));
expect(
getRawMaterialButtonWidget(smallFabMaterialButton).fillColor,
theme.colorScheme.primaryContainer,
);
expect(
getRawMaterialButtonWidget(smallFabMaterialButton).shape,
RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)),
);
final Finder regularFABMaterialButton = find.byType(RawMaterialButton).at(1);
final RenderBox regularFABRenderBox = tester.renderObject(regularFABMaterialButton);
expect(regularFABRenderBox.size, const Size(56.0, 56.0));
expect(getRawMaterialButtonWidget(regularFABMaterialButton).fillColor, theme.colorScheme.primaryContainer);
expect(getRawMaterialButtonWidget(regularFABMaterialButton).shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(16.0)));
expect(
getRawMaterialButtonWidget(regularFABMaterialButton).fillColor,
theme.colorScheme.primaryContainer,
);
expect(
getRawMaterialButtonWidget(regularFABMaterialButton).shape,
RoundedRectangleBorder(borderRadius: BorderRadius.circular(16.0)),
);
final Finder largeFABMaterialButton = find.byType(RawMaterialButton).at(2);
final RenderBox largeFABRenderBox = tester.renderObject(largeFABMaterialButton);
expect(largeFABRenderBox.size, const Size(96.0, 96.0));
expect(getRawMaterialButtonWidget(largeFABMaterialButton).fillColor, theme.colorScheme.primaryContainer);
expect(getRawMaterialButtonWidget(largeFABMaterialButton).shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(28.0)));
expect(
getRawMaterialButtonWidget(largeFABMaterialButton).fillColor,
theme.colorScheme.primaryContainer,
);
expect(
getRawMaterialButtonWidget(largeFABMaterialButton).shape,
RoundedRectangleBorder(borderRadius: BorderRadius.circular(28.0)),
);
final Finder extendedFABMaterialButton = find.byType(RawMaterialButton).at(3);
final RenderBox extendedFABRenderBox = tester.renderObject(extendedFABMaterialButton);
expect(extendedFABRenderBox.size, within(distance: 0.01, from: const Size(110.3, 56.0)));
expect(getRawMaterialButtonWidget(extendedFABMaterialButton).fillColor, theme.colorScheme.primaryContainer);
expect(getRawMaterialButtonWidget(extendedFABMaterialButton).shape, RoundedRectangleBorder(borderRadius: BorderRadius.circular(16.0)));
expect(
getRawMaterialButtonWidget(extendedFABMaterialButton).fillColor,
theme.colorScheme.primaryContainer,
);
expect(
getRawMaterialButtonWidget(extendedFABMaterialButton).shape,
RoundedRectangleBorder(borderRadius: BorderRadius.circular(16.0)),
);
});
}

View File

@@ -9,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('FloatingActionButton variants', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FloatingActionButtonExampleApp(),
);
await tester.pumpWidget(const example.FloatingActionButtonExampleApp());
FloatingActionButton getFAB(Finder finder) {
return tester.widget<FloatingActionButton>(finder);

View File

@@ -9,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('The FloatingActionButton should have a right padding', (WidgetTester tester) async {
await tester.pumpWidget(
const example.StandardFabLocationExampleApp(),
);
await tester.pumpWidget(const example.StandardFabLocationExampleApp());
expect(find.widgetWithIcon(FloatingActionButton, Icons.add), findsOne);
final double right = tester.getCenter(find.byType(FloatingActionButton)).dx;

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('IconButton increments volume when tapped', (WidgetTester tester) async {
await tester.pumpWidget(
const example.IconButtonExampleApp(),
);
await tester.pumpWidget(const example.IconButtonExampleApp());
expect(find.byIcon(Icons.volume_up), findsOneWidget);
expect(find.text('Volume : 0.0'), findsOneWidget);
@@ -22,9 +20,7 @@ void main() {
});
testWidgets('IconButton shows tooltip when long pressed', (WidgetTester tester) async {
await tester.pumpWidget(
const example.IconButtonExampleApp(),
);
await tester.pumpWidget(const example.IconButtonExampleApp());
expect(find.text('Increase volume by 10'), findsNothing);
await tester.longPress(find.byType(IconButton));

View File

@@ -8,18 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('IconButton', (WidgetTester tester) async {
await tester.pumpWidget(
const example.IconButtonExampleApp(),
);
await tester.pumpWidget(const example.IconButtonExampleApp());
await tester.pumpAndSettle();
expect(find.byIcon(Icons.android), findsOneWidget);
final Ink ink = tester.widget<Ink>(
find.ancestor(
of: find.byIcon(Icons.android),
matching: find.byType(Ink),
),
find.ancestor(of: find.byIcon(Icons.android), matching: find.byType(Ink)),
);
final ShapeDecoration decoration = ink.decoration! as ShapeDecoration;
@@ -27,6 +22,6 @@ void main() {
expect(decoration.shape, const CircleBorder());
final IconButton iconButton = ink.child! as IconButton;
expect(iconButton.color, Colors.white) ;
expect(iconButton.color, Colors.white);
});
}

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('IconButton Types', (WidgetTester tester) async {
await tester.pumpWidget(
const example.IconButtonApp(),
);
await tester.pumpWidget(const example.IconButtonApp());
expect(find.widgetWithIcon(IconButton, Icons.filter_drama), findsNWidgets(8));
final Finder iconButtons = find.widgetWithIcon(IconButton, Icons.filter_drama);
for (int i = 0; i <= 3; i++) {

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('It should select and unselect the icon buttons', (WidgetTester tester) async {
await tester.pumpWidget(
const example.IconButtonToggleApp(),
);
await tester.pumpWidget(const example.IconButtonToggleApp());
expect(find.widgetWithIcon(IconButton, Icons.settings_outlined), findsExactly(8));
final Finder unselectedIconButtons = find.widgetWithIcon(IconButton, Icons.settings_outlined);

View File

@@ -10,25 +10,85 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
const List<int> kTransparentImage = <int>[
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49,
0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x06,
0x00, 0x00, 0x00, 0x1F, 0x15, 0xC4, 0x89, 0x00, 0x00, 0x00, 0x0A, 0x49, 0x44,
0x41, 0x54, 0x78, 0x9C, 0x63, 0x00, 0x01, 0x00, 0x00, 0x05, 0x00, 0x01, 0x0D,
0x0A, 0x2D, 0xB4, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE,
0x89,
0x50,
0x4E,
0x47,
0x0D,
0x0A,
0x1A,
0x0A,
0x00,
0x00,
0x00,
0x0D,
0x49,
0x48,
0x44,
0x52,
0x00,
0x00,
0x00,
0x01,
0x00,
0x00,
0x00,
0x01,
0x08,
0x06,
0x00,
0x00,
0x00,
0x1F,
0x15,
0xC4,
0x89,
0x00,
0x00,
0x00,
0x0A,
0x49,
0x44,
0x41,
0x54,
0x78,
0x9C,
0x63,
0x00,
0x01,
0x00,
0x00,
0x05,
0x00,
0x01,
0x0D,
0x0A,
0x2D,
0xB4,
0x00,
0x00,
0x00,
0x00,
0x49,
0x45,
0x4E,
0x44,
0xAE,
];
testWidgets('Ink ancestor material is not clipped', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: example.ImageClipExample(
image: MemoryImage(Uint8List.fromList(kTransparentImage)),
),
body: example.ImageClipExample(image: MemoryImage(Uint8List.fromList(kTransparentImage))),
),
),
);
final Finder inkMaterialFinder = find.ancestor(of: find.byType(Ink), matching: find.byType(Material));
final Finder inkMaterialFinder = find.ancestor(
of: find.byType(Ink),
matching: find.byType(Material),
);
expect(find.ancestor(of: inkMaterialFinder, matching: find.byType(ClipRRect)), findsNothing);
});
}

View File

@@ -10,25 +10,85 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
const List<int> kTransparentImage = <int>[
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, 0x00, 0x0D, 0x49,
0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x08, 0x06,
0x00, 0x00, 0x00, 0x1F, 0x15, 0xC4, 0x89, 0x00, 0x00, 0x00, 0x0A, 0x49, 0x44,
0x41, 0x54, 0x78, 0x9C, 0x63, 0x00, 0x01, 0x00, 0x00, 0x05, 0x00, 0x01, 0x0D,
0x0A, 0x2D, 0xB4, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE,
0x89,
0x50,
0x4E,
0x47,
0x0D,
0x0A,
0x1A,
0x0A,
0x00,
0x00,
0x00,
0x0D,
0x49,
0x48,
0x44,
0x52,
0x00,
0x00,
0x00,
0x01,
0x00,
0x00,
0x00,
0x01,
0x08,
0x06,
0x00,
0x00,
0x00,
0x1F,
0x15,
0xC4,
0x89,
0x00,
0x00,
0x00,
0x0A,
0x49,
0x44,
0x41,
0x54,
0x78,
0x9C,
0x63,
0x00,
0x01,
0x00,
0x00,
0x05,
0x00,
0x01,
0x0D,
0x0A,
0x2D,
0xB4,
0x00,
0x00,
0x00,
0x00,
0x49,
0x45,
0x4E,
0x44,
0xAE,
];
testWidgets('Ink ancestor material is clipped', (WidgetTester tester) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: example.ImageClipExample(
image: MemoryImage(Uint8List.fromList(kTransparentImage)),
),
body: example.ImageClipExample(image: MemoryImage(Uint8List.fromList(kTransparentImage))),
),
),
);
final Finder inkMaterialFinder = find.ancestor(of: find.byType(Ink), matching: find.byType(Material));
final Finder inkMaterialFinder = find.ancestor(
of: find.byType(Ink),
matching: find.byType(Material),
);
expect(find.ancestor(of: inkMaterialFinder, matching: find.byType(ClipRRect)), findsOneWidget);
});
}

View File

@@ -7,28 +7,31 @@ import 'package:flutter_api_samples/material/ink_well/ink_well.0.dart' as exampl
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Clicking on InkWell changes the Size of 50x50 AnimatedContainer to 100x100 and vice versa', (WidgetTester tester) async {
await tester.pumpWidget(
const example.InkWellExampleApp(),
);
expect(find.widgetWithText(AppBar, 'InkWell Sample'), findsOneWidget);
final Finder inkWell = find.byType(InkWell);
final InkWell inkWellWidget = tester.widget<InkWell>(inkWell);
final Finder animatedContainer = find.byType(AnimatedContainer);
AnimatedContainer animatedContainerWidget = tester.widget<AnimatedContainer>(animatedContainer);
expect(inkWell, findsOneWidget);
expect(inkWellWidget.onTap.runtimeType, VoidCallback);
expect(animatedContainerWidget.constraints?.minWidth, 50);
expect(animatedContainerWidget.constraints?.minHeight, 50);
await tester.tap(inkWell);
await tester.pumpAndSettle();
animatedContainerWidget = tester.widget<AnimatedContainer>(animatedContainer);
expect(animatedContainerWidget.constraints?.minWidth, 100);
expect(animatedContainerWidget.constraints?.minHeight, 100);
await tester.tap(inkWell);
await tester.pumpAndSettle();
animatedContainerWidget = tester.widget<AnimatedContainer>(animatedContainer);
expect(animatedContainerWidget.constraints?.minWidth, 50);
expect(animatedContainerWidget.constraints?.minHeight, 50);
});
testWidgets(
'Clicking on InkWell changes the Size of 50x50 AnimatedContainer to 100x100 and vice versa',
(WidgetTester tester) async {
await tester.pumpWidget(const example.InkWellExampleApp());
expect(find.widgetWithText(AppBar, 'InkWell Sample'), findsOneWidget);
final Finder inkWell = find.byType(InkWell);
final InkWell inkWellWidget = tester.widget<InkWell>(inkWell);
final Finder animatedContainer = find.byType(AnimatedContainer);
AnimatedContainer animatedContainerWidget = tester.widget<AnimatedContainer>(
animatedContainer,
);
expect(inkWell, findsOneWidget);
expect(inkWellWidget.onTap.runtimeType, VoidCallback);
expect(animatedContainerWidget.constraints?.minWidth, 50);
expect(animatedContainerWidget.constraints?.minHeight, 50);
await tester.tap(inkWell);
await tester.pumpAndSettle();
animatedContainerWidget = tester.widget<AnimatedContainer>(animatedContainer);
expect(animatedContainerWidget.constraints?.minWidth, 100);
expect(animatedContainerWidget.constraints?.minHeight, 100);
await tester.tap(inkWell);
await tester.pumpAndSettle();
animatedContainerWidget = tester.widget<AnimatedContainer>(animatedContainer);
expect(animatedContainerWidget.constraints?.minWidth, 50);
expect(animatedContainerWidget.constraints?.minHeight, 50);
},
);
}

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ChipApp(),
);
await tester.pumpWidget(const example.ChipApp());
expect(find.byType(InputChip), findsNWidgets(3));

View File

@@ -3,26 +3,23 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/material/input_chip/input_chip.1.dart'
as example;
import 'package:flutter_api_samples/material/input_chip/input_chip.1.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
final String replacementChar = String.fromCharCode(
example.ChipsInputEditingController.kObjectReplacementChar);
example.ChipsInputEditingController.kObjectReplacementChar,
);
testWidgets('User input generates InputChips', (WidgetTester tester) async {
await tester.pumpWidget(
const example.EditableChipFieldApp(),
);
await tester.pumpWidget(const example.EditableChipFieldApp());
await tester.pumpAndSettle();
expect(find.byType(example.EditableChipFieldApp), findsOneWidget);
expect(find.byType(example.ChipsInput<String>), findsOneWidget);
expect(find.byType(InputChip), findsOneWidget);
example.ChipsInputState<String> state =
tester.state(find.byType(example.ChipsInput<String>));
example.ChipsInputState<String> state = tester.state(find.byType(example.ChipsInput<String>));
expect(state.controller.textWithoutReplacements.isEmpty, true);
await tester.tap(find.byType(example.ChipsInput<String>));
@@ -45,17 +42,15 @@ void main() {
expect(find.byType(InputChip), findsNWidgets(2));
// Simulate item deletion.
await tester.tap(find.descendant(
of: find.byType(InputChip),
matching: find.byType(InkWell).last,
));
await tester.tap(
find.descendant(of: find.byType(InputChip), matching: find.byType(InkWell).last),
);
await tester.pumpAndSettle();
expect(find.byType(InputChip), findsOneWidget);
await tester.tap(find.descendant(
of: find.byType(InputChip),
matching: find.byType(InkWell).last,
));
await tester.tap(
find.descendant(of: find.byType(InputChip), matching: find.byType(InkWell).last),
);
await tester.pumpAndSettle();
expect(find.byType(InputChip), findsNothing);
});

Some files were not shown because too many files have changed in this diff Show More