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

@@ -12,12 +12,12 @@ void main() {
final _MockClipboard mockClipboard = _MockClipboard();
testWidgets('Copies text on Ctrl-C', (WidgetTester tester) async {
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.platform, mockClipboard.handleMethodCall);
await tester.pumpWidget(const MaterialApp(
home: Scaffold(
body: Center(child: example.VerificationCodeGenerator()),
),
),
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(
SystemChannels.platform,
mockClipboard.handleMethodCall,
);
await tester.pumpWidget(
const MaterialApp(home: Scaffold(body: Center(child: example.VerificationCodeGenerator()))),
);
expect(primaryFocus, isNotNull);

View File

@@ -8,7 +8,9 @@ import 'package:flutter_api_samples/widgets/actions/action_listener.0.dart' as e
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('ActionListener can be enabled, triggered, and disabled', (WidgetTester tester) async {
testWidgets('ActionListener can be enabled, triggered, and disabled', (
WidgetTester tester,
) async {
final List<String?> log = <String?>[];
final DebugPrintCallback originalDebugPrint = debugPrint;
@@ -16,9 +18,7 @@ void main() {
log.add(message);
};
try {
await tester.pumpWidget(
const example.ActionListenerExampleApp(),
);
await tester.pumpWidget(const example.ActionListenerExampleApp());
expect(find.widgetWithText(AppBar, 'ActionListener Sample'), findsOne);
expect(find.widgetWithText(OutlinedButton, 'Enable'), findsOne);
@@ -39,10 +39,7 @@ void main() {
await tester.pump();
expect(find.widgetWithText(OutlinedButton, 'Enable'), findsOne);
expect(
log,
const <String?>['Action Listener was added', 'Action Listener was removed'],
);
expect(log, const <String?>['Action Listener was added', 'Action Listener was removed']);
} finally {
debugPrint = originalDebugPrint;
}

View File

@@ -12,9 +12,7 @@ void main() {
final ButtonStyleButton button = tester.widget<ButtonStyleButton>(
find.descendant(
of: find.byType(example.SaveButton),
matching: find.byWidgetPredicate(
(Widget widget) => widget is TextButton,
),
matching: find.byWidgetPredicate((Widget widget) => widget is TextButton),
),
);
@@ -22,9 +20,7 @@ void main() {
}
testWidgets('Increments and decrements value', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ActionsExampleApp(),
);
await tester.pumpWidget(const example.ActionsExampleApp());
int value = 0;
@@ -50,9 +46,7 @@ void main() {
});
testWidgets('SaveButton indicates dirty status', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ActionsExampleApp(),
);
await tester.pumpWidget(const example.ActionsExampleApp());
// Verify that initial color is green, as the value is not marked as dirty.
Color? saveButtonColor = getSaveButtonColor(tester);
@@ -85,18 +79,13 @@ void main() {
log.add(message);
};
await tester.pumpWidget(
const example.ActionsExampleApp(),
);
await tester.pumpWidget(const example.ActionsExampleApp());
// Verify that value is not marked as dirty.
Color? saveButtonColor = getSaveButtonColor(tester);
expect(saveButtonColor, equals(Colors.green));
expect(
find.descendant(
of: find.byType(example.SaveButton),
matching: find.text('0'),
),
find.descendant(of: find.byType(example.SaveButton), matching: find.text('0')),
findsOneWidget,
);
@@ -109,10 +98,7 @@ void main() {
saveButtonColor = getSaveButtonColor(tester);
expect(saveButtonColor, equals(Colors.red));
expect(
find.descendant(
of: find.byType(example.SaveButton),
matching: find.text('0'),
),
find.descendant(of: find.byType(example.SaveButton), matching: find.text('0')),
findsOneWidget,
);
@@ -128,10 +114,7 @@ void main() {
saveButtonColor = getSaveButtonColor(tester);
expect(saveButtonColor, equals(Colors.green));
expect(
find.descendant(
of: find.byType(example.SaveButton),
matching: find.text('-1'),
),
find.descendant(of: find.byType(example.SaveButton), matching: find.text('-1')),
findsOneWidget,
);

View File

@@ -13,9 +13,7 @@ void main() {
);
testWidgets('Taps on the "And me" button toggle the red box', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FocusableActionDetectorExampleApp(),
);
await tester.pumpWidget(const example.FocusableActionDetectorExampleApp());
expect(find.widgetWithText(AppBar, 'FocusableActionDetector Example'), findsOne);
@@ -32,10 +30,10 @@ void main() {
expect(redContainerFinder, findsNothing);
});
testWidgets('Hits on the X key when "And me" is focused toggle the red box', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FocusableActionDetectorExampleApp(),
);
testWidgets('Hits on the X key when "And me" is focused toggle the red box', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.FocusableActionDetectorExampleApp());
expect(find.widgetWithText(AppBar, 'FocusableActionDetector Example'), findsOne);

View File

@@ -3,15 +3,12 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/animated_grid/animated_grid.0.dart'
as example;
import 'package:flutter_api_samples/widgets/animated_grid/animated_grid.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('AnimatedGrid example', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AnimatedGridSample(),
);
await tester.pumpWidget(const example.AnimatedGridSample());
expect(find.text('1'), findsOneWidget);
expect(find.text('2'), findsOneWidget);

View File

@@ -3,15 +3,12 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/animated_grid/sliver_animated_grid.0.dart'
as example;
import 'package:flutter_api_samples/widgets/animated_grid/sliver_animated_grid.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('SliverAnimatedGrid example', (WidgetTester tester) async {
await tester.pumpWidget(
const example.SliverAnimatedGridSample(),
);
await tester.pumpWidget(const example.SliverAnimatedGridSample());
expect(find.text('1'), findsOneWidget);
expect(find.text('2'), findsOneWidget);

View File

@@ -7,39 +7,38 @@ import 'package:flutter_api_samples/widgets/animated_list/animated_list.0.dart'
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'Items can be selected, added, and removed from AnimatedList',
(WidgetTester tester) async {
await tester.pumpWidget(const example.AnimatedListSample());
testWidgets('Items can be selected, added, and removed from AnimatedList', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.AnimatedListSample());
expect(find.text('Item 0'), findsOne);
expect(find.text('Item 1'), findsOne);
expect(find.text('Item 2'), findsOne);
expect(find.text('Item 0'), findsOne);
expect(find.text('Item 1'), findsOne);
expect(find.text('Item 2'), findsOne);
// Add an item at the end of the list.
await tester.tap(find.byIcon(Icons.add_circle));
await tester.pumpAndSettle();
expect(find.text('Item 3'), findsOne);
// Add an item at the end of the list.
await tester.tap(find.byIcon(Icons.add_circle));
await tester.pumpAndSettle();
expect(find.text('Item 3'), findsOne);
// Select Item 1.
await tester.tap(find.text('Item 1'));
await tester.pumpAndSettle();
// Select Item 1.
await tester.tap(find.text('Item 1'));
await tester.pumpAndSettle();
// Add item at the top of the list.
await tester.tap(find.byIcon(Icons.add_circle));
await tester.pumpAndSettle();
expect(find.text('Item 4'), findsOne);
// Add item at the top of the list.
await tester.tap(find.byIcon(Icons.add_circle));
await tester.pumpAndSettle();
expect(find.text('Item 4'), findsOne);
// Remove selected item.
await tester.tap(find.byIcon(Icons.remove_circle));
// Remove selected item.
await tester.tap(find.byIcon(Icons.remove_circle));
// Item animation is not completed.
await tester.pump();
expect(find.text('Item 1'), findsOne);
// Item animation is not completed.
await tester.pump();
expect(find.text('Item 1'), findsOne);
// When the animation completes, Item 1 disappears.
await tester.pumpAndSettle();
expect(find.text('Item 1'), findsNothing);
},
);
// When the animation completes, Item 1 disappears.
await tester.pumpAndSettle();
expect(find.text('Item 1'), findsNothing);
});
}

View File

@@ -3,54 +3,54 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/animated_list/animated_list_separated.0.dart' as example;
import 'package:flutter_api_samples/widgets/animated_list/animated_list_separated.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'Items can be selected, added, and removed from AnimatedList.separated',
(WidgetTester tester) async {
await tester.pumpWidget(const example.AnimatedListSeparatedSample());
testWidgets('Items can be selected, added, and removed from AnimatedList.separated', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.AnimatedListSeparatedSample());
expect(find.text('Item 0'), findsOneWidget);
expect(find.text('Separator 0'), findsOneWidget);
expect(find.text('Item 1'), findsOneWidget);
expect(find.text('Separator 1'), findsOneWidget);
expect(find.text('Item 2'), findsOneWidget);
expect(find.text('Item 0'), findsOneWidget);
expect(find.text('Separator 0'), findsOneWidget);
expect(find.text('Item 1'), findsOneWidget);
expect(find.text('Separator 1'), findsOneWidget);
expect(find.text('Item 2'), findsOneWidget);
// Add an item at the end of the list
await tester.tap(find.byIcon(Icons.add_circle));
await tester.pumpAndSettle();
expect(find.text('Separator 2'), findsOneWidget);
expect(find.text('Item 3'), findsOneWidget);
// Add an item at the end of the list
await tester.tap(find.byIcon(Icons.add_circle));
await tester.pumpAndSettle();
expect(find.text('Separator 2'), findsOneWidget);
expect(find.text('Item 3'), findsOneWidget);
// Select Item 1.
await tester.tap(find.text('Item 1'));
await tester.pumpAndSettle();
// Select Item 1.
await tester.tap(find.text('Item 1'));
await tester.pumpAndSettle();
// Add item at the top of the list
await tester.tap(find.byIcon(Icons.add_circle));
await tester.pumpAndSettle();
expect(find.text('Item 4'), findsOneWidget);
// Contrary to the behavior for insertion at other places,
// the Separator for the last item of the list will be added
// before that item instead of after it.
expect(find.text('Separator 4'), findsOneWidget);
// Add item at the top of the list
await tester.tap(find.byIcon(Icons.add_circle));
await tester.pumpAndSettle();
expect(find.text('Item 4'), findsOneWidget);
// Contrary to the behavior for insertion at other places,
// the Separator for the last item of the list will be added
// before that item instead of after it.
expect(find.text('Separator 4'), findsOneWidget);
// Remove selected item.
await tester.tap(find.byIcon(Icons.remove_circle));
// Remove selected item.
await tester.tap(find.byIcon(Icons.remove_circle));
// Item animation is not completed.
await tester.pump();
expect(find.text('Item 1'), findsOneWidget);
expect(find.text('Separator 1'), findsNothing);
expect(find.text('Removing separator'), findsOneWidget);
// Item animation is not completed.
await tester.pump();
expect(find.text('Item 1'), findsOneWidget);
expect(find.text('Separator 1'), findsNothing);
expect(find.text('Removing separator'), findsOneWidget);
// When the animation completes, Item 1 disappears.
await tester.pumpAndSettle();
expect(find.text('Item 1'), findsNothing);
expect(find.text('Separator 1'), findsNothing);
expect(find.text('Removing separator'), findsNothing);
},
);
// When the animation completes, Item 1 disappears.
await tester.pumpAndSettle();
expect(find.text('Item 1'), findsNothing);
expect(find.text('Separator 1'), findsNothing);
expect(find.text('Removing separator'), findsNothing);
});
}

View File

@@ -7,39 +7,38 @@ import 'package:flutter_api_samples/widgets/animated_list/sliver_animated_list.0
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'Items can be selected, added, and removed from SliverAnimatedList',
(WidgetTester tester) async {
await tester.pumpWidget(const example.SliverAnimatedListSample());
testWidgets('Items can be selected, added, and removed from SliverAnimatedList', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.SliverAnimatedListSample());
expect(find.text('Item 0'), findsOneWidget);
expect(find.text('Item 1'), findsOneWidget);
expect(find.text('Item 2'), findsOneWidget);
expect(find.text('Item 0'), findsOneWidget);
expect(find.text('Item 1'), findsOneWidget);
expect(find.text('Item 2'), findsOneWidget);
// Add an item at the end of the list
await tester.tap(find.byIcon(Icons.add_circle));
await tester.pumpAndSettle();
expect(find.text('Item 3'), findsOneWidget);
// Add an item at the end of the list
await tester.tap(find.byIcon(Icons.add_circle));
await tester.pumpAndSettle();
expect(find.text('Item 3'), findsOneWidget);
// Select Item 1.
await tester.tap(find.text('Item 1'));
await tester.pumpAndSettle();
// Select Item 1.
await tester.tap(find.text('Item 1'));
await tester.pumpAndSettle();
// Add item at the top of the list
await tester.tap(find.byIcon(Icons.add_circle));
await tester.pumpAndSettle();
expect(find.text('Item 4'), findsOneWidget);
// Add item at the top of the list
await tester.tap(find.byIcon(Icons.add_circle));
await tester.pumpAndSettle();
expect(find.text('Item 4'), findsOneWidget);
// Remove selected item.
await tester.tap(find.byIcon(Icons.remove_circle));
// Remove selected item.
await tester.tap(find.byIcon(Icons.remove_circle));
// Item animation is not completed.
await tester.pump();
expect(find.text('Item 1'), findsOneWidget);
// Item animation is not completed.
await tester.pump();
expect(find.text('Item 1'), findsOneWidget);
// When the animation completes, Item 1 disappears.
await tester.pumpAndSettle();
expect(find.text('Item 1'), findsNothing);
},
);
// When the animation completes, Item 1 disappears.
await tester.pumpAndSettle();
expect(find.text('Item 1'), findsNothing);
});
}

View File

@@ -3,15 +3,12 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/animated_size/animated_size.0.dart'
as example;
import 'package:flutter_api_samples/widgets/animated_size/animated_size.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('AnimatedSize animates on tap', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AnimatedSizeExampleApp(),
);
await tester.pumpWidget(const example.AnimatedSizeExampleApp());
const Size beginSize = Size.square(100.0);
const Size endSize = Size.square(250.0);
@@ -27,22 +24,15 @@ void main() {
expect(box.size, equals(beginSize));
// Advance animation to the middle.
await tester.pump(
example.AnimatedSizeExampleApp.duration ~/ 2,
);
await tester.pump(example.AnimatedSizeExampleApp.duration ~/ 2);
final double t = example.AnimatedSizeExampleApp.curve.transform(0.5);
box = tester.renderObject(find.byType(AnimatedSize));
expect(
box.size,
equals(Size.lerp(beginSize, endSize, t)),
);
expect(box.size, equals(Size.lerp(beginSize, endSize, t)));
// Advance animation to the end.
await tester.pump(
example.AnimatedSizeExampleApp.duration ~/ 2,
);
await tester.pump(example.AnimatedSizeExampleApp.duration ~/ 2);
box = tester.renderObject(find.byType(AnimatedSize));
expect(box.size, equals(endSize));
@@ -55,20 +45,13 @@ void main() {
expect(box.size, equals(endSize));
// Advance animation to the middle.
await tester.pump(
example.AnimatedSizeExampleApp.duration ~/ 2,
);
await tester.pump(example.AnimatedSizeExampleApp.duration ~/ 2);
box = tester.renderObject(find.byType(AnimatedSize));
expect(
box.size,
equals(Size.lerp(endSize, beginSize, t)),
);
expect(box.size, equals(Size.lerp(endSize, beginSize, t)));
// Advance animation to the end.
await tester.pump(
example.AnimatedSizeExampleApp.duration ~/ 2,
);
await tester.pump(example.AnimatedSizeExampleApp.duration ~/ 2);
box = tester.renderObject(find.byType(AnimatedSize));
expect(box.size, equals(beginSize));

View File

@@ -3,15 +3,12 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/animated_switcher/animated_switcher.0.dart'
as example;
import 'package:flutter_api_samples/widgets/animated_switcher/animated_switcher.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Increments counter on button tap', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AnimatedSwitcherExampleApp(),
);
await tester.pumpWidget(const example.AnimatedSwitcherExampleApp());
int counter = 0;
@@ -20,10 +17,7 @@ void main() {
while (counter < 10) {
// Tap on the button to increment the counter.
await tester.tap(
find.ancestor(
of: find.text('Increment'),
matching: find.byType(ElevatedButton),
),
find.ancestor(of: find.text('Increment'), matching: find.byType(ElevatedButton)),
);
await tester.pumpAndSettle();
@@ -35,9 +29,7 @@ void main() {
});
testWidgets('Animates counter change', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AnimatedSwitcherExampleApp(),
);
await tester.pumpWidget(const example.AnimatedSwitcherExampleApp());
// The animation duration defined in the example app.
const Duration animationDuration = Duration(milliseconds: 500);
@@ -59,10 +51,7 @@ void main() {
// Tap on the button to increment the counter.
await tester.tap(
find.ancestor(
of: find.text('Increment'),
matching: find.byType(ElevatedButton),
),
find.ancestor(of: find.text('Increment'), matching: find.byType(ElevatedButton)),
);
await tester.pump();

View File

@@ -7,9 +7,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('WidgetsApp test', (WidgetTester tester) async {
await tester.pumpWidget(
const example.WidgetsAppExampleApp(),
);
await tester.pumpWidget(const example.WidgetsAppExampleApp());
expect(find.text('Hello World'), findsOneWidget);
});

View File

@@ -2,14 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_api_samples/widgets/app_lifecycle_listener/app_lifecycle_listener.0.dart' as example;
import 'package:flutter_api_samples/widgets/app_lifecycle_listener/app_lifecycle_listener.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('AppLifecycleListener example', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AppLifecycleListenerExample(),
);
await tester.pumpWidget(const example.AppLifecycleListenerExample());
expect(find.textContaining('Current State:'), findsOneWidget);
expect(find.textContaining('State History:'), findsOneWidget);

View File

@@ -2,14 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter_api_samples/widgets/app_lifecycle_listener/app_lifecycle_listener.1.dart' as example;
import 'package:flutter_api_samples/widgets/app_lifecycle_listener/app_lifecycle_listener.1.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('AppLifecycleListener example', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AppLifecycleListenerExample(),
);
await tester.pumpWidget(const example.AppLifecycleListenerExample());
expect(find.text('Do Not Allow Exit'), findsOneWidget);
expect(find.text('Allow Exit'), findsOneWidget);

View File

@@ -3,15 +3,12 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/async/future_builder.0.dart'
as example;
import 'package:flutter_api_samples/widgets/async/future_builder.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('StreamBuilder listens to internal stream', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FutureBuilderExampleApp(),
);
await tester.pumpWidget(const example.FutureBuilderExampleApp());
expect(find.byType(CircularProgressIndicator), findsOne);
expect(find.text('Awaiting result...'), findsOne);

View File

@@ -5,15 +5,12 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/async/stream_builder.0.dart'
as example;
import 'package:flutter_api_samples/widgets/async/stream_builder.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('StreamBuilder listens to internal stream', (WidgetTester tester) async {
await tester.pumpWidget(
const example.StreamBuilderExampleApp(),
);
await tester.pumpWidget(const example.StreamBuilderExampleApp());
expect(find.byType(CircularProgressIndicator), findsOneWidget);
expect(find.text('Awaiting bids...'), findsOneWidget);
@@ -37,11 +34,7 @@ void main() {
controller.addError('Unexpected error!', StackTrace.empty);
};
await tester.pumpWidget(
MaterialApp(
home: example.BidsStatus(bids: controller.stream),
),
);
await tester.pumpWidget(MaterialApp(home: example.BidsStatus(bids: controller.stream)));
await tester.pump();
expect(find.byIcon(Icons.error_outline), findsOneWidget);
@@ -50,11 +43,7 @@ void main() {
});
testWidgets('BidsStatus correctly displays none state', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: example.BidsStatus(bids: null),
),
);
await tester.pumpWidget(const MaterialApp(home: example.BidsStatus(bids: null)));
expect(find.byIcon(Icons.info), findsOneWidget);
expect(find.text('Select a lot'), findsOneWidget);
@@ -64,11 +53,7 @@ void main() {
final StreamController<int> controller = StreamController<int>();
addTearDown(controller.close);
await tester.pumpWidget(
MaterialApp(
home: example.BidsStatus(bids: controller.stream),
),
);
await tester.pumpWidget(MaterialApp(home: example.BidsStatus(bids: controller.stream)));
expect(find.byType(CircularProgressIndicator), findsOneWidget);
expect(find.text('Awaiting bids...'), findsOneWidget);
@@ -82,11 +67,7 @@ void main() {
controller.add(1);
};
await tester.pumpWidget(
MaterialApp(
home: example.BidsStatus(bids: controller.stream),
),
);
await tester.pumpWidget(MaterialApp(home: example.BidsStatus(bids: controller.stream)));
await tester.pump();
expect(find.byIcon(Icons.check_circle_outline), findsOneWidget);
@@ -97,11 +78,7 @@ void main() {
final StreamController<int> controller = StreamController<int>();
controller.close();
await tester.pumpWidget(
MaterialApp(
home: example.BidsStatus(bids: controller.stream),
),
);
await tester.pumpWidget(MaterialApp(home: example.BidsStatus(bids: controller.stream)));
await tester.pump();
expect(find.byIcon(Icons.info), findsOneWidget);

View File

@@ -39,9 +39,9 @@ void main() {
await tester.pump();
expect(find.byType(ListTile), findsNothing);
expect(find.descendant(
of: find.byType(TextFormField),
matching: find.text('bobcat'),
), findsOneWidget);
expect(
find.descendant(of: find.byType(TextFormField), matching: find.text('bobcat')),
findsOneWidget,
);
});
}

View File

@@ -39,10 +39,10 @@ void main() {
await tester.pump();
expect(find.byType(ListTile), findsNothing);
expect(find.descendant(
of: find.byType(TextFormField),
matching: find.text('Bob'),
), findsOneWidget);
expect(
find.descendant(of: find.byType(TextFormField), matching: find.text('Bob')),
findsOneWidget,
);
});
testWidgets('Finds users by email address', (WidgetTester tester) async {
@@ -68,9 +68,9 @@ void main() {
await tester.pump();
expect(find.byType(ListTile), findsNothing);
expect(find.descendant(
of: find.byType(TextFormField),
matching: find.text('Charlie'),
), findsOneWidget);
expect(
find.descendant(of: find.byType(TextFormField), matching: find.text('Charlie')),
findsOneWidget,
);
});
}

View File

@@ -7,7 +7,9 @@ import 'package:flutter_api_samples/widgets/autocomplete/raw_autocomplete.2.dart
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Form is entirely visible and rejects invalid responses', (WidgetTester tester) async {
testWidgets('Form is entirely visible and rejects invalid responses', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.AutocompleteExampleApp());
expect(find.text('RawAutocomplete Form'), findsOneWidget);
expect(find.byType(TextFormField), findsNWidgets(2));
@@ -58,10 +60,12 @@ void main() {
'regular user input',
);
await tester.tap(find.ancestor(
of: find.text('This is a RawAutocomplete!'),
matching: find.byType(TextFormField),
));
await tester.tap(
find.ancestor(
of: find.text('This is a RawAutocomplete!'),
matching: find.byType(TextFormField),
),
);
await tester.pump();
expect(find.text('aardvark'), findsOneWidget);
expect(find.text('bobcat'), findsOneWidget);

View File

@@ -3,7 +3,8 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/autocomplete/raw_autocomplete.focus_node.0.dart' as example;
import 'package:flutter_api_samples/widgets/autocomplete/raw_autocomplete.focus_node.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
@@ -13,10 +14,7 @@ void main() {
expect(find.byType(AppBar), findsOneWidget);
expect(find.byType(TextFormField), findsOneWidget);
expect(
find.descendant(
of: find.byType(AppBar),
matching: find.byType(TextFormField)
),
find.descendant(of: find.byType(AppBar), matching: find.byType(TextFormField)),
findsOneWidget,
);
@@ -25,10 +23,7 @@ void main() {
expect(find.text('bobcat'), findsNothing);
expect(find.text('chameleon'), findsNothing);
expect(
find.ancestor(
matching: find.byType(AppBar),
of: find.byType(RawAutocomplete)
),
find.ancestor(matching: find.byType(AppBar), of: find.byType(RawAutocomplete)),
findsNothing,
);
});
@@ -56,10 +51,7 @@ void main() {
expect(find.byType(ListTile), findsNothing);
expect(
find.descendant(
of: find.byType(TextFormField),
matching: find.text('bobcat'),
),
find.descendant(of: find.byType(TextFormField), matching: find.text('bobcat')),
findsOneWidget,
);
});

View File

@@ -33,70 +33,32 @@ void main() {
findsNWidgets(7), // 5 initial + 2 billing address fields
);
final TextField shippingAddress1 = tester.widget(
find.byType(TextField).at(0),
);
expect(
shippingAddress1.autofillHints,
contains(AutofillHints.streetAddressLine1),
);
final TextField shippingAddress1 = tester.widget(find.byType(TextField).at(0));
expect(shippingAddress1.autofillHints, contains(AutofillHints.streetAddressLine1));
final TextField shippingAddress2 = tester.widget(
find.byType(TextField).at(1),
);
expect(
shippingAddress2.autofillHints,
contains(AutofillHints.streetAddressLine2),
);
final TextField shippingAddress2 = tester.widget(find.byType(TextField).at(1));
expect(shippingAddress2.autofillHints, contains(AutofillHints.streetAddressLine2));
final TextField billingAddress1 = tester.widget(
find.byType(TextField).at(2),
);
expect(
billingAddress1.autofillHints,
contains(AutofillHints.streetAddressLine1),
);
final TextField billingAddress1 = tester.widget(find.byType(TextField).at(2));
expect(billingAddress1.autofillHints, contains(AutofillHints.streetAddressLine1));
final TextField billingAddress2 = tester.widget(
find.byType(TextField).at(3),
);
expect(
billingAddress2.autofillHints,
contains(AutofillHints.streetAddressLine2),
);
final TextField billingAddress2 = tester.widget(find.byType(TextField).at(3));
expect(billingAddress2.autofillHints, contains(AutofillHints.streetAddressLine2));
// Credit card information fields.
final TextField creditCardNumber = tester.widget(
find.byType(TextField).at(4),
);
expect(
creditCardNumber.autofillHints,
contains(AutofillHints.creditCardNumber),
);
final TextField creditCardNumber = tester.widget(find.byType(TextField).at(4));
expect(creditCardNumber.autofillHints, contains(AutofillHints.creditCardNumber));
final TextField creditCardSecurityCode = tester.widget(
find.byType(TextField).at(5),
);
expect(
creditCardSecurityCode.autofillHints,
contains(AutofillHints.creditCardSecurityCode),
);
final TextField creditCardSecurityCode = tester.widget(find.byType(TextField).at(5));
expect(creditCardSecurityCode.autofillHints, contains(AutofillHints.creditCardSecurityCode));
// Contact phone number field.
final TextField phoneNumber = tester.widget(
find.byType(TextField).at(6),
);
expect(
phoneNumber.autofillHints,
contains(AutofillHints.telephoneNumber),
);
final TextField phoneNumber = tester.widget(find.byType(TextField).at(6));
expect(phoneNumber.autofillHints, contains(AutofillHints.telephoneNumber));
await tester.tap(find.byType(Checkbox));
await tester.pump();
expect(
find.byType(TextField),
findsNWidgets(5),
);
expect(find.byType(TextField), findsNWidgets(5));
});
}

View File

@@ -10,20 +10,27 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('AbsorbPointer prevents hit testing on its child', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AbsorbPointerApp(),
);
await tester.pumpWidget(const example.AbsorbPointerApp());
// Get the center of the stack.
final Offset center = tester.getCenter(find.byType(Stack).first);
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
final TestGesture gesture = await tester.createGesture(
kind: PointerDeviceKind.mouse,
pointer: 1,
);
// Add the point to the center of the stack where the AbsorbPointer is.
await gesture.addPointer(location: center);
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
expect(
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
SystemMouseCursors.basic,
);
// Move the pointer to the left of the stack where the AbsorbPointer is not.
await gesture.moveTo(center + const Offset(-100, 0));
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
expect(
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
SystemMouseCursors.click,
);
});
}

View File

@@ -10,9 +10,7 @@ void main() {
testWidgets('AspectRatio applies 16 / 9 aspect ratio on its child', (WidgetTester tester) async {
const double height = 100.0;
await tester.pumpWidget(
const example.AspectRatioApp(),
);
await tester.pumpWidget(const example.AspectRatioApp());
final Size parentContainer = tester.getSize(find.byType(Container).first);
expect(parentContainer.width, 800.0);

View File

@@ -10,9 +10,7 @@ void main() {
testWidgets('AspectRatio applies 2.0 aspect ratio on its child', (WidgetTester tester) async {
const Size containerSize = Size(100, 100);
await tester.pumpWidget(
const example.AspectRatioApp(),
);
await tester.pumpWidget(const example.AspectRatioApp());
final Size parentContainer = tester.getSize(find.byType(Container).first);
expect(parentContainer, containerSize);

View File

@@ -10,9 +10,7 @@ void main() {
testWidgets('AspectRatio applies 0.5 aspect ratio on its child', (WidgetTester tester) async {
const Size containerSize = Size(100, 100);
await tester.pumpWidget(
const example.AspectRatioApp(),
);
await tester.pumpWidget(const example.AspectRatioApp());
final Size parentContainer = tester.getSize(find.byType(Container).first);
expect(parentContainer, containerSize);

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('ClipRRect adds rounded corners to containers', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ClipRRectApp(),
);
await tester.pumpWidget(const example.ClipRRectApp());
final Finder clipRRectFinder = find.byType(ClipRRect);
final Finder containerFinder = find.byType(Container);

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('ClipRRect fits to its child', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ClipRRectApp(),
);
await tester.pumpWidget(const example.ClipRRectApp());
final Finder clipRRectFinder = find.byType(ClipRRect);
final Finder logoFinder = find.byType(FlutterLogo);

View File

@@ -3,26 +3,19 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/basic/custom_multi_child_layout.0.dart'
as example;
import 'package:flutter_api_samples/widgets/basic/custom_multi_child_layout.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('has four containers', (WidgetTester tester) async {
await tester.pumpWidget(
const example.CustomMultiChildLayoutApp(),
);
await tester.pumpWidget(const example.CustomMultiChildLayoutApp());
final Finder containerFinder = find.byType(Container);
expect(containerFinder, findsNWidgets(4));
});
testWidgets('containers are the same size', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: example.CustomMultiChildLayoutExample(),
),
),
const MaterialApp(home: Scaffold(body: example.CustomMultiChildLayoutExample())),
);
final Finder containerFinder = find.byType(Container);
const Size expectedSize = Size(100, 100);
@@ -34,11 +27,7 @@ void main() {
testWidgets('containers are offset', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: example.CustomMultiChildLayoutExample(),
),
),
const MaterialApp(home: Scaffold(body: example.CustomMultiChildLayoutExample())),
);
final Finder containerFinder = find.byType(Container);
Rect previousRect = tester.getRect(containerFinder.first);

View File

@@ -16,9 +16,7 @@ void main() {
const double containerTwoHeight = columnHeight - 200;
const double containerThreeHeight = 100;
await tester.pumpWidget(
const example.ExpandedApp(),
);
await tester.pumpWidget(const example.ExpandedApp());
final Size column = tester.getSize(find.byType(Column));
expect(column, const Size(columnWidth, columnHeight));

View File

@@ -14,9 +14,7 @@ void main() {
const double containerTwoWidth = 50;
const double containerThreeWidth = (rowWidth - 50) * 1 / 3;
await tester.pumpWidget(
const example.ExpandedApp(),
);
await tester.pumpWidget(const example.ExpandedApp());
final Size row = tester.getSize(find.byType(Row));
expect(row, const Size(rowWidth, rowHeight));

View File

@@ -13,10 +13,10 @@ void main() {
HttpOverrides.global = null;
});
testWidgets('FittedBox scales the image to fill the parent container', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FittedBoxApp(),
);
testWidgets('FittedBox scales the image to fill the parent container', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.FittedBoxApp());
final Size containerSize = tester.getSize(find.byType(Container));
expect(containerSize, const Size(300, 400));

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Clicking on the menu icon opens the Flow menu', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FlowApp(),
);
await tester.pumpWidget(const example.FlowApp());
// The menu icon is in the top left corner of the screen.
Offset menuIcon = tester.getCenter(find.byIcon(Icons.menu));

View File

@@ -12,11 +12,11 @@ void main() {
const double widthFactor = 0.5;
const double heightFactor = 0.5;
await tester.pumpWidget(
const example.FractionallySizedBoxApp(),
);
await tester.pumpWidget(const example.FractionallySizedBoxApp());
final FractionallySizedBox fractionallySizedBox = tester.widget(find.byType(FractionallySizedBox));
final FractionallySizedBox fractionallySizedBox = tester.widget(
find.byType(FractionallySizedBox),
);
expect(fractionallySizedBox.widthFactor, widthFactor);
expect(fractionallySizedBox.heightFactor, heightFactor);

View File

@@ -11,23 +11,30 @@ void main() {
testWidgets('IgnorePointer ignores pointer on the ElevatedButton', (WidgetTester tester) async {
const String clickButtonText = 'Click me!';
await tester.pumpWidget(
const example.IgnorePointerApp(),
);
await tester.pumpWidget(const example.IgnorePointerApp());
// The ElevatedButton is clickable.
expect(find.text('Ignoring: false'), findsOneWidget);
final TestGesture gesture = await tester.createGesture(kind: PointerDeviceKind.mouse, pointer: 1);
final TestGesture gesture = await tester.createGesture(
kind: PointerDeviceKind.mouse,
pointer: 1,
);
await gesture.addPointer(location: tester.getCenter(find.text(clickButtonText)));
// On hovering the ElevatedButton, the cursor should be SystemMouseCursors.click.
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.click);
expect(
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
SystemMouseCursors.click,
);
// Tap to set ignoring pointer to true.
await tester.tap(find.text('Set ignoring to true'));
await tester.pump();
// The ElevatedButton is not clickable so the cursor should be SystemMouseCursors.basic.
expect(RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1), SystemMouseCursors.basic);
expect(
RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
SystemMouseCursors.basic,
);
});
}

View File

@@ -11,11 +11,14 @@ void main() {
await tester.pumpWidget(const example.IndexedStackApp());
final Finder gesture2 = find.byKey(const Key('gesture2'));
final Element containerFinder = find.byKey(const Key('Dash'), skipOffstage: false).evaluate().first;
final Element containerFinder =
find.byKey(const Key('Dash'), skipOffstage: false).evaluate().first;
expect(containerFinder.renderObject!.debugNeedsPaint, false);
final Element containerFinder1 = find.byKey(const Key('John'), skipOffstage: false).evaluate().first;
final Element containerFinder1 =
find.byKey(const Key('John'), skipOffstage: false).evaluate().first;
expect(containerFinder1.renderObject!.debugNeedsPaint, true);
final Element containerFinder2 = find.byKey(const Key('Mary'), skipOffstage: false).evaluate().first;
final Element containerFinder2 =
find.byKey(const Key('Mary'), skipOffstage: false).evaluate().first;
expect(containerFinder2.renderObject!.debugNeedsPaint, true);
await tester.tap(gesture2);
@@ -34,9 +37,12 @@ void main() {
await tester.pumpWidget(const example.IndexedStackApp());
final Finder gesture1 = find.byKey(const Key('gesture1'));
final Element containerFinder = find.byKey(const Key('Dash'), skipOffstage: false).evaluate().first;
final Element containerFinder1 = find.byKey(const Key('John'), skipOffstage: false).evaluate().first;
final Element containerFinder2 = find.byKey(const Key('Mary'), skipOffstage: false).evaluate().first;
final Element containerFinder =
find.byKey(const Key('Dash'), skipOffstage: false).evaluate().first;
final Element containerFinder1 =
find.byKey(const Key('John'), skipOffstage: false).evaluate().first;
final Element containerFinder2 =
find.byKey(const Key('Mary'), skipOffstage: false).evaluate().first;
await tester.tap(gesture1);
await tester.pump();

View File

@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/basic/listener.0.dart' as example;
@@ -10,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Listener detects press & release, and cursor location', (WidgetTester tester) async {
await tester.pumpWidget(
const MaterialApp(home: example.ListenerExample()),
);
await tester.pumpWidget(const MaterialApp(home: example.ListenerExample()));
expect(find.text('0 presses\n0 releases'), findsOneWidget);
expect(find.text('The cursor is here: (0.00, 0.00)'), findsOneWidget);

View File

@@ -8,10 +8,10 @@ import 'package:flutter_api_samples/widgets/basic/mouse_region.0.dart' as exampl
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('MouseRegion detects mouse entries, exists, and location', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MouseRegionApp(),
);
testWidgets('MouseRegion detects mouse entries, exists, and location', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.MouseRegionApp());
expect(find.text('0 Entries\n0 Exits'), findsOneWidget);
expect(find.text('The cursor is here: (0.00, 0.00)'), findsOneWidget);
@@ -24,9 +24,7 @@ void main() {
expect(find.text('1 Entries\n0 Exits'), findsOneWidget);
expect(find.text('The cursor is here: (400.00, 328.00)'), findsOneWidget);
await gesture.moveTo(
tester.getCenter(find.byType(ColoredBox)) + const Offset(50.0, 30.0),
);
await gesture.moveTo(tester.getCenter(find.byType(ColoredBox)) + const Offset(50.0, 30.0));
await tester.pump();
expect(find.text('The cursor is here: (450.00, 358.00)'), findsOneWidget);

View File

@@ -9,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('MouseRegion detects mouse hover', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MouseRegionApp(),
);
await tester.pumpWidget(const example.MouseRegionApp());
Container container = tester.widget<Container>(find.byType(Container));
expect(container.decoration, const BoxDecoration(color: Colors.blue));

View File

@@ -9,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('MouseRegion update mouse hover with a delay', (WidgetTester tester) async {
await tester.pumpWidget(
const example.MouseRegionApp(),
);
await tester.pumpWidget(const example.MouseRegionApp());
expect(find.text('Not hovering'), findsOneWidget);

View File

@@ -7,9 +7,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can off/on stage Flutter logo widget', (WidgetTester tester) async {
await tester.pumpWidget(
const example.OffstageApp(),
);
await tester.pumpWidget(const example.OffstageApp());
// The Flutter logo is off stage and not visible.
expect(find.text('Flutter logo is offstage: true'), findsOneWidget);

View File

@@ -7,13 +7,13 @@ import 'package:flutter_api_samples/widgets/basic/overflowbox.0.dart' as example
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('OverflowBox allows child widget to overflow parent container', (WidgetTester tester) async {
const Size containerSize = Size(100, 100);
testWidgets('OverflowBox allows child widget to overflow parent container', (
WidgetTester tester,
) async {
const Size containerSize = Size(100, 100);
const Size maxSize = Size(200, 200);
await tester.pumpWidget(
const example.OverflowBoxApp(),
);
await tester.pumpWidget(const example.OverflowBoxApp());
// The parent container has fixed width and height of 100 pixels.
expect(tester.getSize(find.byType(Container).first), containerSize);

View File

@@ -8,15 +8,10 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('PhysicalShape is an ancestor of the text widget', (WidgetTester tester) async {
await tester.pumpWidget(
const example.PhysicalShapeApp(),
);
await tester.pumpWidget(const example.PhysicalShapeApp());
final PhysicalShape physicalShape = tester.widget<PhysicalShape>(
find.ancestor(
of:find.text('Hello, World!'),
matching: find.byType(PhysicalShape),
),
find.ancestor(of: find.text('Hello, World!'), matching: find.byType(PhysicalShape)),
);
expect(physicalShape.clipper, isNotNull);
expect(physicalShape.color, Colors.orange);

View File

@@ -4,22 +4,21 @@
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_api_samples/widgets/binding/widget_binding_observer.0.dart'
as example;
import 'package:flutter_api_samples/widgets/binding/widget_binding_observer.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('App tracks lifecycle states', (WidgetTester tester) async {
Future<void> setAppLifeCycleState(AppLifecycleState state) async {
final ByteData? message =
const StringCodec().encodeMessage(state.toString());
final ByteData? message = const StringCodec().encodeMessage(state.toString());
await tester.binding.defaultBinaryMessenger.handlePlatformMessage(
'flutter/lifecycle', message, (_) {});
'flutter/lifecycle',
message,
(_) {},
);
}
await tester.pumpWidget(
const example.WidgetBindingObserverExampleApp(),
);
await tester.pumpWidget(const example.WidgetBindingObserverExampleApp());
expect(find.text('There are no AppLifecycleStates to show.'), findsOneWidget);

View File

@@ -6,8 +6,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_api_samples/widgets/color_filter/color_filtered.0.dart'
as example;
import 'package:flutter_api_samples/widgets/color_filter/color_filtered.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
@@ -18,20 +17,15 @@ void main() {
});
testWidgets('Color filters are applied to the images', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ColorFilteredExampleApp(),
);
await tester.pumpWidget(const example.ColorFilteredExampleApp());
await tester.pumpAndSettle();
// Verify that two images are displayed.
expect(find.byType(Image), findsNWidgets(2));
RenderObject renderObject = tester.firstRenderObject(
find.byType(ColorFiltered).first,
);
ColorFilterLayer colorFilterLayer =
renderObject.debugLayer! as ColorFilterLayer;
RenderObject renderObject = tester.firstRenderObject(find.byType(ColorFiltered).first);
ColorFilterLayer colorFilterLayer = renderObject.debugLayer! as ColorFilterLayer;
// Verify that red colored filter with modulate blend mode is applied to the first image.
expect(
@@ -39,9 +33,7 @@ void main() {
equals(const ColorFilter.mode(Colors.red, BlendMode.modulate)),
);
renderObject = tester.firstRenderObject(
find.byType(ColorFiltered).last,
);
renderObject = tester.firstRenderObject(find.byType(ColorFiltered).last);
colorFilterLayer = renderObject.debugLayer! as ColorFilterLayer;
// Verify that grey colored filter with saturation blend mode is applied to the first image.

View File

@@ -3,8 +3,7 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/dismissible/dismissible.0.dart'
as example;
import 'package:flutter_api_samples/widgets/dismissible/dismissible.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
@@ -25,57 +24,47 @@ void main() {
await tester.drag(finder, offset);
}
testWidgets(
'ListTiles can be dismissed from right to left',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.DismissibleExampleApp(),
testWidgets('ListTiles can be dismissed from right to left', (WidgetTester tester) async {
await tester.pumpWidget(const example.DismissibleExampleApp());
for (final int index in <int>[0, 33, 66, 99]) {
final ValueKey<int> key = ValueKey<int>(index);
await tester.scrollUntilVisible(find.byKey(key), 100);
expect(find.byKey(key), findsOneWidget);
await dismissHorizontally(
tester: tester,
finder: find.byKey(key),
direction: AxisDirection.left,
);
for (final int index in <int>[0, 33, 66, 99]) {
final ValueKey<int> key = ValueKey<int>(index);
await tester.pumpAndSettle();
await tester.scrollUntilVisible(find.byKey(key), 100);
expect(find.byKey(key), findsNothing);
}
});
expect(find.byKey(key), findsOneWidget);
testWidgets('ListTiles can be dismissed from left to right', (WidgetTester tester) async {
await tester.pumpWidget(const example.DismissibleExampleApp());
await dismissHorizontally(
tester: tester,
finder: find.byKey(key),
direction: AxisDirection.left,
);
for (final int index in <int>[0, 33, 66, 99]) {
final ValueKey<int> key = ValueKey<int>(index);
await tester.pumpAndSettle();
await tester.scrollUntilVisible(find.byKey(key), 100);
expect(find.byKey(key), findsNothing);
}
},
);
expect(find.byKey(key), findsOneWidget);
testWidgets(
'ListTiles can be dismissed from left to right',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.DismissibleExampleApp(),
await dismissHorizontally(
tester: tester,
finder: find.byKey(key),
direction: AxisDirection.right,
);
for (final int index in <int>[0, 33, 66, 99]) {
final ValueKey<int> key = ValueKey<int>(index);
await tester.pumpAndSettle();
await tester.scrollUntilVisible(find.byKey(key), 100);
expect(find.byKey(key), findsOneWidget);
await dismissHorizontally(
tester: tester,
finder: find.byKey(key),
direction: AxisDirection.right,
);
await tester.pumpAndSettle();
expect(find.byKey(key), findsNothing);
}
},
);
expect(find.byKey(key), findsNothing);
}
});
}

View File

@@ -3,15 +3,11 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/drag_target/draggable.0.dart'
as example;
import 'package:flutter_api_samples/widgets/drag_target/draggable.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
Finder findContainerWith({
required Finder child,
required Color color,
}) {
Finder findContainerWith({required Finder child, required Color color}) {
return find.ancestor(
of: child,
matching: find.byWidgetPredicate(
@@ -21,33 +17,25 @@ void main() {
}
testWidgets('Verify initial state', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DraggableExampleApp(),
);
await tester.pumpWidget(const example.DraggableExampleApp());
expect(find.text('Draggable Sample'), findsOneWidget);
expect(
findContainerWith(
color: Colors.lightGreenAccent,
child: find.text('Draggable'),
),
findContainerWith(color: Colors.lightGreenAccent, child: find.text('Draggable')),
findsOneWidget,
);
expect(
findContainerWith(
color: Colors.cyan,
child: find.text('Value is updated to: 0'),
),
findContainerWith(color: Colors.cyan, child: find.text('Value is updated to: 0')),
findsOneWidget,
);
});
testWidgets('Verify correct containers are displayed while dragging', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DraggableExampleApp(),
);
testWidgets('Verify correct containers are displayed while dragging', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.DraggableExampleApp());
final Finder idleContainer = findContainerWith(
color: Colors.lightGreenAccent,
@@ -66,9 +54,7 @@ void main() {
expect(draggingContainer, findsNothing);
expect(feedbackContainer, findsNothing);
final TestGesture gesture = await tester.startGesture(
tester.getCenter(idleContainer),
);
final TestGesture gesture = await tester.startGesture(tester.getCenter(idleContainer));
await tester.pump();
expect(idleContainer, findsNothing);
@@ -90,10 +76,10 @@ void main() {
expect(feedbackContainer, findsNothing);
});
testWidgets('Dropping Draggable over DragTarget updates the counter', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DraggableExampleApp(),
);
testWidgets('Dropping Draggable over DragTarget updates the counter', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.DraggableExampleApp());
final Finder draggable = find.byType(Draggable<int>);
final Finder target = find.byType(DragTarget<int>);
@@ -101,9 +87,7 @@ void main() {
int counter = 0;
for (int i = 0; i < 5; i++) {
final TestGesture gesture = await tester.startGesture(
tester.getCenter(draggable),
);
final TestGesture gesture = await tester.startGesture(tester.getCenter(draggable));
await gesture.moveTo(tester.getCenter(target));
await gesture.up();
await tester.pump();
@@ -111,10 +95,7 @@ void main() {
counter += 10;
expect(
findContainerWith(
color: Colors.cyan,
child: find.text('Value is updated to: $counter'),
),
findContainerWith(color: Colors.cyan, child: find.text('Value is updated to: $counter')),
findsOneWidget,
);
}

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/draggable_scrollable_sheet/draggable_scrollable_sheet.0.dart' as example;
import 'package:flutter_api_samples/widgets/draggable_scrollable_sheet/draggable_scrollable_sheet.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Test DraggableScrollableSheet initial state', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DraggableScrollableSheetExampleApp(),
);
await tester.pumpWidget(const example.DraggableScrollableSheetExampleApp());
final Finder sheetFinder = find.byType(DraggableScrollableSheet);
@@ -22,42 +21,48 @@ void main() {
expect(draggableSheet.initialChildSize, 0.5);
});
testWidgets('Test DraggableScrollableSheet drag behavior on mobile platforms', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DraggableScrollableSheetExampleApp(),
);
testWidgets(
'Test DraggableScrollableSheet drag behavior on mobile platforms',
(WidgetTester tester) async {
await tester.pumpWidget(const example.DraggableScrollableSheetExampleApp());
// Verify that ListView is visible
final Finder listViewFinder = find.byType(ListView);
expect(listViewFinder, findsOneWidget);
// Verify that ListView is visible
final Finder listViewFinder = find.byType(ListView);
expect(listViewFinder, findsOneWidget);
// Get the initial size of the ListView
final Size listViewInitialSize = tester.getSize(listViewFinder);
// Get the initial size of the ListView
final Size listViewInitialSize = tester.getSize(listViewFinder);
// Drag the sheet from anywhere inside the sheet to change the sheet position
await tester.drag(listViewFinder, const Offset(0.0, -100.0));
await tester.pump();
// Drag the sheet from anywhere inside the sheet to change the sheet position
await tester.drag(listViewFinder, const Offset(0.0, -100.0));
await tester.pump();
// Verify that the ListView is expanded
final Size listViewCurrentSize = tester.getSize(listViewFinder);
expect(listViewCurrentSize.height, greaterThan(listViewInitialSize.height));
}, variant: TargetPlatformVariant.mobile());
// Verify that the ListView is expanded
final Size listViewCurrentSize = tester.getSize(listViewFinder);
expect(listViewCurrentSize.height, greaterThan(listViewInitialSize.height));
},
variant: TargetPlatformVariant.mobile(),
);
testWidgets('Test DraggableScrollableSheet drag behavior on desktop platforms', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DraggableScrollableSheetExampleApp(),
);
testWidgets(
'Test DraggableScrollableSheet drag behavior on desktop platforms',
(WidgetTester tester) async {
await tester.pumpWidget(const example.DraggableScrollableSheetExampleApp());
// Verify that Grabber is visible
final Finder grabberFinder = find.byType(example.Grabber);
expect(grabberFinder, findsOneWidget);
// Verify that Grabber is visible
final Finder grabberFinder = find.byType(example.Grabber);
expect(grabberFinder, findsOneWidget);
// Drag the Grabber to change the sheet position
await tester.drag(grabberFinder, const Offset(0.0, -100.0));
await tester.pump();
// Drag the Grabber to change the sheet position
await tester.drag(grabberFinder, const Offset(0.0, -100.0));
await tester.pump();
// Verify that the DraggableScrollableSheet's initialChildSize is updated
final DraggableScrollableSheet draggableSheet = tester.widget(find.byType(DraggableScrollableSheet));
expect(draggableSheet.initialChildSize, isNot(0.5));
}, variant: TargetPlatformVariant.desktop());
// Verify that the DraggableScrollableSheet's initialChildSize is updated
final DraggableScrollableSheet draggableSheet = tester.widget(
find.byType(DraggableScrollableSheet),
);
expect(draggableSheet.initialChildSize, isNot(0.5));
},
variant: TargetPlatformVariant.desktop(),
);
}

View File

@@ -9,21 +9,14 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Verify correct labels are displayed', (WidgetTester tester) async {
await tester.pumpWidget(
const example.OnChangedExampleApp(),
);
await tester.pumpWidget(const example.OnChangedExampleApp());
expect(
find.text('What number comes next in the sequence?'),
findsOneWidget,
);
expect(find.text('What number comes next in the sequence?'), findsOneWidget);
expect(find.text('1, 1, 2, 3, 5, 8...?'), findsOneWidget);
});
testWidgets('Does not show dialog when answer is not correct', (WidgetTester tester) async {
await tester.pumpWidget(
const example.OnChangedExampleApp(),
);
await tester.pumpWidget(const example.OnChangedExampleApp());
await tester.enterText(find.byType(TextField), '33');
await tester.pumpAndSettle();
@@ -32,9 +25,7 @@ void main() {
});
testWidgets('Shows dialog when answer is correct', (WidgetTester tester) async {
await tester.pumpWidget(
const example.OnChangedExampleApp(),
);
await tester.pumpWidget(const example.OnChangedExampleApp());
await tester.enterText(find.byType(TextField), '13');
await tester.pumpAndSettle();
@@ -46,21 +37,14 @@ void main() {
});
testWidgets('Closes dialog on OK button tap', (WidgetTester tester) async {
await tester.pumpWidget(
const example.OnChangedExampleApp(),
);
await tester.pumpWidget(const example.OnChangedExampleApp());
await tester.enterText(find.byType(TextField), '13');
await tester.pumpAndSettle();
expect(find.byType(AlertDialog), findsOneWidget);
await tester.tap(
find.ancestor(
of: find.text('OK'),
matching: find.byType(TextButton),
),
);
await tester.tap(find.ancestor(of: find.text('OK'), matching: find.byType(TextButton)));
await tester.pumpAndSettle();
expect(find.byType(AlertDialog), findsNothing);

View File

@@ -6,14 +6,13 @@ import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_api_samples/widgets/editable_text/editable_text.on_content_inserted.0.dart' as example;
import 'package:flutter_api_samples/widgets/editable_text/editable_text.on_content_inserted.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Image.memory displays inserted content', (WidgetTester tester) async {
await tester.pumpWidget(
const example.KeyboardInsertedContentApp(),
);
await tester.pumpWidget(const example.KeyboardInsertedContentApp());
expect(find.text('Keyboard Inserted Content Sample'), findsOneWidget);
@@ -23,16 +22,135 @@ void main() {
const String uri = 'content://com.google.android.inputmethod.latin.fileprovider/test.png';
const List<int> kBlueSquarePng = <int>[
0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0x00, 0x00, 0x00, 0x0d, 0x49,
0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x32, 0x08, 0x06,
0x00, 0x00, 0x00, 0x1e, 0x3f, 0x88, 0xb1, 0x00, 0x00, 0x00, 0x48, 0x49, 0x44,
0x41, 0x54, 0x78, 0xda, 0xed, 0xcf, 0x31, 0x0d, 0x00, 0x30, 0x08, 0x00, 0xb0,
0x61, 0x63, 0x2f, 0xfe, 0x2d, 0x61, 0x05, 0x34, 0xf0, 0x92, 0xd6, 0x41, 0x23,
0x7f, 0xf5, 0x3b, 0x20, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
0x44, 0x44, 0x44, 0x36, 0x06, 0x03, 0x6e, 0x69, 0x47, 0x12, 0x8e, 0xea, 0xaa,
0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e, 0x44, 0xae, 0x42, 0x60, 0x82,
0x89,
0x50,
0x4e,
0x47,
0x0d,
0x0a,
0x1a,
0x0a,
0x00,
0x00,
0x00,
0x0d,
0x49,
0x48,
0x44,
0x52,
0x00,
0x00,
0x00,
0x32,
0x00,
0x00,
0x00,
0x32,
0x08,
0x06,
0x00,
0x00,
0x00,
0x1e,
0x3f,
0x88,
0xb1,
0x00,
0x00,
0x00,
0x48,
0x49,
0x44,
0x41,
0x54,
0x78,
0xda,
0xed,
0xcf,
0x31,
0x0d,
0x00,
0x30,
0x08,
0x00,
0xb0,
0x61,
0x63,
0x2f,
0xfe,
0x2d,
0x61,
0x05,
0x34,
0xf0,
0x92,
0xd6,
0x41,
0x23,
0x7f,
0xf5,
0x3b,
0x20,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x44,
0x36,
0x06,
0x03,
0x6e,
0x69,
0x47,
0x12,
0x8e,
0xea,
0xaa,
0x00,
0x00,
0x00,
0x00,
0x49,
0x45,
0x4e,
0x44,
0xae,
0x42,
0x60,
0x82,
];
final ByteData? messageBytes = const JSONMessageCodec().encodeMessage(<String, dynamic>{
'args': <dynamic>[
@@ -47,7 +165,7 @@ void main() {
await tester.binding.defaultBinaryMessenger.handlePlatformMessage(
'flutter/textinput',
messageBytes,
(ByteData? _) {},
(ByteData? _) {},
);
} catch (_) {}

View File

@@ -9,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Forces text to be lower case', (WidgetTester tester) async {
await tester.pumpWidget(
const example.TextEditingControllerExampleApp(),
);
await tester.pumpWidget(const example.TextEditingControllerExampleApp());
const String input = 'Almost Everything Is a WIDGET! 💙';
@@ -26,9 +24,7 @@ void main() {
});
testWidgets('Keeps the caret at the end of the input', (WidgetTester tester) async {
await tester.pumpWidget(
const example.TextEditingControllerExampleApp(),
);
await tester.pumpWidget(const example.TextEditingControllerExampleApp());
const String input = 'flutter';
@@ -41,17 +37,12 @@ void main() {
final TextEditingController controller = textField.controller!;
// Verify that the caret positioned at the end of the input.
expect(
controller.selection,
const TextSelection.collapsed(offset: input.length),
);
expect(controller.selection, const TextSelection.collapsed(offset: input.length));
final RenderBox box = tester.renderObject(find.byType(TextFormField));
// Calculate the center-left point of the field.
final Offset centerLeftPoint = box.localToGlobal(
Offset(0, box.size.height / 2),
);
final Offset centerLeftPoint = box.localToGlobal(Offset(0, box.size.height / 2));
// Tap on the center-left point of the field to try to change the caret
// position.
@@ -59,9 +50,6 @@ void main() {
await tester.pump();
// Verify that the caret position remains unchanged.
expect(
controller.selection,
const TextSelection.collapsed(offset: input.length),
);
expect(controller.selection, const TextSelection.collapsed(offset: input.length));
});
}

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/editable_text/text_editing_controller.1.dart' as example;
import 'package:flutter_api_samples/widgets/editable_text/text_editing_controller.1.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Initial selection is collapsed at offset 0', (WidgetTester tester) async {
await tester.pumpWidget(
const example.TextEditingControllerExampleApp(),
);
await tester.pumpWidget(const example.TextEditingControllerExampleApp());
final EditableText editableText = tester.widget(find.byType(EditableText));
final TextEditingController controller = editableText.controller;

View File

@@ -4,153 +4,127 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_api_samples/widgets/focus_manager/focus_node.0.dart'
as example;
import 'package:flutter_api_samples/widgets/focus_manager/focus_node.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'FocusNode gets focused and unfocused on ColorfulButton tap',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.FocusNodeExampleApp(),
);
testWidgets('FocusNode gets focused and unfocused on ColorfulButton tap', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.FocusNodeExampleApp());
final Element button = tester.element(
find.byType(example.ColorfulButton),
);
final Element button = tester.element(find.byType(example.ColorfulButton));
expect(
tester.binding.focusManager.primaryFocus?.context,
isNot(equals(button)),
);
expect(tester.binding.focusManager.primaryFocus?.context, isNot(equals(button)));
// Tapping on ColorfulButton to focus on FocusNode.
await tester.tap(find.byType(example.ColorfulButton));
await tester.pump();
// Tapping on ColorfulButton to focus on FocusNode.
await tester.tap(find.byType(example.ColorfulButton));
await tester.pump();
expect(
tester.binding.focusManager.primaryFocus?.context,
equals(button),
);
expect(tester.binding.focusManager.primaryFocus?.context, equals(button));
// Tapping on ColorfulButton to unfocus from FocusNode.
await tester.tap(find.byType(example.ColorfulButton));
await tester.pump();
// Tapping on ColorfulButton to unfocus from FocusNode.
await tester.tap(find.byType(example.ColorfulButton));
await tester.pump();
expect(
tester.binding.focusManager.primaryFocus?.context,
isNot(equals(button)),
);
},
);
expect(tester.binding.focusManager.primaryFocus?.context, isNot(equals(button)));
});
testWidgets(
'FocusNode updates the text label when focused or unfocused',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.FocusNodeExampleApp(),
);
testWidgets('FocusNode updates the text label when focused or unfocused', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.FocusNodeExampleApp());
expect(find.text('Press to focus'), findsOneWidget);
expect(find.text("I'm in color! Press R,G,B!"), findsNothing);
expect(find.text('Press to focus'), findsOneWidget);
expect(find.text("I'm in color! Press R,G,B!"), findsNothing);
// Tapping on ColorfulButton to focus on FocusNode.
await tester.tap(find.byType(example.ColorfulButton));
await tester.pump();
// Tapping on ColorfulButton to focus on FocusNode.
await tester.tap(find.byType(example.ColorfulButton));
await tester.pump();
expect(find.text('Press to focus'), findsNothing);
expect(find.text("I'm in color! Press R,G,B!"), findsOneWidget);
expect(find.text('Press to focus'), findsNothing);
expect(find.text("I'm in color! Press R,G,B!"), findsOneWidget);
// Tapping on ColorfulButton to unfocus from FocusNode.
await tester.tap(find.byType(example.ColorfulButton));
await tester.pump();
// Tapping on ColorfulButton to unfocus from FocusNode.
await tester.tap(find.byType(example.ColorfulButton));
await tester.pump();
expect(find.text('Press to focus'), findsOneWidget);
expect(find.text("I'm in color! Press R,G,B!"), findsNothing);
},
);
expect(find.text('Press to focus'), findsOneWidget);
expect(find.text("I'm in color! Press R,G,B!"), findsNothing);
});
testWidgets(
'FocusNode updates color of the Container according to the key events when focused',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.FocusNodeExampleApp(),
);
testWidgets('FocusNode updates color of the Container according to the key events when focused', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.FocusNodeExampleApp());
// Tapping on ColorfulButton to focus on FocusNode.
await tester.tap(find.byType(example.ColorfulButton));
await tester.pump();
// Tapping on ColorfulButton to focus on FocusNode.
await tester.tap(find.byType(example.ColorfulButton));
await tester.pump();
final Finder containerFinder = find.descendant(
of: find.byType(example.ColorfulButton),
matching: find.byType(Container),
);
final Finder containerFinder = find.descendant(
of: find.byType(example.ColorfulButton),
matching: find.byType(Container),
);
Container container = tester.widget<Container>(containerFinder);
expect(container.color, equals(Colors.white));
Container container = tester.widget<Container>(containerFinder);
expect(container.color, equals(Colors.white));
await tester.sendKeyEvent(LogicalKeyboardKey.keyR);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.keyR);
await tester.pump();
container = tester.widget<Container>(containerFinder);
expect(container.color, equals(Colors.red));
container = tester.widget<Container>(containerFinder);
expect(container.color, equals(Colors.red));
await tester.sendKeyEvent(LogicalKeyboardKey.keyG);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.keyG);
await tester.pump();
container = tester.widget<Container>(containerFinder);
expect(container.color, equals(Colors.green));
container = tester.widget<Container>(containerFinder);
expect(container.color, equals(Colors.green));
await tester.sendKeyEvent(LogicalKeyboardKey.keyB);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.keyB);
await tester.pump();
container = tester.widget<Container>(containerFinder);
expect(container.color, equals(Colors.blue));
},
);
container = tester.widget<Container>(containerFinder);
expect(container.color, equals(Colors.blue));
});
testWidgets(
'FocusNode does not listen to the key events when unfocused',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.FocusNodeExampleApp(),
);
testWidgets('FocusNode does not listen to the key events when unfocused', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.FocusNodeExampleApp());
final Finder containerFinder = find.descendant(
of: find.byType(example.ColorfulButton),
matching: find.byType(Container),
);
final Finder containerFinder = find.descendant(
of: find.byType(example.ColorfulButton),
matching: find.byType(Container),
);
Container container = tester.widget<Container>(containerFinder);
expect(container.color, equals(Colors.white));
Container container = tester.widget<Container>(containerFinder);
expect(container.color, equals(Colors.white));
await tester.sendKeyEvent(LogicalKeyboardKey.keyR);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.keyR);
await tester.pump();
container = tester.widget<Container>(containerFinder);
expect(container.color, equals(Colors.white));
container = tester.widget<Container>(containerFinder);
expect(container.color, equals(Colors.white));
await tester.sendKeyEvent(LogicalKeyboardKey.keyG);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.keyG);
await tester.pump();
container = tester.widget<Container>(containerFinder);
expect(container.color, equals(Colors.white));
container = tester.widget<Container>(containerFinder);
expect(container.color, equals(Colors.white));
await tester.sendKeyEvent(LogicalKeyboardKey.keyB);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.keyB);
await tester.pump();
container = tester.widget<Container>(containerFinder);
expect(container.color, equals(Colors.white));
},
);
container = tester.widget<Container>(containerFinder);
expect(container.color, equals(Colors.white));
});
testWidgets(
'FocusNode sets color to the white when unfocused and sets it back to the selected one when focused',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.FocusNodeExampleApp(),
);
await tester.pumpWidget(const example.FocusNodeExampleApp());
final Finder containerFinder = find.descendant(
of: find.byType(example.ColorfulButton),

View File

@@ -4,46 +4,40 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_api_samples/widgets/focus_manager/focus_node.unfocus.0.dart'
as example;
import 'package:flutter_api_samples/widgets/focus_manager/focus_node.unfocus.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'Unfocusing with UnfocusDisposition.scope gives the focus to the parent scope',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.UnfocusExampleApp(),
);
testWidgets('Unfocusing with UnfocusDisposition.scope gives the focus to the parent scope', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.UnfocusExampleApp());
// Focuses the first text field.
await tester.tap(find.byType(TextField).first);
await tester.pump();
// Changes the focus to the unfocus button.
for (int i = 0; i < 6; i++) {
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
await tester.pump();
}
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pump();
// Focuses the first text field.
await tester.tap(find.byType(TextField).first);
await tester.pump();
// Changes the focus to the unfocus button.
for (int i = 0; i < 6; i++) {
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
await tester.pump();
}
// After pressing tab once, the focus is on the first text field.
final EditableText firstEditableText = tester.firstWidget(find.byType(EditableText));
expect(firstEditableText.focusNode.hasFocus, true);
},
);
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
await tester.pump();
await tester.sendKeyEvent(LogicalKeyboardKey.tab);
await tester.pump();
// After pressing tab once, the focus is on the first text field.
final EditableText firstEditableText = tester.firstWidget(find.byType(EditableText));
expect(firstEditableText.focusNode.hasFocus, true);
});
testWidgets(
'Unfocusing with UnfocusDisposition.previouslyFocusedChild gives the focus the previously focused child',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.UnfocusExampleApp(),
);
await tester.pumpWidget(const example.UnfocusExampleApp());
// Focuses the first text field.
await tester.tap(find.byType(TextField).first);

View File

@@ -4,8 +4,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_api_samples/widgets/focus_scope/focus.0.dart'
as example;
import 'package:flutter_api_samples/widgets/focus_scope/focus.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
@@ -18,8 +17,7 @@ void main() {
expect(find.text('Focus Sample'), findsOneWidget);
expect(find.byType(Container), findsOneWidget);
final Container container =
tester.widget<Container>(find.byType(Container));
final Container container = tester.widget<Container>(find.byType(Container));
expect(container.color, Colors.white);
});
@@ -33,8 +31,7 @@ void main() {
expect(find.text("I'm in color! Press R,G,B!"), findsOneWidget);
expect(find.byType(Container), findsOneWidget);
final Container container =
tester.widget<Container>(find.byType(Container));
final Container container = tester.widget<Container>(find.byType(Container));
expect(container.color, Colors.white);
await tester.tap(find.text("I'm in color! Press R,G,B!"));

View File

@@ -4,96 +4,80 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_api_samples/widgets/focus_scope/focus.1.dart'
as example;
import 'package:flutter_api_samples/widgets/focus_scope/focus.1.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('FocusableText shows content and color depending on focus',
(WidgetTester tester) async {
await tester.pumpWidget(const MaterialApp(
home: Scaffold(
body: example.FocusableText(
'Item 0',
autofocus: false,
),
),
));
testWidgets('FocusableText shows content and color depending on focus', (
WidgetTester tester,
) async {
await tester.pumpWidget(
const MaterialApp(home: Scaffold(body: example.FocusableText('Item 0', autofocus: false))),
);
// Autofocus needs to check that no other node in the [FocusScope] is
// focused and can only request focus for the second frame.
await tester.pumpAndSettle();
expect(find.descendant(
of: find.byType(example.FocusableText),
matching: find.byType(Focus),
), findsOneWidget);
expect(
find.descendant(of: find.byType(example.FocusableText), matching: find.byType(Focus)),
findsOneWidget,
);
expect(find.text('Item 0'), findsOneWidget);
expect(find.byType(Container), findsOneWidget);
final Container container1 = tester.widget<Container>(
find.byType(Container)
);
final Container container1 = tester.widget<Container>(find.byType(Container));
expect(container1.color, Colors.white);
await tester.pumpWidget(const MaterialApp(
home: Scaffold(
body: example.FocusableText(
'Item 1',
autofocus: true,
),
),
));
await tester.pumpWidget(
const MaterialApp(home: Scaffold(body: example.FocusableText('Item 1', autofocus: true))),
);
await tester.pumpAndSettle();
final Finder focusableTextFinder2 = find.ancestor(
of: find.text('Item 1'),
matching: find.byType(example.FocusableText),
);
expect(tester.widget<Focus>(find.descendant(
of: focusableTextFinder2,
matching: find.byType(Focus),
)).autofocus, isTrue);
final Container container2 = tester.widget<Container>(find.descendant(
of: focusableTextFinder2,
matching: find.byType(Container),
));
expect(
tester
.widget<Focus>(find.descendant(of: focusableTextFinder2, matching: find.byType(Focus)))
.autofocus,
isTrue,
);
final Container container2 = tester.widget<Container>(
find.descendant(of: focusableTextFinder2, matching: find.byType(Container)),
);
expect(container2.color, Colors.red);
});
testWidgets('builds list showcasing focus traversal',
(WidgetTester tester) async {
testWidgets('builds list showcasing focus traversal', (WidgetTester tester) async {
await tester.pumpWidget(const example.FocusExampleApp());
await tester.pumpAndSettle();
expect(find.byType(ListView), findsOneWidget);
final Finder childFinder = find.descendant(
of: find.byType(ListView),
matching: find.byType(example.FocusableText),
of: find.byType(ListView),
matching: find.byType(example.FocusableText),
);
expect(childFinder, findsAtLeastNWidgets(2));
Container container0 = tester.widget<Container>(find.descendant(
of: childFinder.first,
matching: find.byType(Container),
));
Container container1 = tester.widget<Container>(find.descendant(
of: childFinder.at(1),
matching: find.byType(Container),
));
Container container0 = tester.widget<Container>(
find.descendant(of: childFinder.first, matching: find.byType(Container)),
);
Container container1 = tester.widget<Container>(
find.descendant(of: childFinder.at(1), matching: find.byType(Container)),
);
expect(container0.color, Colors.red);
expect(container1.color, Colors.white);
await tester.sendKeyDownEvent(LogicalKeyboardKey.arrowDown);
await tester.pumpAndSettle();
container0 = tester.widget<Container>(find.descendant(
of: childFinder.first,
matching: find.byType(Container),
));
container1 = tester.widget<Container>(find.descendant(
of: childFinder.at(1),
matching: find.byType(Container),
));
container0 = tester.widget<Container>(
find.descendant(of: childFinder.first, matching: find.byType(Container)),
);
container1 = tester.widget<Container>(
find.descendant(of: childFinder.at(1), matching: find.byType(Container)),
);
expect(container0.color, Colors.white);
expect(container1.color, Colors.red);
});

View File

@@ -3,8 +3,7 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/focus_scope/focus.2.dart'
as example;
import 'package:flutter_api_samples/widgets/focus_scope/focus.2.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
@@ -27,10 +26,9 @@ void main() {
for (int i = 0; i <= 10; i += 1) {
expect(find.text('CHILD $i'), findsOneWidget);
final ActionChip chip = tester.widget<ActionChip>(find.ancestor(
of: find.text('CHILD $i'),
matching: find.byType(ActionChip)
));
final ActionChip chip = tester.widget<ActionChip>(
find.ancestor(of: find.text('CHILD $i'), matching: find.byType(ActionChip)),
);
expect(chip.focusNode, isNotNull);
expect(chip.focusNode!.hasPrimaryFocus, isTrue);
expect(chip.focusNode!.debugLabel, 'Child $i');

View File

@@ -4,23 +4,20 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_api_samples/widgets/focus_scope/focus_scope.0.dart'
as example;
import 'package:flutter_api_samples/widgets/focus_scope/focus_scope.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
bool hasFocus(WidgetTester tester, IconData icon) =>
tester.widget<IconButton>(
find.ancestor(
of: find.byIcon(icon),
matching: find.byType(IconButton),
),
).focusNode!.hasFocus;
tester
.widget<IconButton>(
find.ancestor(of: find.byIcon(icon), matching: find.byType(IconButton)),
)
.focusNode!
.hasFocus;
testWidgets('The focus is restricted to the foreground', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FocusScopeExampleApp(),
);
await tester.pumpWidget(const example.FocusScopeExampleApp());
expect(find.text('FOREGROUND'), findsOne);
expect(hasFocus(tester, Icons.menu), true);
@@ -32,9 +29,7 @@ void main() {
});
testWidgets('The background can be focused', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FocusScopeExampleApp(),
);
await tester.pumpWidget(const example.FocusScopeExampleApp());
expect(find.text('FOREGROUND'), findsOne);
expect(hasFocus(tester, Icons.menu), true);

View File

@@ -4,7 +4,8 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_api_samples/widgets/focus_traversal/focus_traversal_group.0.dart' as example;
import 'package:flutter_api_samples/widgets/focus_traversal/focus_traversal_group.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
@@ -12,10 +13,10 @@ void main() {
return Focus.of(tester.element(find.text(text))).hasPrimaryFocus;
}
testWidgets('The focus updates should follow the focus traversal groups policy', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FocusTraversalGroupExampleApp(),
);
testWidgets('The focus updates should follow the focus traversal groups policy', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.FocusTraversalGroupExampleApp());
// Set the focus to the first button.
Focus.of(tester.element(find.text('num: 0'))).requestFocus();

View File

@@ -4,7 +4,8 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_api_samples/widgets/focus_traversal/ordered_traversal_policy.0.dart' as example;
import 'package:flutter_api_samples/widgets/focus_traversal/ordered_traversal_policy.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
@@ -12,21 +13,14 @@ void main() {
return Focus.of(tester.element(find.text(text))).hasPrimaryFocus;
}
testWidgets('The focus updates should follow the focus traversal groups policy', (WidgetTester tester) async {
await tester.pumpWidget(
const example.OrderedTraversalPolicyExampleApp(),
);
testWidgets('The focus updates should follow the focus traversal groups policy', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.OrderedTraversalPolicyExampleApp());
expect(hasFocus(tester, 'One'), isTrue);
const List<String> focusOrder = <String>[
'Two',
'Three',
'Four',
'Five',
'Six',
'One',
];
const List<String> focusOrder = <String>['Two', 'Three', 'Four', 'Five', 'Six', 'One'];
for (final String text in focusOrder) {
await tester.sendKeyEvent(LogicalKeyboardKey.tab);

View File

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

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can go back when form is clean', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FormApp(),
);
await tester.pumpWidget(const example.FormApp());
expect(find.text('Are you sure?'), findsNothing);
@@ -21,9 +19,7 @@ void main() {
});
testWidgets('Cannot go back when form is dirty', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FormApp(),
);
await tester.pumpWidget(const example.FormApp());
expect(find.text('Are you sure?'), findsNothing);

View File

@@ -14,9 +14,6 @@ void main() {
});
test('The size of the widget is measured', () {
expect(
example.measureWidget(const SizedBox(width: 234, height: 567)),
const Size(234, 567),
);
expect(example.measureWidget(const SizedBox(width: 234, height: 567)), const Size(234, 567));
});
}

View File

@@ -10,7 +10,7 @@ void main() {
testWidgets('ErrorWidget is displayed in debug mode', (WidgetTester tester) async {
final ErrorWidgetBuilder oldBuilder = ErrorWidget.builder;
ErrorWidget.builder = (FlutterErrorDetails details) {
return ErrorWidget(details.exception);
return ErrorWidget(details.exception);
};
await tester.pumpWidget(const example.ErrorWidgetExampleApp());

View File

@@ -3,38 +3,32 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/gesture_detector/gesture_detector.0.dart'
as example;
import 'package:flutter_api_samples/widgets/gesture_detector/gesture_detector.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'GestureDetector updates icon color and text on tap',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.GestureDetectorExampleApp(),
);
testWidgets('GestureDetector updates icon color and text on tap', (WidgetTester tester) async {
await tester.pumpWidget(const example.GestureDetectorExampleApp());
Icon icon = tester.widget(find.byIcon(Icons.lightbulb_outline));
Icon icon = tester.widget(find.byIcon(Icons.lightbulb_outline));
expect(find.text('TURN LIGHT ON'), findsOneWidget);
expect(icon.color, Colors.black);
expect(find.text('TURN LIGHT ON'), findsOneWidget);
expect(icon.color, Colors.black);
await tester.tap(find.byType(GestureDetector));
await tester.pump();
await tester.tap(find.byType(GestureDetector));
await tester.pump();
icon = tester.widget(find.byIcon(Icons.lightbulb_outline));
icon = tester.widget(find.byIcon(Icons.lightbulb_outline));
expect(find.text('TURN LIGHT OFF'), findsOneWidget);
expect(icon.color, Colors.yellow.shade600);
expect(find.text('TURN LIGHT OFF'), findsOneWidget);
expect(icon.color, Colors.yellow.shade600);
await tester.tap(find.byType(GestureDetector));
await tester.pump();
await tester.tap(find.byType(GestureDetector));
await tester.pump();
icon = tester.widget(find.byIcon(Icons.lightbulb_outline));
icon = tester.widget(find.byIcon(Icons.lightbulb_outline));
expect(find.text('TURN LIGHT ON'), findsOneWidget);
expect(icon.color, Colors.black);
},
);
expect(find.text('TURN LIGHT ON'), findsOneWidget);
expect(icon.color, Colors.black);
});
}

View File

@@ -3,50 +3,35 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/gesture_detector/gesture_detector.1.dart'
as example;
import 'package:flutter_api_samples/widgets/gesture_detector/gesture_detector.1.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'GestureDetector updates Container color on tap',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.GestureDetectorExampleApp(),
);
testWidgets('GestureDetector updates Container color on tap', (WidgetTester tester) async {
await tester.pumpWidget(const example.GestureDetectorExampleApp());
Container container = tester.widget(
find.ancestor(
of: find.byType(GestureDetector),
matching: find.byType(Container),
),
);
Container container = tester.widget(
find.ancestor(of: find.byType(GestureDetector), matching: find.byType(Container)),
);
expect(container.color, Colors.white);
expect(container.color, Colors.white);
await tester.tap(find.byType(GestureDetector));
await tester.pump();
await tester.tap(find.byType(GestureDetector));
await tester.pump();
container = tester.widget(
find.ancestor(
of: find.byType(GestureDetector),
matching: find.byType(Container),
),
);
container = tester.widget(
find.ancestor(of: find.byType(GestureDetector), matching: find.byType(Container)),
);
expect(container.color, Colors.yellow);
expect(container.color, Colors.yellow);
await tester.tap(find.byType(GestureDetector));
await tester.pump();
await tester.tap(find.byType(GestureDetector));
await tester.pump();
container = tester.widget(
find.ancestor(
of: find.byType(GestureDetector),
matching: find.byType(Container),
),
);
container = tester.widget(
find.ancestor(of: find.byType(GestureDetector), matching: find.byType(Container)),
);
expect(container.color, Colors.white);
},
);
expect(container.color, Colors.white);
});
}

View File

@@ -3,12 +3,10 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/gesture_detector/gesture_detector.2.dart'
as example;
import 'package:flutter_api_samples/widgets/gesture_detector/gesture_detector.2.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
void expectBorders(
WidgetTester tester, {
required bool expectGreenHasBorder,
@@ -30,14 +28,16 @@ void main() {
void expectInnerGestureDetectorBehavior(WidgetTester tester, HitTestBehavior behavior) {
// There is a third GestureDetector added by Scaffold.
final Finder innerGestureDetectorFinder = find.byType(GestureDetector).at(1);
final GestureDetector innerGestureDetector = tester.firstWidget<GestureDetector>(innerGestureDetectorFinder);
final GestureDetector innerGestureDetector = tester.firstWidget<GestureDetector>(
innerGestureDetectorFinder,
);
expect(innerGestureDetector.behavior, behavior);
}
testWidgets('Only the green Container shows a red border when tapped', (WidgetTester tester) async {
await tester.pumpWidget(
const example.NestedGestureDetectorsApp(),
);
testWidgets('Only the green Container shows a red border when tapped', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.NestedGestureDetectorsApp());
final Finder greenFinder = find.byType(Container).first;
final Offset greenTopLeftCorner = tester.getTopLeft(greenFinder);
@@ -63,10 +63,10 @@ void main() {
expectInnerGestureDetectorBehavior(tester, HitTestBehavior.opaque);
});
testWidgets('Only the yellow Container shows a red border when tapped', (WidgetTester tester) async {
await tester.pumpWidget(
const example.NestedGestureDetectorsApp(),
);
testWidgets('Only the yellow Container shows a red border when tapped', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.NestedGestureDetectorsApp());
final Finder yellowFinder = find.byType(Container).last;
final Offset yellowTopLeftCorner = tester.getTopLeft(yellowFinder);

View File

@@ -4,15 +4,12 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/gesture_detector/gesture_detector.3.dart'
as example;
import 'package:flutter_api_samples/widgets/gesture_detector/gesture_detector.3.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('The red box always moves inside the green box', (WidgetTester tester) async {
await tester.pumpWidget(
const example.DragBoundaryExampleApp(),
);
await tester.pumpWidget(const example.DragBoundaryExampleApp());
final Finder greenFinder = find.byType(Container).first;
final Finder redFinder = find.byType(Container).last;
final TestGesture drag = await tester.startGesture(tester.getCenter(redFinder));

View File

@@ -4,27 +4,21 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_api_samples/widgets/hardware_keyboard/key_event_manager.0.dart'
as example;
import 'package:flutter_api_samples/widgets/hardware_keyboard/key_event_manager.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('App tracks lifecycle states', (WidgetTester tester) async {
Future<String> getCapturedKey() async {
final Widget textWidget = tester.firstWidget(
find.textContaining('is not handled by shortcuts.'));
find.textContaining('is not handled by shortcuts.'),
);
expect(textWidget, isA<Text>());
return (textWidget as Text).data!.split(' ').first;
}
await tester.pumpWidget(
const MaterialApp(
home: Scaffold(
body: Center(
child: example.FallbackDemo(),
)
),
),
const MaterialApp(home: Scaffold(body: Center(child: example.FallbackDemo()))),
);
// Focus on the first text field.

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Has Hero animation', (WidgetTester tester) async {
await tester.pumpWidget(
const example.HeroApp(),
);
await tester.pumpWidget(const example.HeroApp());
expect(find.text('Hero Sample'), findsOneWidget);
await tester.tap(find.byType(Container));

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Hero flight animation with default rect tween', (WidgetTester tester) async {
await tester.pumpWidget(
const example.HeroApp(),
);
await tester.pumpWidget(const example.HeroApp());
expect(find.text('Hero Sample'), findsOneWidget);
await tester.tap(find.byType(ElevatedButton));
@@ -71,9 +69,7 @@ void main() {
});
testWidgets('Hero flight animation with custom rect tween', (WidgetTester tester) async {
await tester.pumpWidget(
const example.HeroApp(),
);
await tester.pumpWidget(const example.HeroApp());
expect(find.text('Hero Sample'), findsOneWidget);
await tester.tap(find.byType(ElevatedButton));

View File

@@ -5,8 +5,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/image/image.error_builder.0.dart'
as example;
import 'package:flutter_api_samples/widgets/image/image.error_builder.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
@@ -17,24 +16,17 @@ void main() {
});
testWidgets('Has nonexistent url', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ErrorBuilderExampleApp(),
);
await tester.pumpWidget(const example.ErrorBuilderExampleApp());
await tester.pumpAndSettle();
final Image image = tester.widget<Image>(find.byType(Image));
final NetworkImage imageProvider = image.image as NetworkImage;
expect(
imageProvider.url,
equals('https://example.does.not.exist/image.jpg'),
);
expect(imageProvider.url, equals('https://example.does.not.exist/image.jpg'));
});
testWidgets('errorBuilder returns text with emoji', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ErrorBuilderExampleApp(),
);
await tester.pumpWidget(const example.ErrorBuilderExampleApp());
await tester.pumpAndSettle();
final Image image = tester.widget<Image>(find.byType(Image));

View File

@@ -5,8 +5,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/image/image.frame_builder.0.dart'
as example;
import 'package:flutter_api_samples/widgets/image/image.frame_builder.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
@@ -16,10 +15,10 @@ void main() {
HttpOverrides.global = null;
});
testWidgets('The frame builder returns an AnimatedOpacity when not synchronously loaded', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FrameBuilderExampleApp(),
);
testWidgets('The frame builder returns an AnimatedOpacity when not synchronously loaded', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.FrameBuilderExampleApp());
await tester.pumpAndSettle();
final Image image = tester.widget<Image>(find.byType(Image));
@@ -29,17 +28,15 @@ void main() {
const Key key = Key('child');
expect(
frameBuilder(context, const SizedBox(key: key), null, false),
isA<AnimatedOpacity>().having(
(AnimatedOpacity opacity) => opacity.child!.key, 'key', key,
),
frameBuilder(context, const SizedBox(key: key), null, false),
isA<AnimatedOpacity>().having((AnimatedOpacity opacity) => opacity.child!.key, 'key', key),
);
});
testWidgets('The frame builder returns the child when synchronously loaded', (WidgetTester tester) async {
await tester.pumpWidget(
const example.FrameBuilderExampleApp(),
);
testWidgets('The frame builder returns the child when synchronously loaded', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.FrameBuilderExampleApp());
await tester.pumpAndSettle();
final Image image = tester.widget<Image>(find.byType(Image));
@@ -49,10 +46,8 @@ void main() {
const Key key = Key('child');
expect(
frameBuilder(context, const SizedBox(key: key), null, true),
isA<SizedBox>().having(
(SizedBox widget) => widget.key, 'key', key,
),
frameBuilder(context, const SizedBox(key: key), null, true),
isA<SizedBox>().having((SizedBox widget) => widget.key, 'key', key),
);
});
}

View File

@@ -5,8 +5,7 @@
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/image/image.loading_builder.0.dart'
as example;
import 'package:flutter_api_samples/widgets/image/image.loading_builder.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
@@ -16,10 +15,10 @@ void main() {
HttpOverrides.global = null;
});
testWidgets('The loading builder returns the child when there is no loading progress', (WidgetTester tester) async {
await tester.pumpWidget(
const example.LoadingBuilderExampleApp(),
);
testWidgets('The loading builder returns the child when there is no loading progress', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.LoadingBuilderExampleApp());
await tester.pumpAndSettle();
final Image image = tester.widget<Image>(find.byType(Image));
@@ -34,10 +33,10 @@ void main() {
expect(find.byType(CircularProgressIndicator), findsNothing);
});
testWidgets('The loading builder returns a circular progress indicator when loading', (WidgetTester tester) async {
await tester.pumpWidget(
const example.LoadingBuilderExampleApp(),
);
testWidgets('The loading builder returns a circular progress indicator when loading', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.LoadingBuilderExampleApp());
await tester.pumpAndSettle();
final Image image = tester.widget<Image>(find.byType(Image));
@@ -51,10 +50,7 @@ void main() {
home: loadingBuilder(
context,
child,
const ImageChunkEvent(
cumulativeBytesLoaded: 1,
expectedTotalBytes: 10,
),
const ImageChunkEvent(cumulativeBytesLoaded: 1, expectedTotalBytes: 10),
),
),
);

View File

@@ -3,15 +3,12 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/implicit_animations/animated_align.0.dart'
as example;
import 'package:flutter_api_samples/widgets/implicit_animations/animated_align.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('AnimatedAlign animates on tap', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AnimatedAlignExampleApp(),
);
await tester.pumpWidget(const example.AnimatedAlignExampleApp());
final Finder alignFinder = find.descendant(
of: find.byType(AnimatedAlign),

View File

@@ -9,43 +9,23 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('AnimatedContainer updates on tap', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AnimatedContainerExampleApp(),
);
await tester.pumpWidget(const example.AnimatedContainerExampleApp());
Container container = tester.widget(
find.ancestor(
of: find.byType(AnimatedContainer),
matching: find.byType(Container),
),
);
expect(
(container.decoration! as BoxDecoration).color,
equals(Colors.blue),
);
expect(
container.constraints,
equals(const BoxConstraints.tightFor(width: 100, height: 200)),
find.ancestor(of: find.byType(AnimatedContainer), matching: find.byType(Container)),
);
expect((container.decoration! as BoxDecoration).color, equals(Colors.blue));
expect(container.constraints, equals(const BoxConstraints.tightFor(width: 100, height: 200)));
expect(container.alignment, equals(Alignment.topCenter));
await tester.tap(find.byType(FlutterLogo));
await tester.pump();
container = tester.widget(
find.ancestor(
of: find.byType(AnimatedContainer),
matching: find.byType(Container),
),
);
expect(
(container.decoration! as BoxDecoration).color,
equals(Colors.blue),
);
expect(
container.constraints,
equals(const BoxConstraints.tightFor(width: 100, height: 200)),
find.ancestor(of: find.byType(AnimatedContainer), matching: find.byType(Container)),
);
expect((container.decoration! as BoxDecoration).color, equals(Colors.blue));
expect(container.constraints, equals(const BoxConstraints.tightFor(width: 100, height: 200)));
expect(container.alignment, equals(Alignment.topCenter));
// Advance animation to the end by the 2-second duration specified in
@@ -53,19 +33,10 @@ void main() {
await tester.pump(const Duration(seconds: 2));
container = tester.widget(
find.ancestor(
of: find.byType(AnimatedContainer),
matching: find.byType(Container),
),
);
expect(
(container.decoration! as BoxDecoration).color,
equals(Colors.red),
);
expect(
container.constraints,
equals(const BoxConstraints.tightFor(width: 200, height: 100)),
find.ancestor(of: find.byType(AnimatedContainer), matching: find.byType(Container)),
);
expect((container.decoration! as BoxDecoration).color, equals(Colors.red));
expect(container.constraints, equals(const BoxConstraints.tightFor(width: 200, height: 100)));
expect(container.alignment, equals(Alignment.center));
});
}

View File

@@ -10,116 +10,78 @@ import 'package:flutter_api_samples/widgets/implicit_animations/animated_fractio
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'AnimatedFractionallySizedBox animates on tap',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.AnimatedFractionallySizedBoxExampleApp(),
);
testWidgets('AnimatedFractionallySizedBox animates on tap', (WidgetTester tester) async {
await tester.pumpWidget(const example.AnimatedFractionallySizedBoxExampleApp());
final Finder fractionallySizedBoxFinder = find.descendant(
of: find.byType(AnimatedFractionallySizedBox),
matching: find.byType(FractionallySizedBox),
);
final Finder fractionallySizedBoxFinder = find.descendant(
of: find.byType(AnimatedFractionallySizedBox),
matching: find.byType(FractionallySizedBox),
);
const double beginWidthFactor = 0.75;
const double endWidthFactor = 0.25;
const double beginHeightFactor = 0.25;
const double endHeightFactor = 0.75;
const Alignment beginAlignment = Alignment.bottomRight;
const Alignment endAlignment = Alignment.topLeft;
const double beginWidthFactor = 0.75;
const double endWidthFactor = 0.25;
const double beginHeightFactor = 0.25;
const double endHeightFactor = 0.75;
const Alignment beginAlignment = Alignment.bottomRight;
const Alignment endAlignment = Alignment.topLeft;
FractionallySizedBox fractionallySizedBox = tester.widget(
fractionallySizedBoxFinder,
);
expect(fractionallySizedBox.widthFactor, beginWidthFactor);
expect(fractionallySizedBox.heightFactor, beginHeightFactor);
expect(fractionallySizedBox.alignment, beginAlignment);
FractionallySizedBox fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
expect(fractionallySizedBox.widthFactor, beginWidthFactor);
expect(fractionallySizedBox.heightFactor, beginHeightFactor);
expect(fractionallySizedBox.alignment, beginAlignment);
// Tap on the AnimatedFractionallySizedBoxExample to start the forward
// animation.
await tester.tap(
find.byType(example.AnimatedFractionallySizedBoxExample),
);
await tester.pump();
// Tap on the AnimatedFractionallySizedBoxExample to start the forward
// animation.
await tester.tap(find.byType(example.AnimatedFractionallySizedBoxExample));
await tester.pump();
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
expect(fractionallySizedBox.widthFactor, beginWidthFactor);
expect(fractionallySizedBox.heightFactor, beginHeightFactor);
expect(fractionallySizedBox.alignment, beginAlignment);
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
expect(fractionallySizedBox.widthFactor, beginWidthFactor);
expect(fractionallySizedBox.heightFactor, beginHeightFactor);
expect(fractionallySizedBox.alignment, beginAlignment);
// Advance animation to the middle.
await tester.pump(
example.AnimatedFractionallySizedBoxExampleApp.duration ~/ 2,
);
// Advance animation to the middle.
await tester.pump(example.AnimatedFractionallySizedBoxExampleApp.duration ~/ 2);
final double t =
example.AnimatedFractionallySizedBoxExampleApp.curve.transform(0.5);
final double t = example.AnimatedFractionallySizedBoxExampleApp.curve.transform(0.5);
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
expect(
fractionallySizedBox.widthFactor,
lerpDouble(beginWidthFactor, endWidthFactor, t),
);
expect(
fractionallySizedBox.heightFactor,
lerpDouble(beginHeightFactor, endHeightFactor, t),
);
expect(
fractionallySizedBox.alignment,
Alignment.lerp(beginAlignment, endAlignment, t),
);
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
expect(fractionallySizedBox.widthFactor, lerpDouble(beginWidthFactor, endWidthFactor, t));
expect(fractionallySizedBox.heightFactor, lerpDouble(beginHeightFactor, endHeightFactor, t));
expect(fractionallySizedBox.alignment, Alignment.lerp(beginAlignment, endAlignment, t));
// Advance animation to the end.
await tester.pump(
example.AnimatedFractionallySizedBoxExampleApp.duration ~/ 2,
);
// Advance animation to the end.
await tester.pump(example.AnimatedFractionallySizedBoxExampleApp.duration ~/ 2);
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
expect(fractionallySizedBox.widthFactor, endWidthFactor);
expect(fractionallySizedBox.heightFactor, endHeightFactor);
expect(fractionallySizedBox.alignment, endAlignment);
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
expect(fractionallySizedBox.widthFactor, endWidthFactor);
expect(fractionallySizedBox.heightFactor, endHeightFactor);
expect(fractionallySizedBox.alignment, endAlignment);
// Tap on the AnimatedFractionallySizedBoxExample again to start the
// reverse animation.
await tester.tap(
find.byType(example.AnimatedFractionallySizedBoxExample),
);
await tester.pump();
// Tap on the AnimatedFractionallySizedBoxExample again to start the
// reverse animation.
await tester.tap(find.byType(example.AnimatedFractionallySizedBoxExample));
await tester.pump();
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
expect(fractionallySizedBox.widthFactor, endWidthFactor);
expect(fractionallySizedBox.heightFactor, endHeightFactor);
expect(fractionallySizedBox.alignment, endAlignment);
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
expect(fractionallySizedBox.widthFactor, endWidthFactor);
expect(fractionallySizedBox.heightFactor, endHeightFactor);
expect(fractionallySizedBox.alignment, endAlignment);
// Advance animation to the middle.
await tester.pump(
example.AnimatedFractionallySizedBoxExampleApp.duration ~/ 2,
);
// Advance animation to the middle.
await tester.pump(example.AnimatedFractionallySizedBoxExampleApp.duration ~/ 2);
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
expect(
fractionallySizedBox.widthFactor,
lerpDouble(endWidthFactor, beginWidthFactor, t),
);
expect(
fractionallySizedBox.heightFactor,
lerpDouble(endHeightFactor, beginHeightFactor, t),
);
expect(
fractionallySizedBox.alignment,
Alignment.lerp(endAlignment, beginAlignment, t),
);
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
expect(fractionallySizedBox.widthFactor, lerpDouble(endWidthFactor, beginWidthFactor, t));
expect(fractionallySizedBox.heightFactor, lerpDouble(endHeightFactor, beginHeightFactor, t));
expect(fractionallySizedBox.alignment, Alignment.lerp(endAlignment, beginAlignment, t));
// Advance animation to the end.
await tester.pump(
example.AnimatedFractionallySizedBoxExampleApp.duration ~/ 2,
);
// Advance animation to the end.
await tester.pump(example.AnimatedFractionallySizedBoxExampleApp.duration ~/ 2);
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
expect(fractionallySizedBox.widthFactor, beginWidthFactor);
expect(fractionallySizedBox.heightFactor, beginHeightFactor);
expect(fractionallySizedBox.alignment, beginAlignment);
},
);
fractionallySizedBox = tester.widget(fractionallySizedBoxFinder);
expect(fractionallySizedBox.widthFactor, beginWidthFactor);
expect(fractionallySizedBox.heightFactor, beginHeightFactor);
expect(fractionallySizedBox.alignment, beginAlignment);
});
}

View File

@@ -3,48 +3,33 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/implicit_animations/animated_padding.0.dart'
as example;
import 'package:flutter_api_samples/widgets/implicit_animations/animated_padding.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'AnimatedPadding animates on ElevatedButton tap',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.AnimatedPaddingExampleApp(),
);
testWidgets('AnimatedPadding animates on ElevatedButton tap', (WidgetTester tester) async {
await tester.pumpWidget(const example.AnimatedPaddingExampleApp());
Padding padding = tester.widget(
find.descendant(
of: find.byType(AnimatedPadding),
matching: find.byType(Padding),
),
);
expect(padding.padding, equals(EdgeInsets.zero));
Padding padding = tester.widget(
find.descendant(of: find.byType(AnimatedPadding), matching: find.byType(Padding)),
);
expect(padding.padding, equals(EdgeInsets.zero));
await tester.tap(find.byType(ElevatedButton));
await tester.pump();
await tester.tap(find.byType(ElevatedButton));
await tester.pump();
padding = tester.widget(
find.descendant(
of: find.byType(AnimatedPadding),
matching: find.byType(Padding),
),
);
expect(padding.padding, equals(EdgeInsets.zero));
padding = tester.widget(
find.descendant(of: find.byType(AnimatedPadding), matching: find.byType(Padding)),
);
expect(padding.padding, equals(EdgeInsets.zero));
// Advance animation to the end by the 2-second duration specified in
// the example app.
await tester.pump(const Duration(seconds: 2));
// Advance animation to the end by the 2-second duration specified in
// the example app.
await tester.pump(const Duration(seconds: 2));
padding = tester.widget(
find.descendant(
of: find.byType(AnimatedPadding),
matching: find.byType(Padding),
),
);
expect(padding.padding, equals(const EdgeInsets.all(100.0)));
},
);
padding = tester.widget(
find.descendant(of: find.byType(AnimatedPadding), matching: find.byType(Padding)),
);
expect(padding.padding, equals(const EdgeInsets.all(100.0)));
});
}

View File

@@ -10,82 +10,76 @@ import 'package:flutter_api_samples/widgets/implicit_animations/animated_positio
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'AnimatedPositioned animates on tap',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.AnimatedPositionedExampleApp(),
);
testWidgets('AnimatedPositioned animates on tap', (WidgetTester tester) async {
await tester.pumpWidget(const example.AnimatedPositionedExampleApp());
final Finder positionedFinder = find.descendant(
of: find.byType(AnimatedPositioned),
matching: find.byType(Positioned),
);
final Finder positionedFinder = find.descendant(
of: find.byType(AnimatedPositioned),
matching: find.byType(Positioned),
);
const double beginWidth = 50.0;
const double endWidth = 200.0;
const double beginHeight = 200.0;
const double endHeight = 50.0;
const double beginTop = 150.0;
const double endTop = 50.0;
const double beginWidth = 50.0;
const double endWidth = 200.0;
const double beginHeight = 200.0;
const double endHeight = 50.0;
const double beginTop = 150.0;
const double endTop = 50.0;
Positioned positioned = tester.widget(positionedFinder);
expect(positioned.width, beginWidth);
expect(positioned.height, beginHeight);
expect(positioned.top, beginTop);
Positioned positioned = tester.widget(positionedFinder);
expect(positioned.width, beginWidth);
expect(positioned.height, beginHeight);
expect(positioned.top, beginTop);
// Tap on the 'Tap me' text to start the forward animation.
await tester.tap(find.text('Tap me'));
await tester.pump();
// Tap on the 'Tap me' text to start the forward animation.
await tester.tap(find.text('Tap me'));
await tester.pump();
positioned = tester.widget(positionedFinder);
expect(positioned.width, beginWidth);
expect(positioned.height, beginHeight);
expect(positioned.top, beginTop);
positioned = tester.widget(positionedFinder);
expect(positioned.width, beginWidth);
expect(positioned.height, beginHeight);
expect(positioned.top, beginTop);
// Advance animation to the middle.
await tester.pump(example.AnimatedPositionedExampleApp.duration ~/ 2);
// Advance animation to the middle.
await tester.pump(example.AnimatedPositionedExampleApp.duration ~/ 2);
final double t =
example.AnimatedPositionedExampleApp.curve.transform(0.5);
final double t = example.AnimatedPositionedExampleApp.curve.transform(0.5);
positioned = tester.widget(positionedFinder);
expect(positioned.width, lerpDouble(beginWidth, endWidth, t));
expect(positioned.height, lerpDouble(beginHeight, endHeight, t));
expect(positioned.top, lerpDouble(beginTop, endTop, t));
positioned = tester.widget(positionedFinder);
expect(positioned.width, lerpDouble(beginWidth, endWidth, t));
expect(positioned.height, lerpDouble(beginHeight, endHeight, t));
expect(positioned.top, lerpDouble(beginTop, endTop, t));
// Advance animation to the end.
await tester.pump(example.AnimatedPositionedExampleApp.duration ~/ 2);
// Advance animation to the end.
await tester.pump(example.AnimatedPositionedExampleApp.duration ~/ 2);
positioned = tester.widget(positionedFinder);
expect(positioned.width, endWidth);
expect(positioned.height, endHeight);
expect(positioned.top, endTop);
positioned = tester.widget(positionedFinder);
expect(positioned.width, endWidth);
expect(positioned.height, endHeight);
expect(positioned.top, endTop);
// Tap on the 'Tap me' text again to start the reverse animation.
await tester.tap(find.text('Tap me'));
await tester.pump();
// Tap on the 'Tap me' text again to start the reverse animation.
await tester.tap(find.text('Tap me'));
await tester.pump();
positioned = tester.widget(positionedFinder);
expect(positioned.width, endWidth);
expect(positioned.height, endHeight);
expect(positioned.top, endTop);
positioned = tester.widget(positionedFinder);
expect(positioned.width, endWidth);
expect(positioned.height, endHeight);
expect(positioned.top, endTop);
// Advance animation to the middle.
await tester.pump(example.AnimatedPositionedExampleApp.duration ~/ 2);
// Advance animation to the middle.
await tester.pump(example.AnimatedPositionedExampleApp.duration ~/ 2);
positioned = tester.widget(positionedFinder);
expect(positioned.width, lerpDouble(endWidth, beginWidth, t));
expect(positioned.height, lerpDouble(endHeight, beginHeight, t));
expect(positioned.top, lerpDouble(endTop, beginTop, t));
positioned = tester.widget(positionedFinder);
expect(positioned.width, lerpDouble(endWidth, beginWidth, t));
expect(positioned.height, lerpDouble(endHeight, beginHeight, t));
expect(positioned.top, lerpDouble(endTop, beginTop, t));
// Advance animation to the end.
await tester.pump(example.AnimatedPositionedExampleApp.duration ~/ 2);
// Advance animation to the end.
await tester.pump(example.AnimatedPositionedExampleApp.duration ~/ 2);
positioned = tester.widget(positionedFinder);
expect(positioned.width, beginWidth);
expect(positioned.height, beginHeight);
expect(positioned.top, beginTop);
},
);
positioned = tester.widget(positionedFinder);
expect(positioned.width, beginWidth);
expect(positioned.height, beginHeight);
expect(positioned.top, beginTop);
});
}

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Translate FlutterLogo using AnimatedSlide', (WidgetTester tester) async {
await tester.pumpWidget(
const example.AnimatedSlideApp(),
);
await tester.pumpWidget(const example.AnimatedSlideApp());
Offset logoOffset = tester.getCenter(find.byType(FlutterLogo));
expect(logoOffset.dx, 376.0);

View File

@@ -10,75 +10,72 @@ import 'package:flutter_api_samples/widgets/implicit_animations/sliver_animated_
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets(
'SilverAnimatedOpacity animates on FloatingActionButton tap',
(WidgetTester tester) async {
await tester.pumpWidget(
const example.SliverAnimatedOpacityExampleApp(),
);
testWidgets('SilverAnimatedOpacity animates on FloatingActionButton tap', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.SliverAnimatedOpacityExampleApp());
final Finder fadeTransitionFinder = find.descendant(
of: find.byType(SliverAnimatedOpacity),
matching: find.byType(SliverFadeTransition),
);
final Finder fadeTransitionFinder = find.descendant(
of: find.byType(SliverAnimatedOpacity),
matching: find.byType(SliverFadeTransition),
);
const double beginOpacity = 1.0;
const double endOpacity = 0.0;
const double beginOpacity = 1.0;
const double endOpacity = 0.0;
SliverFadeTransition fadeTransition = tester.widget(fadeTransitionFinder);
expect(fadeTransition.opacity.value, beginOpacity);
SliverFadeTransition fadeTransition = tester.widget(fadeTransitionFinder);
expect(fadeTransition.opacity.value, beginOpacity);
// Tap on the FloatingActionButton to start the forward animation.
await tester.tap(find.byType(FloatingActionButton));
await tester.pump();
// Tap on the FloatingActionButton to start the forward animation.
await tester.tap(find.byType(FloatingActionButton));
await tester.pump();
fadeTransition = tester.widget(fadeTransitionFinder);
expect(fadeTransition.opacity.value, beginOpacity);
fadeTransition = tester.widget(fadeTransitionFinder);
expect(fadeTransition.opacity.value, beginOpacity);
// Advance animation to the middle.
await tester.pump(example.SliverAnimatedOpacityExampleApp.duration ~/ 2);
// Advance animation to the middle.
await tester.pump(example.SliverAnimatedOpacityExampleApp.duration ~/ 2);
fadeTransition = tester.widget(fadeTransitionFinder);
expect(
fadeTransition.opacity.value,
lerpDouble(
beginOpacity,
endOpacity,
example.SliverAnimatedOpacityExampleApp.curve.transform(0.5),
),
);
fadeTransition = tester.widget(fadeTransitionFinder);
expect(
fadeTransition.opacity.value,
lerpDouble(
beginOpacity,
endOpacity,
example.SliverAnimatedOpacityExampleApp.curve.transform(0.5),
),
);
// Advance animation to the end.
await tester.pump(example.SliverAnimatedOpacityExampleApp.duration ~/ 2);
// Advance animation to the end.
await tester.pump(example.SliverAnimatedOpacityExampleApp.duration ~/ 2);
fadeTransition = tester.widget(fadeTransitionFinder);
expect(fadeTransition.opacity.value, endOpacity);
fadeTransition = tester.widget(fadeTransitionFinder);
expect(fadeTransition.opacity.value, endOpacity);
// Tap on the FloatingActionButton again to start the reverse animation.
await tester.tap(find.byType(FloatingActionButton));
await tester.pump();
// Tap on the FloatingActionButton again to start the reverse animation.
await tester.tap(find.byType(FloatingActionButton));
await tester.pump();
fadeTransition = tester.widget(fadeTransitionFinder);
expect(fadeTransition.opacity.value, endOpacity);
fadeTransition = tester.widget(fadeTransitionFinder);
expect(fadeTransition.opacity.value, endOpacity);
// Advance animation to the middle.
await tester.pump(example.SliverAnimatedOpacityExampleApp.duration ~/ 2);
// Advance animation to the middle.
await tester.pump(example.SliverAnimatedOpacityExampleApp.duration ~/ 2);
fadeTransition = tester.widget(fadeTransitionFinder);
expect(
fadeTransition.opacity.value,
lerpDouble(
endOpacity,
beginOpacity,
example.SliverAnimatedOpacityExampleApp.curve.transform(0.5),
),
);
fadeTransition = tester.widget(fadeTransitionFinder);
expect(
fadeTransition.opacity.value,
lerpDouble(
endOpacity,
beginOpacity,
example.SliverAnimatedOpacityExampleApp.curve.transform(0.5),
),
);
// Advance animation to the end.
await tester.pump(example.SliverAnimatedOpacityExampleApp.duration ~/ 2);
// Advance animation to the end.
await tester.pump(example.SliverAnimatedOpacityExampleApp.duration ~/ 2);
fadeTransition = tester.widget(fadeTransitionFinder);
expect(fadeTransition.opacity.value, beginOpacity);
},
);
fadeTransition = tester.widget(fadeTransitionFinder);
expect(fadeTransition.opacity.value, beginOpacity);
});
}

View File

@@ -8,20 +8,18 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Rebuild widget using InheritedModel', (WidgetTester tester) async {
await tester.pumpWidget(
const example.InheritedModelApp(),
);
await tester.pumpWidget(const example.InheritedModelApp());
BoxDecoration? decoration = tester.widget<AnimatedContainer>(
find.byType(AnimatedContainer).first,
).decoration as BoxDecoration?;
BoxDecoration? decoration =
tester.widget<AnimatedContainer>(find.byType(AnimatedContainer).first).decoration
as BoxDecoration?;
expect(decoration!.color, Colors.blue);
await tester.tap(find.text('Update background'));
await tester.pumpAndSettle();
decoration = tester.widget<AnimatedContainer>(
find.byType(AnimatedContainer).first,
).decoration as BoxDecoration?;
decoration =
tester.widget<AnimatedContainer>(find.byType(AnimatedContainer).first).decoration
as BoxDecoration?;
expect(decoration!.color, Colors.red);
double? size = tester.widget<FlutterLogo>(find.byType(FlutterLogo)).size;

View File

@@ -5,24 +5,22 @@
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/inherited_notifier/inherited_notifier.0.dart' as example;
import 'package:flutter_api_samples/widgets/inherited_notifier/inherited_notifier.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('It rotates the spinners', (WidgetTester tester) async {
await tester.pumpWidget(
const example.InheritedNotifierExampleApp(),
);
await tester.pumpWidget(const example.InheritedNotifierExampleApp());
final Iterable<Transform> widgets = tester.widgetList<Transform>(
find.ancestor(
of: find.text('Whee!'),
matching: find.byType(Transform),
),
find.ancestor(of: find.text('Whee!'), matching: find.byType(Transform)),
);
Matcher transformMatcher(Matrix4 matrix) {
return everyElement(isA<Transform>().having((Transform widget) => widget.transform, 'transform', matrix));
return everyElement(
isA<Transform>().having((Transform widget) => widget.transform, 'transform', matrix),
);
}
expect(widgets, transformMatcher(Matrix4.identity()));
@@ -40,7 +38,14 @@ void main() {
expect(widgets, transformMatcher(Matrix4.rotationZ(0.8 * math.pi)));
await tester.pump(const Duration(seconds: 1));
expect(widgets, transformMatcher(Matrix4.identity()..storage[0] = -1..storage[5] = -1));
expect(
widgets,
transformMatcher(
Matrix4.identity()
..storage[0] = -1
..storage[5] = -1,
),
);
await tester.pump(const Duration(seconds: 1));
expect(widgets, transformMatcher(Matrix4.rotationZ(1.2 * math.pi)));

View File

@@ -3,20 +3,19 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/inherited_theme/inherited_theme.0.dart'
as example;
import 'package:flutter_api_samples/widgets/inherited_theme/inherited_theme.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('StreamBuilder listens to internal stream', (WidgetTester tester) async {
await tester.pumpWidget(
const example.InheritedThemeExampleApp(),
);
await tester.pumpWidget(const example.InheritedThemeExampleApp());
expect(find.byType(GestureDetector), findsOne);
expect(find.text('Tap Here'), findsOne);
final DefaultTextStyle bodyDefaultTextStyle = DefaultTextStyle.of(tester.element(find.text('Tap Here')));
final DefaultTextStyle bodyDefaultTextStyle = DefaultTextStyle.of(
tester.element(find.text('Tap Here')),
);
expect(bodyDefaultTextStyle.style, const TextStyle(fontSize: 48, color: Colors.blue));
await tester.tap(find.text('Tap Here'));
@@ -24,7 +23,9 @@ void main() {
expect(find.text('Hello World'), findsOne);
final DefaultTextStyle routeDefaultTextStyle = DefaultTextStyle.of(tester.element(find.text('Hello World')));
final DefaultTextStyle routeDefaultTextStyle = DefaultTextStyle.of(
tester.element(find.text('Hello World')),
);
expect(routeDefaultTextStyle.style, const TextStyle(fontSize: 48, color: Colors.blue));
});
}

View File

@@ -9,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Has correct items on screen', (WidgetTester tester) async {
await tester.pumpWidget(
const example.InteractiveViewerExampleApp(),
);
await tester.pumpWidget(const example.InteractiveViewerExampleApp());
expect(find.widgetWithText(AppBar, 'InteractiveViewer Sample'), findsOne);
expect(find.byType(InteractiveViewer), findsOne);

View File

@@ -9,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('has correct items on screen', (WidgetTester tester) async {
await tester.pumpWidget(
const example.IVBuilderExampleApp(),
);
await tester.pumpWidget(const example.IVBuilderExampleApp());
final Finder positionedFinder = find.byType(Positioned);
final Finder zeroFinder = find.text('0 x 0');

View File

@@ -9,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('The reset button resets the view with an animation', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ConstrainedExampleApp(),
);
await tester.pumpWidget(const example.ConstrainedExampleApp());
expect(find.widgetWithText(AppBar, 'Constrained Sample'), findsOne);
expect(find.byType(InteractiveViewer), findsOne);

View File

@@ -9,9 +9,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('The reset button resets the view with an animation', (WidgetTester tester) async {
await tester.pumpWidget(
const example.TransformationControllerExampleApp(),
);
await tester.pumpWidget(const example.TransformationControllerExampleApp());
expect(find.widgetWithText(AppBar, 'Controller demo'), findsOne);
expect(find.byType(InteractiveViewer), findsOne);

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('has two containers when wide', (WidgetTester tester) async {
await tester.pumpWidget(
const example.LayoutBuilderExampleApp(),
);
await tester.pumpWidget(const example.LayoutBuilderExampleApp());
final Finder containerFinder = find.byType(Container);
expect(containerFinder, findsNWidgets(2));

View File

@@ -3,12 +3,10 @@
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter_api_samples/widgets/magnifier/cupertino_magnifier.0.dart'
as example;
import 'package:flutter_api_samples/widgets/magnifier/cupertino_magnifier.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('CupertinoMagnifier must be visible', (WidgetTester tester) async {
await tester.pumpWidget(const example.CupertinoMagnifierApp());
@@ -54,9 +52,6 @@ void main() {
await tester.dragFrom(centerOfPositioned, dragDistance);
await tester.pump();
expect(
positionedWidgetInTree,
isPositionedAt(updatedPositioned),
);
expect(positionedWidgetInTree, isPositionedAt(updatedPositioned));
});
}

View File

@@ -3,12 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/cupertino.dart';
import 'package:flutter_api_samples/widgets/magnifier/cupertino_text_magnifier.0.dart'
as example;
import 'package:flutter_api_samples/widgets/magnifier/cupertino_text_magnifier.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('CupertinoTextMagnifier must be visible after longPress', (WidgetTester tester) async {
testWidgets('CupertinoTextMagnifier must be visible after longPress', (
WidgetTester tester,
) async {
await tester.pumpWidget(const example.CupertinoTextMagnifierApp());
final Finder cupertinoTextFieldWidget = find.byType(CupertinoTextField);

View File

@@ -3,8 +3,7 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/magnifier/magnifier.0.dart'
as example;
import 'package:flutter_api_samples/widgets/magnifier/magnifier.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
@@ -38,10 +37,7 @@ void main() {
);
await tester.dragFrom(centerOfPositioned, dragDistance);
await tester.pump();
expect(
positionedWidgetInTree,
isPositionedAt(updatedPositioned),
);
expect(positionedWidgetInTree, isPositionedAt(updatedPositioned));
});
testWidgets('should match golden', (WidgetTester tester) async {
@@ -53,9 +49,6 @@ void main() {
await tester.dragFrom(centerOfPositioned, dragDistance);
await tester.pump();
await expectLater(
find.byType(RepaintBoundary).last,
matchesGoldenFile('magnifier.0_test.png'),
);
await expectLater(find.byType(RepaintBoundary).last, matchesGoldenFile('magnifier.0_test.png'));
});
}

View File

@@ -8,11 +8,11 @@ import 'package:flutter_api_samples/widgets/media_query/media_query_data.system_
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('The slider should be padded with the system gesture insets', (WidgetTester tester) async {
testWidgets('The slider should be padded with the system gesture insets', (
WidgetTester tester,
) async {
tester.view.systemGestureInsets = const FakeViewPadding(left: 60, right: 60);
await tester.pumpWidget(
const example.SystemGestureInsetsExampleApp(),
);
await tester.pumpWidget(const example.SystemGestureInsetsExampleApp());
expect(find.widgetWithText(AppBar, 'Pad Slider to avoid systemGestureInsets'), findsOne);

View File

@@ -7,18 +7,16 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('It should show the home page', (WidgetTester tester) async {
await tester.pumpWidget(
const example.NavigatorExampleApp(),
);
await tester.pumpWidget(const example.NavigatorExampleApp());
expect(find.text('Home Page'), findsOne);
});
testWidgets('It should start from the sign up page and follow the flow to reach the home page', (WidgetTester tester) async {
testWidgets('It should start from the sign up page and follow the flow to reach the home page', (
WidgetTester tester,
) async {
tester.platformDispatcher.defaultRouteNameTestValue = '/signup';
await tester.pumpWidget(
const example.NavigatorExampleApp(),
);
await tester.pumpWidget(const example.NavigatorExampleApp());
expect(find.text('Collect Personal Info Page'), findsOne);

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('It pushes a restorable route and pops it', (WidgetTester tester) async {
await tester.pumpWidget(
const example.RestorablePushExampleApp(),
);
await tester.pumpWidget(const example.RestorablePushExampleApp());
expect(find.widgetWithText(AppBar, 'Sample Code'), findsOne);
expect(find.byType(BackButton), findsNothing);
@@ -25,9 +23,7 @@ void main() {
});
testWidgets('It pushes a restorable route and restores it', (WidgetTester tester) async {
await tester.pumpWidget(
const example.RestorablePushExampleApp(),
);
await tester.pumpWidget(const example.RestorablePushExampleApp());
expect(find.widgetWithText(AppBar, 'Sample Code'), findsOne);
expect(find.byType(BackButton), findsNothing);

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/navigator/navigator.restorable_push_and_remove_until.0.dart' as example;
import 'package:flutter_api_samples/widgets/navigator/navigator.restorable_push_and_remove_until.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('It pushes a restorable route and pops it', (WidgetTester tester) async {
await tester.pumpWidget(
const example.RestorablePushAndRemoveUntilExampleApp(),
);
await tester.pumpWidget(const example.RestorablePushAndRemoveUntilExampleApp());
expect(find.widgetWithText(AppBar, 'Sample Code'), findsOne);
expect(find.byType(BackButton), findsNothing);
@@ -25,9 +24,7 @@ void main() {
});
testWidgets('It pushes a restorable route and restores it', (WidgetTester tester) async {
await tester.pumpWidget(
const example.RestorablePushAndRemoveUntilExampleApp(),
);
await tester.pumpWidget(const example.RestorablePushAndRemoveUntilExampleApp());
expect(find.widgetWithText(AppBar, 'Sample Code'), findsOne);
expect(find.byType(BackButton), findsNothing);

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/navigator/navigator.restorable_push_replacement.0.dart' as example;
import 'package:flutter_api_samples/widgets/navigator/navigator.restorable_push_replacement.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('It pushes a restorable route and restores it', (WidgetTester tester) async {
await tester.pumpWidget(
const example.RestorablePushReplacementExampleApp(),
);
await tester.pumpWidget(const example.RestorablePushReplacementExampleApp());
expect(find.widgetWithText(AppBar, 'Sample Code'), findsOne);
expect(find.text('This is the initial route.'), findsOne);

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/navigator/navigator_state.restorable_push.0.dart' as example;
import 'package:flutter_api_samples/widgets/navigator/navigator_state.restorable_push.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('It pushes a restorable route and pops it', (WidgetTester tester) async {
await tester.pumpWidget(
const example.RestorablePushExampleApp(),
);
await tester.pumpWidget(const example.RestorablePushExampleApp());
expect(find.widgetWithText(AppBar, 'Sample Code'), findsOne);
expect(find.byType(BackButton), findsNothing);
@@ -25,9 +24,7 @@ void main() {
});
testWidgets('It pushes a restorable route and restores it', (WidgetTester tester) async {
await tester.pumpWidget(
const example.RestorablePushExampleApp(),
);
await tester.pumpWidget(const example.RestorablePushExampleApp());
expect(find.widgetWithText(AppBar, 'Sample Code'), findsOne);
expect(find.byType(BackButton), findsNothing);

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/navigator/navigator_state.restorable_push_and_remove_until.0.dart' as example;
import 'package:flutter_api_samples/widgets/navigator/navigator_state.restorable_push_and_remove_until.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('It pushes a restorable route and pops it', (WidgetTester tester) async {
await tester.pumpWidget(
const example.RestorablePushAndRemoveUntilExampleApp(),
);
await tester.pumpWidget(const example.RestorablePushAndRemoveUntilExampleApp());
expect(find.widgetWithText(AppBar, 'Sample Code'), findsOne);
expect(find.byType(BackButton), findsNothing);
@@ -25,9 +24,7 @@ void main() {
});
testWidgets('It pushes a restorable route and restores it', (WidgetTester tester) async {
await tester.pumpWidget(
const example.RestorablePushAndRemoveUntilExampleApp(),
);
await tester.pumpWidget(const example.RestorablePushAndRemoveUntilExampleApp());
expect(find.widgetWithText(AppBar, 'Sample Code'), findsOne);
expect(find.byType(BackButton), findsNothing);

View File

@@ -3,14 +3,13 @@
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_api_samples/widgets/navigator/navigator_state.restorable_push_replacement.0.dart' as example;
import 'package:flutter_api_samples/widgets/navigator/navigator_state.restorable_push_replacement.0.dart'
as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('It pushes a restorable route and restores it', (WidgetTester tester) async {
await tester.pumpWidget(
const example.RestorablePushReplacementExampleApp(),
);
await tester.pumpWidget(const example.RestorablePushReplacementExampleApp());
expect(find.widgetWithText(AppBar, 'Sample Code'), findsOne);
expect(find.text('This is the initial route.'), findsOne);

View File

@@ -8,9 +8,7 @@ import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('It pushes a restorable route and pops it', (WidgetTester tester) async {
await tester.pumpWidget(
const example.RestorableRouteFutureExampleApp(),
);
await tester.pumpWidget(const example.RestorableRouteFutureExampleApp());
expect(find.widgetWithText(AppBar, 'RestorableRouteFuture Example'), findsOne);
expect(find.byType(BackButton), findsNothing);
@@ -36,9 +34,7 @@ void main() {
});
testWidgets('It pushes a restorable route and restores it', (WidgetTester tester) async {
await tester.pumpWidget(
const example.RestorableRouteFutureExampleApp(),
);
await tester.pumpWidget(const example.RestorableRouteFutureExampleApp());
expect(find.widgetWithText(AppBar, 'RestorableRouteFuture Example'), findsOne);
expect(find.byType(BackButton), findsNothing);

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