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:
committed by
GitHub
parent
8e0993eda8
commit
5491c8c146
@@ -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),
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user