Auto-format Framework (#160545)

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

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

---------

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

View File

@@ -9,10 +9,10 @@ import 'package:integration_ui/overflow.dart' as app;
void main() {
group('Integration Test', () {
testWidgets('smoke test', (WidgetTester tester) async {
app.main();
await tester.pumpAndSettle();
app.main();
await tester.pumpAndSettle();
expect(find.byType(SizedBox), findsOneWidget);
});
expect(find.byType(SizedBox), findsOneWidget);
});
});
}

View File

@@ -11,9 +11,9 @@ void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
group('end-to-end test', () {
testWidgets('Use button to resize window',
timeout: const Timeout(Duration(seconds: 5)),
(WidgetTester tester) async {
testWidgets('Use button to resize window', timeout: const Timeout(Duration(seconds: 5)), (
WidgetTester tester,
) async {
const app.ResizeApp resizeApp = app.ResizeApp();
widgets.runApp(resizeApp);
@@ -42,16 +42,18 @@ void main() {
});
});
testWidgets('resize window after calling runApp twice, the second with no content',
timeout: const Timeout(Duration(seconds: 5)),
(WidgetTester tester) async {
const app.ResizeApp root = app.ResizeApp();
widgets.runApp(root);
widgets.runApp(widgets.Container());
testWidgets(
'resize window after calling runApp twice, the second with no content',
timeout: const Timeout(Duration(seconds: 5)),
(WidgetTester tester) async {
const app.ResizeApp root = app.ResizeApp();
widgets.runApp(root);
widgets.runApp(widgets.Container());
await tester.pumpAndSettle();
await tester.pumpAndSettle();
const widgets.Size expectedSize = widgets.Size(100, 100);
await app.ResizeApp.resize(expectedSize);
});
const widgets.Size expectedSize = widgets.Size(100, 100);
await app.ResizeApp.resize(expectedSize);
},
);
}

View File

@@ -11,14 +11,14 @@ void main() {
}
class Test extends SingleChildRenderObjectWidget {
const Test({ super.key });
const Test({super.key});
@override
RenderTest createRenderObject(BuildContext context) => RenderTest();
}
class RenderTest extends RenderProxyBox {
RenderTest({ RenderBox? child }) : super(child);
RenderTest({RenderBox? child}) : super(child);
@override
void debugPaintSize(PaintingContext context, Offset offset) {

View File

@@ -27,22 +27,15 @@ class DriverTestAppState extends State<DriverTestApp> {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('FlutterDriver test'),
),
appBar: AppBar(title: const Text('FlutterDriver test')),
body: ListView(
padding: const EdgeInsets.all(5.0),
children: <Widget>[
Row(
children: <Widget>[
Expanded(
child: Text(present ? 'present' : 'absent'),
),
Expanded(child: Text(present ? 'present' : 'absent')),
ElevatedButton(
child: const Text(
'toggle',
key: ValueKey<String>('togglePresent'),
),
child: const Text('toggle', key: ValueKey<String>('togglePresent')),
onPressed: () {
setState(() {
present = !present;
@@ -53,9 +46,7 @@ class DriverTestAppState extends State<DriverTestApp> {
),
Row(
children: <Widget>[
const Expanded(
child: Text('hit testability'),
),
const Expanded(child: Text('hit testability')),
DropdownButton<Letter>(
key: const ValueKey<String>('dropdown'),
value: _selectedValue,
@@ -81,9 +72,7 @@ class DriverTestAppState extends State<DriverTestApp> {
),
],
),
const TextField(
key: ValueKey<String>('enter-text-field'),
),
const TextField(key: ValueKey<String>('enter-text-field')),
],
),
),

View File

@@ -18,16 +18,16 @@ void main() {
completer.complete(timings);
});
runApp(Directionality(
textDirection: TextDirection.ltr,
child: _FirstFrameTimings(completer: completer),
));
runApp(
Directionality(
textDirection: TextDirection.ltr,
child: _FirstFrameTimings(completer: completer),
),
);
}
class _FirstFrameTimings extends StatefulWidget {
const _FirstFrameTimings({
required this.completer,
});
const _FirstFrameTimings({required this.completer});
final Completer<List<FrameTiming>> completer;
@@ -42,19 +42,14 @@ class _FirstFrameTimingsState extends State<_FirstFrameTimings> {
Widget build(BuildContext context) {
widget.completer.future.then(_setMinFrameNumber);
if (_minFrameNumber != null) {
return Text(
_minFrameNumber.toString(),
key: const Key('minFrameNumber'),
);
return Text(_minFrameNumber.toString(), key: const Key('minFrameNumber'));
} else {
return const Text('Waiting...');
}
}
void _setMinFrameNumber(List<FrameTiming> timings) {
final int minFrameNumber = timings
.map((FrameTiming timing) => timing.frameNumber)
.reduce(min);
final int minFrameNumber = timings.map((FrameTiming timing) => timing.frameNumber).reduce(min);
setState(() {
_minFrameNumber = minFrameNumber;
});

View File

@@ -8,10 +8,12 @@ import 'package:flutter_driver/driver_extension.dart';
import 'keys.dart' as keys;
void main() {
enableFlutterDriverExtension(handler: (String? message) async {
// TODO(cbernaschina): remove when test flakiness is resolved
return 'keyboard_resize';
});
enableFlutterDriverExtension(
handler: (String? message) async {
// TODO(cbernaschina): remove when test flakiness is resolved
return 'keyboard_resize';
},
);
runApp(const MyApp());
}
@@ -52,15 +54,19 @@ class _MyHomePageState extends State<MyHomePage> {
children: <Widget>[
LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return Center(child: Text('${constraints.biggest.height}', key: const Key(keys.kHeightText)));
}
return Center(
child: Text('${constraints.biggest.height}', key: const Key(keys.kHeightText)),
);
},
),
textField,
],
),
floatingActionButton: FloatingActionButton(
key: const Key(keys.kUnfocusButton),
onPressed: () { textField.focusNode!.unfocus(); },
onPressed: () {
textField.focusNode!.unfocus();
},
tooltip: 'Unfocus',
child: const Icon(Icons.done),
),

View File

@@ -59,24 +59,16 @@ class _MyHomePageState extends State<MyHomePage> {
return Scaffold(
body: Column(
children: <Widget>[
Text('$offset',
key: const ValueKey<String>(keys.kOffsetText),
),
if (isSoftKeyboardVisible) const Text(
'keyboard visible',
key: ValueKey<String>(keys.kKeyboardVisibleView),
),
Text('$offset', key: const ValueKey<String>(keys.kOffsetText)),
if (isSoftKeyboardVisible)
const Text('keyboard visible', key: ValueKey<String>(keys.kKeyboardVisibleView)),
Expanded(
child: ListView(
key: const ValueKey<String>(keys.kListView),
controller: _controller,
children: <Widget>[
Container(
height: MediaQuery.of(context).size.height,
),
const TextField(
key: ValueKey<String>(keys.kDefaultTextField),
),
Container(height: MediaQuery.of(context).size.height),
const TextField(key: ValueKey<String>(keys.kDefaultTextField)),
],
),
),

View File

@@ -16,11 +16,8 @@ void main() {
class ShowLicenses extends StatelessWidget {
const ShowLicenses({super.key});
Widget _buildTestResultWidget(
BuildContext context,
AsyncSnapshot<List<LicenseEntry>> snapshot,
) {
final List<LicenseEntry> entries = snapshot.data ?? <LicenseEntry>[];
Widget _buildTestResultWidget(BuildContext context, AsyncSnapshot<List<LicenseEntry>> snapshot) {
final List<LicenseEntry> entries = snapshot.data ?? <LicenseEntry>[];
String flutterPackage = '';
final List<String> flutterParagraphs = <String>[];
String enginePackage = '';
@@ -34,9 +31,7 @@ class ShowLicenses extends StatelessWidget {
}
if (entry.packages.contains('engine')) {
enginePackage = 'engine';
engineParagraphs.addAll(
entry.paragraphs.map<String>((LicenseParagraph para) => para.text),
);
engineParagraphs.addAll(entry.paragraphs.map<String>((LicenseParagraph para) => para.text));
}
}
@@ -51,9 +46,7 @@ class ShowLicenses extends StatelessWidget {
Text('${engineParagraphs.length}', key: const ValueKey<String>('EngineCount')),
]);
return ListView(
children: result,
);
return ListView(children: result);
}
@override

View File

@@ -8,35 +8,31 @@ import 'package:flutter_driver/driver_extension.dart';
void main() {
enableFlutterDriverExtension();
runApp(MaterialApp(
home: Material(
child: Builder(
builder: (BuildContext context) {
return TextButton(
child: const Text(
'flutter drive lib/xxx.dart',
textDirection: TextDirection.ltr,
),
onPressed: () {
Navigator.push<Object?>(
context,
MaterialPageRoute<Object?>(
builder: (BuildContext context) {
return const Material(
child: Center(
child: Text(
'navigated here',
textDirection: TextDirection.ltr,
runApp(
MaterialApp(
home: Material(
child: Builder(
builder: (BuildContext context) {
return TextButton(
child: const Text('flutter drive lib/xxx.dart', textDirection: TextDirection.ltr),
onPressed: () {
Navigator.push<Object?>(
context,
MaterialPageRoute<Object?>(
builder: (BuildContext context) {
return const Material(
child: Center(
child: Text('navigated here', textDirection: TextDirection.ltr),
),
),
);
},
),
);
},
);
},
);
},
),
);
},
);
},
),
),
),
));
);
}

View File

@@ -9,7 +9,7 @@ void main() {
}
class Test extends StatefulWidget {
const Test({ super.key });
const Test({super.key});
@override
State<Test> createState() => _TestState();
@@ -29,14 +29,16 @@ class _TestState extends State<Test> {
if (!_triggered) {
return const SizedBox.shrink();
}
return const Row(children: <Widget>[
SizedBox(width: 10000.0),
SizedBox(width: 10000.0),
SizedBox(width: 10000.0),
SizedBox(width: 10000.0),
SizedBox(width: 10000.0),
SizedBox(width: 10000.0),
SizedBox(width: 10000.0),
]);
return const Row(
children: <Widget>[
SizedBox(width: 10000.0),
SizedBox(width: 10000.0),
SizedBox(width: 10000.0),
SizedBox(width: 10000.0),
SizedBox(width: 10000.0),
SizedBox(width: 10000.0),
SizedBox(width: 10000.0),
],
);
}
}

View File

@@ -17,17 +17,13 @@ class ResizeApp extends StatefulWidget {
static const Key widthLabel = Key('width label');
static const Key extendedFab = Key('extended FAB');
static const MethodChannel platform =
MethodChannel('samples.flutter.dev/resize');
static const MethodChannel platform = MethodChannel('samples.flutter.dev/resize');
static Future<void> resize(Size size) async {
await ResizeApp.platform.invokeMethod<void>(
'resize',
<String, dynamic>{
'width': size.width,
'height': size.height,
}
);
await ResizeApp.platform.invokeMethod<void>('resize', <String, dynamic>{
'width': size.width,
'height': size.height,
});
}
@override
@@ -57,19 +53,13 @@ class _ResizeAppState extends State<ResizeApp> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
key: ResizeApp.widthLabel,
'width: ${currentSize.width}'
),
Text(
key: ResizeApp.heightLabel,
'height: ${currentSize.height}',
),
Text(key: ResizeApp.widthLabel, 'width: ${currentSize.width}'),
Text(key: ResizeApp.heightLabel, 'height: ${currentSize.height}'),
],
),
),
);
}
},
),
);
}

View File

@@ -9,7 +9,9 @@ import 'package:flutter_driver/driver_extension.dart';
// To use this test: "flutter drive --route '/smuggle-it' lib/route.dart"
void main() {
enableFlutterDriverExtension(handler: (String? message) async {
return ui.PlatformDispatcher.instance.defaultRouteName;
});
enableFlutterDriverExtension(
handler: (String? message) async {
return ui.PlatformDispatcher.instance.defaultRouteName;
},
);
}

View File

@@ -29,9 +29,7 @@ class TogglerState extends State<Toggler> {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('FlutterDriver test'),
),
appBar: AppBar(title: const Text('FlutterDriver test')),
body: Material(
child: Column(
children: <Widget>[
@@ -44,11 +42,7 @@ class TogglerState extends State<Toggler> {
});
},
),
Expanded(
child: ListView(
children: _buildRows(_visible ? 10 : 0),
),
),
Expanded(child: ListView(children: _buildRows(_visible ? 10 : 0))),
],
),
),
@@ -59,9 +53,7 @@ class TogglerState extends State<Toggler> {
List<Widget> _buildRows(int count) {
return List<Widget>.generate(count, (int i) {
return Row(
children: _buildCells(i / count),
);
return Row(children: _buildCells(i / count));
});
}

View File

@@ -8,7 +8,5 @@ import 'package:flutter_driver/driver_extension.dart';
void main() {
enableFlutterDriverExtension();
runApp(Container(
color: const Color(0xFFFF0000),
));
runApp(Container(color: const Color(0xFFFF0000)));
}

View File

@@ -5,11 +5,12 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
// Regression test for https://github.com/flutter/flutter/issues/111285
void main() {
testWidgets('Can load asset from same package without error', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(home: Scaffold(body: Image.asset('assets/foo.png', package: 'integration_ui'))));
await tester.pumpWidget(
MaterialApp(home: Scaffold(body: Image.asset('assets/foo.png', package: 'integration_ui'))),
);
await tester.pumpAndSettle();
// If this asset couldn't be loaded, the exception message would be

View File

@@ -28,21 +28,25 @@ void main() {
test('waitForAbsent should time out waiting for text "present" to disappear', () async {
await expectLater(
() => driver.waitForAbsent(presentText, timeout: const Duration(seconds: 1)),
throwsA(isA<DriverError>().having(
(DriverError error) => error.message,
'message',
contains('Timeout while executing waitForAbsent'),
)),
throwsA(
isA<DriverError>().having(
(DriverError error) => error.message,
'message',
contains('Timeout while executing waitForAbsent'),
),
),
);
}, timeout: Timeout.none);
test('waitForAbsent should resolve when text "present" disappears', () async {
// Begin waiting for it to disappear
final Completer<void> whenWaitForAbsentResolves = Completer<void>();
driver.waitForAbsent(presentText).then(
whenWaitForAbsentResolves.complete,
onError: whenWaitForAbsentResolves.completeError,
);
driver
.waitForAbsent(presentText)
.then(
whenWaitForAbsentResolves.complete,
onError: whenWaitForAbsentResolves.completeError,
);
// Wait 1 second then make it disappear
await Future<void>.delayed(const Duration(seconds: 1));
@@ -55,21 +59,22 @@ void main() {
test('waitFor times out waiting for "present" to reappear', () async {
await expectLater(
() => driver.waitFor(presentText, timeout: const Duration(seconds: 1)),
throwsA(isA<DriverError>().having(
(DriverError error) => error.message,
'message',
contains('Timeout while executing waitFor'),
)),
throwsA(
isA<DriverError>().having(
(DriverError error) => error.message,
'message',
contains('Timeout while executing waitFor'),
),
),
);
}, timeout: Timeout.none);
test('waitFor should resolve when text "present" reappears', () async {
// Begin waiting for it to reappear
final Completer<void> whenWaitForResolves = Completer<void>();
driver.waitFor(presentText).then(
whenWaitForResolves.complete,
onError: whenWaitForResolves.completeError,
);
driver
.waitFor(presentText)
.then(whenWaitForResolves.complete, onError: whenWaitForResolves.completeError);
// Wait 1 second then make it appear
await Future<void>.delayed(const Duration(seconds: 1));

View File

@@ -23,12 +23,8 @@ void main() {
});
test('minFrameNumber is numeric', () async {
final SerializableFinder minFrameNumberFinder =
find.byValueKey('minFrameNumber');
await driver.waitFor(
minFrameNumberFinder,
timeout: const Duration(seconds: 5),
);
final SerializableFinder minFrameNumberFinder = find.byValueKey('minFrameNumber');
await driver.waitFor(minFrameNumberFinder, timeout: const Duration(seconds: 5));
final String minFrameNumber = await driver.getText(minFrameNumberFinder);
// TODO(iskakaushik): enable the stronger check of _minFrameNumber == '1',
// once this is fixed. https://github.com/flutter/flutter/issues/86487

View File

@@ -24,7 +24,9 @@ void main() {
final SerializableFinder listViewFinder = find.byValueKey(keys.kListView);
final SerializableFinder textFieldFinder = find.byValueKey(keys.kDefaultTextField);
final SerializableFinder offsetFinder = find.byValueKey(keys.kOffsetText);
final SerializableFinder keyboardVisibilityIndicatorFinder = find.byValueKey(keys.kKeyboardVisibleView);
final SerializableFinder keyboardVisibilityIndicatorFinder = find.byValueKey(
keys.kKeyboardVisibleView,
);
// Align TextField with bottom edge to ensure it would be covered when keyboard comes up.
await driver.waitForAbsent(textFieldFinder);

View File

@@ -17,7 +17,8 @@ void main() {
test('Can render solid red', () async {
// RGBA Encoded Bytes.
final Uint8List data = (await driver.screenshot(format: ScreenshotFormat.rawStraightRgba)) as Uint8List;
final Uint8List data =
(await driver.screenshot(format: ScreenshotFormat.rawStraightRgba)) as Uint8List;
expect(data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3], 0xFF0000FF);
}, timeout: Timeout.none);