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

@@ -26,7 +26,7 @@ class Home extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
children: _allPages.map((PageWidget p) => _buildPageListTile(context, p)).toList(),
children: _allPages.map((PageWidget p) => _buildPageListTile(context, p)).toList(),
),
);
}
@@ -35,14 +35,13 @@ class Home extends StatelessWidget {
return ListTile(
title: Text(page.title),
key: page.tileKey,
onTap: () { _pushPage(context, page); },
onTap: () {
_pushPage(context, page);
},
);
}
void _pushPage(BuildContext context, PageWidget page) {
Navigator.of(context).push(MaterialPageRoute<void>(
builder: (_) => Scaffold(
body: page,
)));
Navigator.of(context).push(MaterialPageRoute<void>(builder: (_) => Scaffold(body: page)));
}
}

View File

@@ -15,20 +15,22 @@ const List<int> kPointerActions = <int>[
const double kDoubleErrorMargin = 1e-4;
String diffMotionEvents(
Map<String, dynamic> originalEvent,
Map<String, dynamic> synthesizedEvent,
) {
String diffMotionEvents(Map<String, dynamic> originalEvent, Map<String, dynamic> synthesizedEvent) {
final StringBuffer diff = StringBuffer();
diffMaps(originalEvent, synthesizedEvent, diff, excludeKeys: const <String>[
'pointerProperties', // Compared separately.
'pointerCoords', // Compared separately.
'source', // Unused by Flutter.
'deviceId', // Android documentation says that's an arbitrary number that shouldn't be depended on.
'action', // Compared separately.
'motionEventId', // TODO(kaushikiska): add support for motion event diffing, https://github.com/flutter/flutter/issues/61022.
]);
diffMaps(
originalEvent,
synthesizedEvent,
diff,
excludeKeys: const <String>[
'pointerProperties', // Compared separately.
'pointerCoords', // Compared separately.
'source', // Unused by Flutter.
'deviceId', // Android documentation says that's an arbitrary number that shouldn't be depended on.
'action', // Compared separately.
'motionEventId', // TODO(kaushikiska): add support for motion event diffing, https://github.com/flutter/flutter/issues/61022.
],
);
diffActions(diff, originalEvent, synthesizedEvent);
diffPointerProperties(diff, originalEvent, synthesizedEvent);
@@ -37,19 +39,24 @@ String diffMotionEvents(
return diff.toString();
}
void diffActions(StringBuffer diffBuffer, Map<String, dynamic> originalEvent,
Map<String, dynamic> synthesizedEvent) {
final int synthesizedActionMasked =
getActionMasked(synthesizedEvent['action'] as int);
void diffActions(
StringBuffer diffBuffer,
Map<String, dynamic> originalEvent,
Map<String, dynamic> synthesizedEvent,
) {
final int synthesizedActionMasked = getActionMasked(synthesizedEvent['action'] as int);
final int originalActionMasked = getActionMasked(originalEvent['action'] as int);
final String synthesizedActionName =
getActionName(synthesizedActionMasked, synthesizedEvent['action'] as int);
final String originalActionName =
getActionName(originalActionMasked, originalEvent['action'] as int);
final String synthesizedActionName = getActionName(
synthesizedActionMasked,
synthesizedEvent['action'] as int,
);
final String originalActionName = getActionName(
originalActionMasked,
originalEvent['action'] as int,
);
if (synthesizedActionMasked != originalActionMasked) {
diffBuffer.write(
'action (expected: $originalActionName actual: $synthesizedActionName) ');
diffBuffer.write('action (expected: $originalActionName actual: $synthesizedActionName) ');
}
if (kPointerActions.contains(originalActionMasked) &&
@@ -58,13 +65,17 @@ void diffActions(StringBuffer diffBuffer, Map<String, dynamic> originalEvent,
final int synthesizedPointer = getPointerIdx(synthesizedEvent['action'] as int);
if (originalPointer != synthesizedPointer) {
diffBuffer.write(
'pointerIdx (expected: $originalPointer actual: $synthesizedPointer action: $originalActionName ');
'pointerIdx (expected: $originalPointer actual: $synthesizedPointer action: $originalActionName ',
);
}
}
}
void diffPointerProperties(StringBuffer diffBuffer,
Map<String, dynamic> originalEvent, Map<String, dynamic> synthesizedEvent) {
void diffPointerProperties(
StringBuffer diffBuffer,
Map<String, dynamic> originalEvent,
Map<String, dynamic> synthesizedEvent,
) {
final List<Map<dynamic, dynamic>> expectedList =
(originalEvent['pointerProperties'] as List<dynamic>).cast<Map<dynamic, dynamic>>();
final List<Map<dynamic, dynamic>> actualList =
@@ -72,21 +83,23 @@ void diffPointerProperties(StringBuffer diffBuffer,
if (expectedList.length != actualList.length) {
diffBuffer.write(
'pointerProperties (actual length: ${actualList.length}, expected length: ${expectedList.length} ');
'pointerProperties (actual length: ${actualList.length}, expected length: ${expectedList.length} ',
);
return;
}
for (int i = 0; i < expectedList.length; i++) {
final Map<String, dynamic> expected =
expectedList[i].cast<String, dynamic>();
final Map<String, dynamic> expected = expectedList[i].cast<String, dynamic>();
final Map<String, dynamic> actual = actualList[i].cast<String, dynamic>();
diffMaps(expected, actual, diffBuffer,
messagePrefix: '[pointerProperty $i] ');
diffMaps(expected, actual, diffBuffer, messagePrefix: '[pointerProperty $i] ');
}
}
void diffPointerCoordsList(StringBuffer diffBuffer,
Map<String, dynamic> originalEvent, Map<String, dynamic> synthesizedEvent) {
void diffPointerCoordsList(
StringBuffer diffBuffer,
Map<String, dynamic> originalEvent,
Map<String, dynamic> synthesizedEvent,
) {
final List<Map<dynamic, dynamic>> expectedList =
(originalEvent['pointerCoords'] as List<dynamic>).cast<Map<dynamic, dynamic>>();
final List<Map<dynamic, dynamic>> actualList =
@@ -94,20 +107,24 @@ void diffPointerCoordsList(StringBuffer diffBuffer,
if (expectedList.length != actualList.length) {
diffBuffer.write(
'pointerCoords (actual length: ${actualList.length}, expected length: ${expectedList.length} ');
'pointerCoords (actual length: ${actualList.length}, expected length: ${expectedList.length} ',
);
return;
}
for (int i = 0; i < expectedList.length; i++) {
final Map<String, dynamic> expected =
expectedList[i].cast<String, dynamic>();
final Map<String, dynamic> expected = expectedList[i].cast<String, dynamic>();
final Map<String, dynamic> actual = actualList[i].cast<String, dynamic>();
diffPointerCoords(expected, actual, i, diffBuffer);
}
}
void diffPointerCoords(Map<String, dynamic> expected,
Map<String, dynamic> actual, int pointerIdx, StringBuffer diffBuffer) {
void diffPointerCoords(
Map<String, dynamic> expected,
Map<String, dynamic> actual,
int pointerIdx,
StringBuffer diffBuffer,
) {
diffMaps(expected, actual, diffBuffer, messagePrefix: '[pointerCoord $pointerIdx] ');
}
@@ -120,8 +137,7 @@ void diffMaps(
}) {
const IterableEquality<String> eq = IterableEquality<String>();
if (!eq.equals(expected.keys, actual.keys)) {
diffBuffer.write(
'${messagePrefix}keys (expected: ${expected.keys} actual: ${actual.keys} ');
diffBuffer.write('${messagePrefix}keys (expected: ${expected.keys} actual: ${actual.keys} ');
return;
}
for (final String key in expected.keys) {
@@ -133,8 +149,7 @@ void diffMaps(
}
if (expected[key] != actual[key]) {
diffBuffer.write(
'$messagePrefix$key (expected: ${expected[key]} actual: ${actual[key]}) ');
diffBuffer.write('$messagePrefix$key (expected: ${expected[key]} actual: ${actual[key]}) ');
}
}
}

View File

@@ -19,7 +19,7 @@ const String kEventsFileName = 'touchEvents';
class MotionEventsPage extends PageWidget {
const MotionEventsPage({Key? key})
: super('Motion Event Tests', const ValueKey<String>('MotionEventsListTile'), key: key);
: super('Motion Event Tests', const ValueKey<String>('MotionEventsListTile'), key: key);
@override
Widget build(BuildContext context) {
@@ -68,15 +68,13 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
SizedBox(
height: 300.0,
child: AndroidView(
key: const ValueKey<String>('PlatformView'),
viewType: 'simple_view',
onPlatformViewCreated: onPlatformViewCreated),
key: const ValueKey<String>('PlatformView'),
viewType: 'simple_view',
onPlatformViewCreated: onPlatformViewCreated,
),
),
Expanded(
child: ListView.builder(
itemBuilder: buildEventTile,
itemCount: flutterViewEvents.length,
),
child: ListView.builder(itemBuilder: buildEventTile, itemCount: flutterViewEvents.length),
),
Row(
children: <Widget>[
@@ -102,8 +100,7 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
child: const Text('SAVE'),
onPressed: () {
const StandardMessageCodec codec = StandardMessageCodec();
saveRecordedEvents(
codec.encodeMessage(flutterViewEvents)!, context);
saveRecordedEvents(codec.encodeMessage(flutterViewEvents)!, context);
},
),
),
@@ -111,14 +108,18 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
child: ElevatedButton(
key: const ValueKey<String>('play'),
child: const Text('PLAY FILE'),
onPressed: () { playEventsFile(); },
onPressed: () {
playEventsFile();
},
),
),
Expanded(
child: ElevatedButton(
key: const ValueKey<String>('back'),
child: const Text('BACK'),
onPressed: () { Navigator.pop(context); },
onPressed: () {
Navigator.pop(context);
},
),
),
],
@@ -130,12 +131,15 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
Future<String> playEventsFile() async {
const StandardMessageCodec codec = StandardMessageCodec();
try {
final ByteData data = await rootBundle.load('packages/assets_for_android_views/assets/touchEvents');
final ByteData data = await rootBundle.load(
'packages/assets_for_android_views/assets/touchEvents',
);
final List<dynamic> unTypedRecordedEvents = codec.decodeMessage(data) as List<dynamic>;
final List<Map<String, dynamic>> recordedEvents = unTypedRecordedEvents
.cast<Map<dynamic, dynamic>>()
.map<Map<String, dynamic>>((Map<dynamic, dynamic> e) =>e.cast<String, dynamic>())
.toList();
final List<Map<String, dynamic>> recordedEvents =
unTypedRecordedEvents
.cast<Map<dynamic, dynamic>>()
.map<Map<String, dynamic>>((Map<dynamic, dynamic> e) => e.cast<String, dynamic>())
.toList();
await channel.invokeMethod<void>('pipeFlutterViewEvents');
await viewChannel?.invokeMethod<void>('pipeTouchEvents');
print('replaying ${recordedEvents.length} motion events');
@@ -198,10 +202,9 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
}
void showMessage(BuildContext context, String message) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text(message),
duration: const Duration(seconds: 3),
));
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(message), duration: const Duration(seconds: 3)));
}
void onPlatformViewCreated(int id) {
@@ -255,11 +258,9 @@ class MotionEventsBodyState extends State<MotionEventsBody> {
Widget buildEventTile(BuildContext context, int index) {
if (embeddedViewEvents.length > index) {
return TouchEventDiff(
flutterViewEvents[index], embeddedViewEvents[index]);
return TouchEventDiff(flutterViewEvents[index], embeddedViewEvents[index]);
}
return Text(
'Unmatched event, action: ${flutterViewEvents[index]['action']}');
return Text('Unmatched event, action: ${flutterViewEvents[index]['action']}');
}
}
@@ -271,7 +272,6 @@ class TouchEventDiff extends StatelessWidget {
@override
Widget build(BuildContext context) {
Color color;
final String diff = diffMotionEvents(originalEvent, synthesizedEvent);
String msg;
@@ -291,11 +291,7 @@ class TouchEventDiff extends StatelessWidget {
print('\nactual:');
prettyPrintEvent(synthesizedEvent);
},
child: Container(
color: color,
margin: const EdgeInsets.only(bottom: 2.0),
child: Text(msg),
),
child: Container(color: color, margin: const EdgeInsets.only(bottom: 2.0), child: Text(msg)),
);
}
@@ -307,12 +303,15 @@ class TouchEventDiff extends StatelessWidget {
buffer.write('$actionName ');
if (maskedAction == 5 || maskedAction == 6) {
buffer.write('pointer: ${getPointerIdx(action)} ');
buffer.write('pointer: ${getPointerIdx(action)} ');
}
final List<Map<dynamic, dynamic>> coords = (event['pointerCoords'] as List<dynamic>).cast<Map<dynamic, dynamic>>();
final List<Map<dynamic, dynamic>> coords =
(event['pointerCoords'] as List<dynamic>).cast<Map<dynamic, dynamic>>();
for (int i = 0; i < coords.length; i++) {
buffer.write('p$i x: ${coords[i]['x']} y: ${coords[i]['y']}, pressure: ${coords[i]['pressure']} ');
buffer.write(
'p$i x: ${coords[i]['x']} y: ${coords[i]['y']}, pressure: ${coords[i]['pressure']} ',
);
}
print(buffer);
}

View File

@@ -11,7 +11,11 @@ import 'page.dart';
class WindowManagerIntegrationsPage extends PageWidget {
const WindowManagerIntegrationsPage({Key? key})
: super('Window Manager Integrations Tests', const ValueKey<String>('WmIntegrationsListTile'), key: key);
: super(
'Window Manager Integrations Tests',
const ValueKey<String>('WmIntegrationsListTile'),
key: key,
);
@override
Widget build(BuildContext context) => const WindowManagerBody();
@@ -24,14 +28,9 @@ class WindowManagerBody extends StatefulWidget {
State<WindowManagerBody> createState() => WindowManagerBodyState();
}
enum _LastTestStatus {
pending,
success,
error
}
enum _LastTestStatus { pending, success, error }
class WindowManagerBodyState extends State<WindowManagerBody> {
MethodChannel? viewChannel;
_LastTestStatus _lastTestStatus = _LastTestStatus.pending;
String? lastError;
@@ -41,9 +40,7 @@ class WindowManagerBodyState extends State<WindowManagerBody> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Window Manager Integrations'),
),
appBar: AppBar(title: const Text('Window Manager Integrations')),
body: Column(
children: <Widget>[
SizedBox(
@@ -54,7 +51,7 @@ class WindowManagerBodyState extends State<WindowManagerBody> {
),
),
if (_lastTestStatus != _LastTestStatus.pending) _statusWidget(),
if (viewChannel != null) ... <Widget>[
if (viewChannel != null) ...<Widget>[
ElevatedButton(
key: const ValueKey<String>('ShowAlertDialog'),
onPressed: onShowAlertDialogPressed,
@@ -74,8 +71,8 @@ class WindowManagerBodyState extends State<WindowManagerBody> {
),
if (windowClickCount > 0)
Text(
'Click count: $windowClickCount',
key: const ValueKey<String>('WindowClickCount'),
'Click count: $windowClickCount',
key: const ValueKey<String>('WindowClickCount'),
),
],
),
@@ -93,9 +90,7 @@ class WindowManagerBodyState extends State<WindowManagerBody> {
child: Text(
message!,
key: const ValueKey<String>('Status'),
style: TextStyle(
color: _lastTestStatus == _LastTestStatus.error ? Colors.yellow : null,
),
style: TextStyle(color: _lastTestStatus == _LastTestStatus.error ? Colors.yellow : null),
),
);
}
@@ -152,5 +147,4 @@ class WindowManagerBodyState extends State<WindowManagerBody> {
viewChannel = MethodChannel('simple_view/$id');
});
}
}

View File

@@ -19,8 +19,7 @@ Future<void> main() async {
// Each test below must return back to the home page after finishing.
test('MotionEvent recomposition', () async {
final SerializableFinder motionEventsListTile =
find.byValueKey('MotionEventsListTile');
final SerializableFinder motionEventsListTile = find.byValueKey('MotionEventsListTile');
await driver?.tap(motionEventsListTile);
await driver?.runUnsynchronized(() async {
driver?.waitFor(find.byValueKey('PlatformView'));
@@ -31,11 +30,9 @@ Future<void> main() async {
await driver?.tap(backButton);
}, timeout: Timeout.none);
group('WindowManager', ()
{
group('WindowManager', () {
setUpAll(() async {
final SerializableFinder wmListTile =
find.byValueKey('WmIntegrationsListTile');
final SerializableFinder wmListTile = find.byValueKey('WmIntegrationsListTile');
await driver?.tap(wmListTile);
});
@@ -45,24 +42,28 @@ Future<void> main() async {
});
test('AlertDialog from platform view context', () async {
final SerializableFinder showAlertDialog = find.byValueKey(
'ShowAlertDialog');
final SerializableFinder showAlertDialog = find.byValueKey('ShowAlertDialog');
await driver?.waitFor(showAlertDialog);
await driver?.tap(showAlertDialog);
final String status = (await driver?.getText(find.byValueKey('Status')))!;
expect(status, 'Success');
}, timeout: Timeout.none);
test('Child windows can handle touches', () async {
final SerializableFinder addWindow = find.byValueKey('AddWindow');
await driver?.waitFor(addWindow);
await driver?.tap(addWindow);
final SerializableFinder tapWindow = find.byValueKey('TapWindow');
await driver?.tap(tapWindow);
final String windowClickCount = (await driver?.getText(
find.byValueKey('WindowClickCount'),
))!;
expect(windowClickCount, 'Click count: 1');
}, timeout: Timeout.none, skip: true); // TODO(garyq): Skipped, see https://github.com/flutter/flutter/issues/88479
test(
'Child windows can handle touches',
() async {
final SerializableFinder addWindow = find.byValueKey('AddWindow');
await driver?.waitFor(addWindow);
await driver?.tap(addWindow);
final SerializableFinder tapWindow = find.byValueKey('TapWindow');
await driver?.tap(tapWindow);
final String windowClickCount =
(await driver?.getText(find.byValueKey('WindowClickCount')))!;
expect(windowClickCount, 'Click count: 1');
},
timeout: Timeout.none,
// TODO(garyq): Skipped, see https://github.com/flutter/flutter/issues/88479
skip: true,
);
});
}