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

@@ -9,15 +9,10 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('animated digit example', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AnimatedDigitApp(),
);
await tester.pumpWidget(const example.AnimatedDigitApp());
Finder findVisibleDigit(int digit) {
return find.descendant(
of: find.byType(SlideTransition).last,
matching: find.text('$digit'),
);
return find.descendant(of: find.byType(SlideTransition).last, matching: find.text('$digit'));
}
expect(findVisibleDigit(0), findsOneWidget);

View File

@@ -8,14 +8,12 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('The buzz widget should move around', (WidgetTester tester) async {
await tester.pumpWidget(
const example.Curve2DExampleApp(),
);
await tester.pumpWidget(const example.Curve2DExampleApp());
final Finder textFinder = find.widgetWithText(CircleAvatar, 'B');
expect(tester.getCenter(textFinder), const Offset(58, 440));
const List<Offset> expectedOffsets= <Offset>[
const List<Offset> expectedOffsets = <Offset>[
Offset(43, 407),
Offset(81, 272),
Offset(185, 103),

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter_api_samples/cupertino/activity_indicator/cupertino_activity_indicator.0.dart' as example;
import 'package:flutter_api_samples/cupertino/activity_indicator/cupertino_activity_indicator.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Default and customized cupertino activity indicators', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoIndicatorApp(),
);
await tester.pumpWidget(const example.CupertinoIndicatorApp());
// Cupertino activity indicator with default properties.
final Finder firstIndicator = find.byType(CupertinoActivityIndicator).at(0);
@@ -21,7 +20,10 @@ void main() {
final Finder secondIndicator = find.byType(CupertinoActivityIndicator).at(1);
expect(tester.widget<CupertinoActivityIndicator>(secondIndicator).animating, true);
expect(tester.widget<CupertinoActivityIndicator>(secondIndicator).radius, 20.0);
expect(tester.widget<CupertinoActivityIndicator>(secondIndicator).color, CupertinoColors.activeBlue);
expect(
tester.widget<CupertinoActivityIndicator>(secondIndicator).color,
CupertinoColors.activeBlue,
);
// Cupertino activity indicator with custom radius and disabled animation.
final Finder thirdIndicator = find.byType(CupertinoActivityIndicator).at(2);

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can switch between tabs', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoTabBarApp(),
);
await tester.pumpWidget(const example.CupertinoTabBarApp());
expect(find.byType(CupertinoTabBar), findsOneWidget);
expect(find.text('Content of tab 0'), findsOneWidget);

View File

@@ -8,12 +8,16 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Has 4 CupertinoButton variants', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoButtonApp(),
);
await tester.pumpWidget(const example.CupertinoButtonApp());
expect(find.byType(CupertinoButton), findsNWidgets(4));
expect(find.ancestor(of: find.text('Enabled'), matching: find.byType(CupertinoButton)), findsNWidgets(2));
expect(find.ancestor(of: find.text('Disabled'), matching: find.byType(CupertinoButton)), findsNWidgets(2));
expect(
find.ancestor(of: find.text('Enabled'), matching: find.byType(CupertinoButton)),
findsNWidgets(2),
);
expect(
find.ancestor(of: find.text('Disabled'), matching: find.byType(CupertinoButton)),
findsNWidgets(2),
);
});
}

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Checkbox can be checked', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoCheckboxApp(),
);
await tester.pumpWidget(const example.CupertinoCheckboxApp());
CupertinoCheckbox checkbox = tester.widget(find.byType(CupertinoCheckbox));

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/cupertino/context_menu/cupertino_context_menu.0.dart' as example;
import 'package:flutter_api_samples/cupertino/context_menu/cupertino_context_menu.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can open cupertino context menu', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ContextMenuApp(),
);
await tester.pumpWidget(const example.ContextMenuApp());
final Offset logo = tester.getCenter(find.byType(FlutterLogo));
expect(find.text('Favorite'), findsNothing);

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/cupertino/context_menu/cupertino_context_menu.1.dart' as example;
import 'package:flutter_api_samples/cupertino/context_menu/cupertino_context_menu.1.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can open cupertino context menu', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ContextMenuApp(),
);
await tester.pumpWidget(const example.ContextMenuApp());
final Offset logo = tester.getCenter(find.byType(FlutterLogo));
expect(find.text('Favorite'), findsNothing);

View File

@@ -8,18 +8,33 @@ import 'package:flutter_test/flutter_test.dart';
const Offset _kRowOffset = Offset(0.0, -50.0);
void main() {
testWidgets('Can change date, time and dateTime using CupertinoDatePicker', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DatePickerApp(),
);
testWidgets('Can change date, time and dateTime using CupertinoDatePicker', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.DatePickerApp());
// Open the date picker.
await tester.tap(find.text('10-26-2016'));
await tester.pumpAndSettle();
// Drag month, day and year wheels to change the picked date.
await tester.drag(find.text('October'), _kRowOffset, touchSlopY: 0, warnIfMissed: false); // see top of file
await tester.drag(find.textContaining('26').last, _kRowOffset, touchSlopY: 0, warnIfMissed: false); // see top of file
await tester.drag(find.text('2016'), _kRowOffset, touchSlopY: 0, warnIfMissed: false); // see top of file
await tester.drag(
find.text('October'),
_kRowOffset,
touchSlopY: 0,
warnIfMissed: false,
); // see top of file
await tester.drag(
find.textContaining('26').last,
_kRowOffset,
touchSlopY: 0,
warnIfMissed: false,
); // see top of file
await tester.drag(
find.text('2016'),
_kRowOffset,
touchSlopY: 0,
warnIfMissed: false,
); // see top of file
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
@@ -35,8 +50,18 @@ void main() {
await tester.pumpAndSettle();
// Drag hour and minute wheels to change the picked time.
await tester.drag(find.text('22'), const Offset(0.0, 50.0), touchSlopY: 0, warnIfMissed: false); // see top of file
await tester.drag(find.text('35'), const Offset(0.0, 50.0), touchSlopY: 0, warnIfMissed: false); // see top of file
await tester.drag(
find.text('22'),
const Offset(0.0, 50.0),
touchSlopY: 0,
warnIfMissed: false,
); // see top of file
await tester.drag(
find.text('35'),
const Offset(0.0, 50.0),
touchSlopY: 0,
warnIfMissed: false,
); // see top of file
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));
@@ -52,8 +77,18 @@ void main() {
await tester.pumpAndSettle();
// Drag hour and minute wheels to change the picked time.
await tester.drag(find.text('17'), const Offset(0.0, 50.0), touchSlopY: 0, warnIfMissed: false); // see top of file
await tester.drag(find.text('45'), const Offset(0.0, 50.0), touchSlopY: 0, warnIfMissed: false); // see top of file
await tester.drag(
find.text('17'),
const Offset(0.0, 50.0),
touchSlopY: 0,
warnIfMissed: false,
); // see top of file
await tester.drag(
find.text('45'),
const Offset(0.0, 50.0),
touchSlopY: 0,
warnIfMissed: false,
); // see top of file
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));

View File

@@ -9,17 +9,25 @@ const Offset _kRowOffset = Offset(0.0, -50.0);
void main() {
testWidgets('Can pick a duration from CupertinoTimerPicker', (WidgetTester tester) async {
await tester.pumpWidget(
const example.TimerPickerApp(),
);
await tester.pumpWidget(const example.TimerPickerApp());
// Launch the timer picker.
await tester.tap(find.text('1:23:00.000000'));
await tester.pumpAndSettle();
// Drag hour, minute to change the time.
await tester.drag(find.text('1'), _kRowOffset, touchSlopY: 0, warnIfMissed: false); // see top of file
await tester.drag(find.text('23'), _kRowOffset, touchSlopY: 0, warnIfMissed: false); // see top of file
await tester.drag(
find.text('1'),
_kRowOffset,
touchSlopY: 0,
warnIfMissed: false,
); // see top of file
await tester.drag(
find.text('23'),
_kRowOffset,
touchSlopY: 0,
warnIfMissed: false,
); // see top of file
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));

View File

@@ -9,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Perform an action on CupertinoActionSheet', (WidgetTester tester) async {
const String actionText = 'Destructive Action';
await tester.pumpWidget(
const example.ActionSheetApp(),
);
await tester.pumpWidget(const example.ActionSheetApp());
// Launch the CupertinoActionSheet.
await tester.tap(find.byType(CupertinoButton));

View File

@@ -9,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Perform an action on CupertinoAlertDialog', (WidgetTester tester) async {
const String actionText = 'Yes';
await tester.pumpWidget(
const example.AlertDialogApp(),
);
await tester.pumpWidget(const example.AlertDialogApp());
// Launch the CupertinoAlertDialog.
await tester.tap(find.byType(CupertinoButton));

View File

@@ -3,13 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter_api_samples/cupertino/dialog/cupertino_popup_surface.0.dart'
as example;
import 'package:flutter_api_samples/cupertino/dialog/cupertino_popup_surface.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('CupertinoPopupSurface displays expected widgets in init state',
(WidgetTester tester) async {
testWidgets('CupertinoPopupSurface displays expected widgets in init state', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.PopupSurfaceApp());
final Finder cupertinoButton = find.byType(CupertinoButton);
@@ -19,8 +19,9 @@ void main() {
expect(cupertinoSwitch, findsOneWidget);
});
testWidgets('CupertinoPopupSurface is displayed with painted surface',
(WidgetTester tester) async {
testWidgets('CupertinoPopupSurface is displayed with painted surface', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.PopupSurfaceApp());
// CupertinoSwitch is toggled on by default.
@@ -42,8 +43,9 @@ void main() {
expect(coloredBox, findsOneWidget);
});
testWidgets('CupertinoPopupSurface is displayed without painted surface',
(WidgetTester tester) async {
testWidgets('CupertinoPopupSurface is displayed without painted surface', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.PopupSurfaceApp());
// Toggling off CupertinoSwitch and confirm its state.

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Cupertino form section displays cupertino form rows', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoFormRowApp(),
);
await tester.pumpWidget(const example.CupertinoFormRowApp());
expect(find.byType(CupertinoFormSection), findsOneWidget);
expect(find.byType(CupertinoFormRow), findsNWidgets(4));

View File

@@ -8,21 +8,19 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Has exactly 1 CupertinoListSection base widget', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoListSectionBaseApp(),
);
await tester.pumpWidget(const example.CupertinoListSectionBaseApp());
final Finder listSectionFinder = find.byType(CupertinoListSection);
expect(listSectionFinder, findsOneWidget);
final CupertinoListSection listSectionWidget = tester.widget<CupertinoListSection>(listSectionFinder);
final CupertinoListSection listSectionWidget = tester.widget<CupertinoListSection>(
listSectionFinder,
);
expect(listSectionWidget.type, equals(CupertinoListSectionType.base));
});
testWidgets('CupertinoListSection has 3 CupertinoListTile children', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoListSectionBaseApp(),
);
await tester.pumpWidget(const example.CupertinoListSectionBaseApp());
expect(find.byType(CupertinoListTile), findsNWidgets(3));
});

View File

@@ -7,22 +7,22 @@ import 'package:flutter_api_samples/cupertino/list_section/list_section_inset.0.
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Has exactly 1 CupertinoListSection inset grouped widget', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoListSectionInsetApp(),
);
testWidgets('Has exactly 1 CupertinoListSection inset grouped widget', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.CupertinoListSectionInsetApp());
final Finder listSectionFinder = find.byType(CupertinoListSection);
expect(listSectionFinder, findsOneWidget);
final CupertinoListSection listSectionWidget = tester.widget<CupertinoListSection>(listSectionFinder);
final CupertinoListSection listSectionWidget = tester.widget<CupertinoListSection>(
listSectionFinder,
);
expect(listSectionWidget.type, equals(CupertinoListSectionType.insetGrouped));
});
testWidgets('CupertinoListSection has 3 CupertinoListTile children', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoListSectionInsetApp(),
);
await tester.pumpWidget(const example.CupertinoListSectionInsetApp());
expect(find.byType(CupertinoListTile), findsNWidgets(3));
});

View File

@@ -26,7 +26,12 @@ void main() {
expect(find.byIcon(Icons.more_vert), findsNWidgets(3));
expect(find.byIcon(Icons.info), findsOne);
final Finder tileWithBackgroundFinder = find.byKey(const Key('CupertinoListTile with background color'));
expect(tester.firstWidget<CupertinoListTile>(tileWithBackgroundFinder).backgroundColor, Colors.lightBlue);
final Finder tileWithBackgroundFinder = find.byKey(
const Key('CupertinoListTile with background color'),
);
expect(
tester.firstWidget<CupertinoListTile>(tileWithBackgroundFinder).backgroundColor,
Colors.lightBlue,
);
});
}

View File

@@ -8,13 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('CupertinoNavigationBar is semi transparent', (WidgetTester tester) async {
await tester.pumpWidget(
const example.NavBarApp(),
);
await tester.pumpWidget(const example.NavBarApp());
final Finder navBarFinder = find.byType(CupertinoNavigationBar);
expect(navBarFinder, findsOneWidget);
final CupertinoNavigationBar cupertinoNavigationBar = tester.widget<CupertinoNavigationBar>(navBarFinder);
final CupertinoNavigationBar cupertinoNavigationBar = tester.widget<CupertinoNavigationBar>(
navBarFinder,
);
expect(cupertinoNavigationBar.backgroundColor, CupertinoColors.systemGrey.withOpacity(0.5));
});
}

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('CupertinoNavigationBar with bottom widget', (WidgetTester tester) async {
await tester.pumpWidget(
const example.NavBarApp(),
);
await tester.pumpWidget(const example.NavBarApp());
final Finder navBarFinder = find.byType(CupertinoNavigationBar);
final Finder searchFieldFinder = find.byType(CupertinoSearchTextField);

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('CupertinoNavigationBar is large', (WidgetTester tester) async {
await tester.pumpWidget(
const example.NavBarApp(),
);
await tester.pumpWidget(const example.NavBarApp());
final Finder navBarFinder = find.byType(CupertinoNavigationBar);
expect(navBarFinder, findsOneWidget);

View File

@@ -9,10 +9,10 @@ import 'package:flutter_test/flutter_test.dart';
const Offset dragUp = Offset(0.0, -150.0);
void main() {
testWidgets('Collapse and expand CupertinoSliverNavigationBar changes title position', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SliverNavBarApp(),
);
testWidgets('Collapse and expand CupertinoSliverNavigationBar changes title position', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.SliverNavBarApp());
// Large title is visible and at lower position.
expect(tester.getBottomLeft(find.text('Contacts').first).dy, 88.0);
@@ -20,13 +20,16 @@ void main() {
await tester.pumpAndSettle();
// Large title is hidden and at higher position.
expect(tester.getBottomLeft(find.text('Contacts').first).dy, 36.0 + 8.0); // Static part + _kNavBarBottomPadding.
expect(
tester.getBottomLeft(find.text('Contacts').first).dy,
36.0 + 8.0,
); // Static part + _kNavBarBottomPadding.
});
testWidgets('Middle widget is visible in both collapsed and expanded states', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SliverNavBarApp(),
);
testWidgets('Middle widget is visible in both collapsed and expanded states', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.SliverNavBarApp());
// Navigate to a page that has both middle and large titles.
final Finder nextButton = find.text('Go to Next Page');
@@ -43,13 +46,16 @@ void main() {
// Large title is hidden and middle title is visible.
expect(tester.getBottomLeft(find.text('Contacts Group').first).dy, 30.5);
expect(tester.getBottomLeft(find.text('Family').first).dy, 36.0 + 8.0); // Static part + _kNavBarBottomPadding.
expect(
tester.getBottomLeft(find.text('Family').first).dy,
36.0 + 8.0,
); // Static part + _kNavBarBottomPadding.
});
testWidgets('CupertinoSliverNavigationBar with previous route has back button', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SliverNavBarApp(),
);
testWidgets('CupertinoSliverNavigationBar with previous route has back button', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.SliverNavBarApp());
// Navigate to a page that has back button
final Finder nextButton = find.text('Go to Next Page');

View File

@@ -10,10 +10,10 @@ const Offset titleDragUp = Offset(0.0, -100.0);
const Offset bottomDragUp = Offset(0.0, -50.0);
void main() {
testWidgets('Collapse and expand CupertinoSliverNavigationBar changes title position', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SliverNavBarApp(),
);
testWidgets('Collapse and expand CupertinoSliverNavigationBar changes title position', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.SliverNavBarApp());
// Large title is visible and at lower position.
expect(tester.getBottomLeft(find.text('Contacts').first).dy, 88.0);
@@ -21,13 +21,14 @@ void main() {
await tester.pumpAndSettle();
// Large title is hidden and at higher position.
expect(tester.getBottomLeft(find.text('Contacts').first).dy, 36.0 + 8.0); // Static part + _kNavBarBottomPadding.
expect(
tester.getBottomLeft(find.text('Contacts').first).dy,
36.0 + 8.0,
); // Static part + _kNavBarBottomPadding.
});
testWidgets('Search field is hidden in bottom automatic mode', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SliverNavBarApp(),
);
await tester.pumpWidget(const example.SliverNavBarApp());
// Navigate to a page with bottom automatic mode.
final Finder nextButton = find.text('Bottom Automatic mode');
@@ -55,14 +56,15 @@ void main() {
// Large title and search field are hidden and middle title is visible.
expect(tester.getBottomLeft(find.text('Contacts Group').first).dy, 30.5);
expect(tester.getBottomLeft(find.text('Family').first).dy, 36.0 + 8.0); // Static part + _kNavBarBottomPadding.
expect(
tester.getBottomLeft(find.text('Family').first).dy,
36.0 + 8.0,
); // Static part + _kNavBarBottomPadding.
expect(tester.getBottomLeft(find.byType(CupertinoSearchTextField)).dy, 52.0);
});
testWidgets('Search field is always shown in bottom always mode', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SliverNavBarApp(),
);
await tester.pumpWidget(const example.SliverNavBarApp());
// Navigate to a page with bottom always mode.
final Finder nextButton = find.text('Bottom Always mode');
@@ -81,15 +83,18 @@ void main() {
// Large title is hidden, but search field and middle title are visible.
expect(tester.getBottomLeft(find.text('Contacts Group').first).dy, 30.5);
expect(tester.getBottomLeft(find.text('Family').first).dy, 36.0 + 8.0); // Static part + _kNavBarBottomPadding.
expect(
tester.getBottomLeft(find.text('Family').first).dy,
36.0 + 8.0,
); // Static part + _kNavBarBottomPadding.
expect(tester.getTopLeft(find.byType(CupertinoSearchTextField)).dy, 52.0);
expect(tester.getBottomLeft(find.byType(CupertinoSearchTextField)).dy, 87.0);
});
testWidgets('CupertinoSliverNavigationBar with previous route has back button', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SliverNavBarApp(),
);
testWidgets('CupertinoSliverNavigationBar with previous route has back button', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.SliverNavBarApp());
// Navigate to the first page.
final Finder nextButton1 = find.text('Bottom Automatic mode');

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter_api_samples/cupertino/page_scaffold/cupertino_page_scaffold.0.dart' as example;
import 'package:flutter_api_samples/cupertino/page_scaffold/cupertino_page_scaffold.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can increment counter', (WidgetTester tester) async {
await tester.pumpWidget(
const example.PageScaffoldApp(),
);
await tester.pumpWidget(const example.PageScaffoldApp());
expect(find.byType(CupertinoPageScaffold), findsOneWidget);
expect(find.text('You have pressed the button 0 times.'), findsOneWidget);

View File

@@ -10,9 +10,7 @@ const Offset _kRowOffset = Offset(0.0, -50.0);
void main() {
testWidgets('Change selected fruit using CupertinoPicker', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoPickerApp(),
);
await tester.pumpWidget(const example.CupertinoPickerApp());
// Open the Cupertino picker.
await tester.tap(find.widgetWithText(CupertinoButton, 'Apple'));
@@ -23,7 +21,12 @@ void main() {
expect(picker.scrollController!.initialItem, 0);
// Drag the wheel to change fruit selection.
await tester.drag(find.text('Mango'), _kRowOffset, touchSlopY: 0, warnIfMissed: false); // see top of file
await tester.drag(
find.text('Mango'),
_kRowOffset,
touchSlopY: 0,
warnIfMissed: false,
); // see top of file
await tester.pump();
await tester.pump(const Duration(milliseconds: 500));

View File

@@ -8,13 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Has 2 CupertinoRadio widgets', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoRadioApp(),
);
await tester.pumpWidget(const example.CupertinoRadioApp());
expect(find.byType(CupertinoRadio<example.SingingCharacter>), findsNWidgets(2));
CupertinoRadio<example.SingingCharacter> radio = tester.widget(find.byType(CupertinoRadio<example.SingingCharacter>).first);
CupertinoRadio<example.SingingCharacter> radio = tester.widget(
find.byType(CupertinoRadio<example.SingingCharacter>).first,
);
expect(radio.groupValue, example.SingingCharacter.lafayette);
radio = tester.widget(find.byType(CupertinoRadio<example.SingingCharacter>).last);

View File

@@ -8,13 +8,13 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Has 2 CupertinoRadio widgets that can be toggled off', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoRadioApp(),
);
await tester.pumpWidget(const example.CupertinoRadioApp());
expect(find.byType(CupertinoRadio<example.SingingCharacter>), findsNWidgets(2));
CupertinoRadio<example.SingingCharacter> radio = tester.widget(find.byType(CupertinoRadio<example.SingingCharacter>).first);
CupertinoRadio<example.SingingCharacter> radio = tester.widget(
find.byType(CupertinoRadio<example.SingingCharacter>).first,
);
expect(radio.groupValue, example.SingingCharacter.mulligan);
radio = tester.widget(find.byType(CupertinoRadio<example.SingingCharacter>).last);

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter_api_samples/cupertino/refresh/cupertino_sliver_refresh_control.0.dart' as example;
import 'package:flutter_api_samples/cupertino/refresh/cupertino_sliver_refresh_control.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can pull down to reveal CupertinoSliverRefreshControl', (WidgetTester tester) async {
await tester.pumpWidget(
const example.RefreshControlApp(),
);
await tester.pumpWidget(const example.RefreshControlApp());
expect(find.byType(CupertinoSliverRefreshControl), findsNothing);
expect(find.byType(Container), findsNWidgets(3));

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Tap on button displays cupertino dialog', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoDialogApp(),
);
await tester.pumpWidget(const example.CupertinoDialogApp());
final Finder dialogTitle = find.text('Title');
expect(dialogTitle, findsNothing);

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Tap on button displays cupertino modal dialog', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ModalPopupApp(),
);
await tester.pumpWidget(const example.ModalPopupApp());
final Finder actionOne = find.text('Action One');
expect(actionOne, findsNothing);

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('List view displays CupertinoScrollbar', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ScrollbarApp(),
);
await tester.pumpWidget(const example.ScrollbarApp());
expect(find.text('Item 0'), findsOneWidget);
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(ListView)));

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('List view displays CupertinoScrollbar', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ScrollbarApp(),
);
await tester.pumpWidget(const example.ScrollbarApp());
expect(find.text('Item 0'), findsOneWidget);
final TestGesture gesture = await tester.startGesture(tester.getCenter(find.byType(ListView)));

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter_api_samples/cupertino/search_field/cupertino_search_field.0.dart' as example;
import 'package:flutter_api_samples/cupertino/search_field/cupertino_search_field.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('CupertinoTextField has initial text', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SearchTextFieldApp(),
);
await tester.pumpWidget(const example.SearchTextFieldApp());
expect(find.byType(CupertinoSearchTextField), findsOneWidget);
expect(find.text('initial text'), findsOneWidget);

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter_api_samples/cupertino/search_field/cupertino_search_field.1.dart' as example;
import 'package:flutter_api_samples/cupertino/search_field/cupertino_search_field.1.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Value changed callback updates entered text', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SearchTextFieldApp(),
);
await tester.pumpWidget(const example.SearchTextFieldApp());
expect(find.byType(CupertinoSearchTextField), findsOneWidget);

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter_api_samples/cupertino/segmented_control/cupertino_segmented_control.0.dart' as example;
import 'package:flutter_api_samples/cupertino/segmented_control/cupertino_segmented_control.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Verify initial state', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SegmentedControlApp(),
);
await tester.pumpWidget(const example.SegmentedControlApp());
// Midnight is the default selected segment.
expect(find.text('Selected Segment: midnight'), findsOneWidget);
@@ -40,9 +39,7 @@ void main() {
});
testWidgets('Can change a selected segmented control', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SegmentedControlApp(),
);
await tester.pumpWidget(const example.SegmentedControlApp());
expect(find.text('Selected Segment: midnight'), findsOneWidget);
@@ -53,9 +50,7 @@ void main() {
});
testWidgets('Can not select on a disabled segment', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SegmentedControlApp(),
);
await tester.pumpWidget(const example.SegmentedControlApp());
// Toggle on the first CupertinoSwitch to disable the first segment.
final Finder firstSwitchFinder = find.byType(CupertinoSwitch).first;
@@ -76,9 +71,7 @@ void main() {
});
testWidgets('Can not select on all disabled segments', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SegmentedControlApp(),
);
await tester.pumpWidget(const example.SegmentedControlApp());
// Toggle off the second CupertinoSwitch to disable all segments.
final Finder secondSwitchFinder = find.byType(CupertinoSwitch).last;

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/cupertino/segmented_control/cupertino_sliding_segmented_control.0.dart' as example;
import 'package:flutter_api_samples/cupertino/segmented_control/cupertino_sliding_segmented_control.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can change a selected segmented control', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SegmentedControlApp(),
);
await tester.pumpWidget(const example.SegmentedControlApp());
expect(find.text('Selected Segment: midnight'), findsOneWidget);
await tester.tap(find.text('Cerulean'));

View File

@@ -15,9 +15,7 @@ void main() {
}
testWidgets('Can change value using CupertinoSlider', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoSliderApp(),
);
await tester.pumpWidget(const example.CupertinoSliderApp());
// Check for the initial slider value.
expect(find.text('0.0'), findsOneWidget);

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Toggling cupertino switch updates icon', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CupertinoSwitchApp(),
);
await tester.pumpWidget(const example.CupertinoSwitchApp());
final Finder switchFinder = find.byType(CupertinoSwitch);
CupertinoSwitch cupertinoSwitch = tester.widget<CupertinoSwitch>(switchFinder);

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter_api_samples/cupertino/tab_scaffold/cupertino_tab_controller.0.dart' as example;
import 'package:flutter_api_samples/cupertino/tab_scaffold/cupertino_tab_controller.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can switch tabs using CupertinoTabController', (WidgetTester tester) async {
await tester.pumpWidget(
const example.TabControllerApp(),
);
await tester.pumpWidget(const example.TabControllerApp());
expect(find.text('Content of tab 0'), findsOneWidget);
await tester.tap(find.byIcon(CupertinoIcons.star_circle_fill));

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter_api_samples/cupertino/tab_scaffold/cupertino_tab_scaffold.0.dart' as example;
import 'package:flutter_api_samples/cupertino/tab_scaffold/cupertino_tab_scaffold.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can use CupertinoTabView as the root widget', (WidgetTester tester) async {
await tester.pumpWidget(
const example.TabScaffoldApp(),
);
await tester.pumpWidget(const example.TabScaffoldApp());
expect(find.text('Page 1 of tab 0'), findsOneWidget);
await tester.tap(find.byIcon(CupertinoIcons.search_circle_fill));

View File

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

View File

@@ -4,14 +4,12 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter_api_samples/cupertino/text_form_field_row/cupertino_text_form_field_row.1.dart'
as example;
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can enter text in CupertinoTextFormFieldRow', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FormSectionApp(),
);
await tester.pumpWidget(const example.FormSectionApp());
expect(find.byType(CupertinoFormSection), findsOneWidget);
expect(find.byType(CupertinoTextFormFieldRow), findsNWidgets(5));

View File

@@ -4,7 +4,6 @@
import 'dart:async';
import 'goldens_io.dart' if (dart.library.js_interop) 'goldens_web.dart' as flutter_goldens;
Future<void> testExecutable(FutureOr<void> Function() testMain) {

View File

@@ -19,14 +19,9 @@ void main() {
}
testWidgets('Scrolling on the boxes changes their color', (WidgetTester tester) async {
await tester.pumpWidget(
const example.PointerSignalResolverExampleApp(),
);
await tester.pumpWidget(const example.PointerSignalResolverExampleApp());
expect(
getColors(tester),
(outer: const Color(0x3300ff00), inner: const Color(0xffffff00)),
);
expect(getColors(tester), (outer: const Color(0x3300ff00), inner: const Color(0xffffff00)));
// Scroll on the outer box.
final TestPointer pointer = TestPointer(1, PointerDeviceKind.mouse);
@@ -69,10 +64,7 @@ void main() {
// The inner box changes color.
colors = getColors(tester);
expect(
colors.outer,
const Color(0x3300ff26),
);
expect(colors.outer, const Color(0x3300ff26));
expect(colors.inner, const Color(0xffe5ff00));
});
}

View File

@@ -3,15 +3,14 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/gestures/tap_and_drag/tap_and_drag.0.dart'
as example;
import 'package:flutter_api_samples/gestures/tap_and_drag/tap_and_drag.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Single tap + drag should not change the scale of child', (WidgetTester tester) async {
await tester.pumpWidget(
const example.TapAndDragToZoomApp(),
);
testWidgets('Single tap + drag should not change the scale of child', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.TapAndDragToZoomApp());
double getScale() {
final RenderBox box = tester.renderObject(find.byType(Container).first);
@@ -36,10 +35,10 @@ void main() {
expect(getScale(), 1.0);
});
testWidgets('Double tap + drag should change the scale of the child', (WidgetTester tester) async {
await tester.pumpWidget(
const example.TapAndDragToZoomApp(),
);
testWidgets('Double tap + drag should change the scale of the child', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.TapAndDragToZoomApp());
double getScale() {
final RenderBox box = tester.renderObject(find.byType(Container).first);

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

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