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

@@ -6,7 +6,5 @@ import 'package:flutter/widgets.dart';
import 'src/app.dart';
void main() {
runApp(
const ComplexLayoutApp()
);
runApp(const ComplexLayoutApp());
}

View File

@@ -6,7 +6,5 @@ import 'package:flutter/widgets.dart';
import 'src/app.dart';
void main() {
runApp(
const ComplexLayoutApp(badScroll: true)
);
runApp(const ComplexLayoutApp(badScroll: true));
}

View File

@@ -15,7 +15,8 @@ class ComplexLayoutApp extends StatefulWidget {
@override
ComplexLayoutAppState createState() => ComplexLayoutAppState();
static ComplexLayoutAppState? of(BuildContext context) => context.findAncestorStateOfType<ComplexLayoutAppState>();
static ComplexLayoutAppState? of(BuildContext context) =>
context.findAncestorStateOfType<ComplexLayoutAppState>();
}
class ComplexLayoutAppState extends State<ComplexLayoutApp> {
@@ -24,7 +25,11 @@ class ComplexLayoutAppState extends State<ComplexLayoutApp> {
return MaterialApp(
theme: lightTheme ? ThemeData.light() : ThemeData.dark(),
title: 'Advanced Layout',
home: scrollMode == ScrollMode.complex ? ComplexLayout(badScroll: widget.badScroll) : const TileScrollLayout());
home:
scrollMode == ScrollMode.complex
? ComplexLayout(badScroll: widget.badScroll)
: const TileScrollLayout(),
);
}
bool _lightTheme = true;
@@ -51,7 +56,7 @@ class ComplexLayoutAppState extends State<ComplexLayoutApp> {
}
class TileScrollLayout extends StatelessWidget {
const TileScrollLayout({ super.key });
const TileScrollLayout({super.key});
@override
Widget build(BuildContext context) {
@@ -77,14 +82,15 @@ class TileScrollLayout extends StatelessWidget {
}
class ComplexLayout extends StatefulWidget {
const ComplexLayout({ super.key, required this.badScroll });
const ComplexLayout({super.key, required this.badScroll});
final bool badScroll;
@override
ComplexLayoutState createState() => ComplexLayoutState();
static ComplexLayoutState? of(BuildContext context) => context.findAncestorStateOfType<ComplexLayoutState>();
static ComplexLayoutState? of(BuildContext context) =>
context.findAncestorStateOfType<ComplexLayoutState>();
}
class ComplexLayoutState extends State<ComplexLayout> {
@@ -92,7 +98,7 @@ class ComplexLayoutState extends State<ComplexLayout> {
Widget build(BuildContext context) {
Widget body = ListView.builder(
key: const Key('complex-scroll'), // this key is used by the driver test
controller: ScrollController(), // So that the scroll offset can be tracked
controller: ScrollController(), // So that the scroll offset can be tracked
itemCount: widget.badScroll ? 500 : null,
shrinkWrap: widget.badScroll,
itemBuilder: (BuildContext context, int index) {
@@ -104,10 +110,7 @@ class ComplexLayoutState extends State<ComplexLayout> {
},
);
if (widget.badScroll) {
body = ListView(
key: const Key('complex-scroll-bad'),
children: <Widget>[body],
);
body = ListView(key: const Key('complex-scroll-bad'), children: <Widget>[body]);
}
return Scaffold(
@@ -124,12 +127,7 @@ class ComplexLayoutState extends State<ComplexLayout> {
const TopBarMenu(),
],
),
body: Column(
children: <Widget>[
Expanded(child: body),
const BottomBar(),
],
),
body: Column(children: <Widget>[Expanded(child: body), const BottomBar()]),
drawer: const GalleryDrawer(),
);
}
@@ -141,49 +139,52 @@ class TopBarMenu extends StatelessWidget {
@override
Widget build(BuildContext context) {
return PopupMenuButton<String>(
onSelected: (String value) { print('Selected: $value'); },
itemBuilder: (BuildContext context) => <PopupMenuItem<String>>[
const PopupMenuItem<String>(
value: 'Friends',
child: MenuItemWithIcon(Icons.people, 'Friends', '5 new'),
),
const PopupMenuItem<String>(
value: 'Events',
child: MenuItemWithIcon(Icons.event, 'Events', '12 upcoming'),
),
const PopupMenuItem<String>(
value: 'Events',
child: MenuItemWithIcon(Icons.group, 'Groups', '14'),
),
const PopupMenuItem<String>(
value: 'Events',
child: MenuItemWithIcon(Icons.image, 'Pictures', '12'),
),
const PopupMenuItem<String>(
value: 'Events',
child: MenuItemWithIcon(Icons.near_me, 'Nearby', '33'),
),
const PopupMenuItem<String>(
value: 'Friends',
child: MenuItemWithIcon(Icons.people, 'Friends', '5'),
),
const PopupMenuItem<String>(
value: 'Events',
child: MenuItemWithIcon(Icons.event, 'Events', '12'),
),
const PopupMenuItem<String>(
value: 'Events',
child: MenuItemWithIcon(Icons.group, 'Groups', '14'),
),
const PopupMenuItem<String>(
value: 'Events',
child: MenuItemWithIcon(Icons.image, 'Pictures', '12'),
),
const PopupMenuItem<String>(
value: 'Events',
child: MenuItemWithIcon(Icons.near_me, 'Nearby', '33'),
),
],
onSelected: (String value) {
print('Selected: $value');
},
itemBuilder:
(BuildContext context) => <PopupMenuItem<String>>[
const PopupMenuItem<String>(
value: 'Friends',
child: MenuItemWithIcon(Icons.people, 'Friends', '5 new'),
),
const PopupMenuItem<String>(
value: 'Events',
child: MenuItemWithIcon(Icons.event, 'Events', '12 upcoming'),
),
const PopupMenuItem<String>(
value: 'Events',
child: MenuItemWithIcon(Icons.group, 'Groups', '14'),
),
const PopupMenuItem<String>(
value: 'Events',
child: MenuItemWithIcon(Icons.image, 'Pictures', '12'),
),
const PopupMenuItem<String>(
value: 'Events',
child: MenuItemWithIcon(Icons.near_me, 'Nearby', '33'),
),
const PopupMenuItem<String>(
value: 'Friends',
child: MenuItemWithIcon(Icons.people, 'Friends', '5'),
),
const PopupMenuItem<String>(
value: 'Events',
child: MenuItemWithIcon(Icons.event, 'Events', '12'),
),
const PopupMenuItem<String>(
value: 'Events',
child: MenuItemWithIcon(Icons.group, 'Groups', '14'),
),
const PopupMenuItem<String>(
value: 'Events',
child: MenuItemWithIcon(Icons.image, 'Pictures', '12'),
),
const PopupMenuItem<String>(
value: 'Events',
child: MenuItemWithIcon(Icons.near_me, 'Nearby', '33'),
),
],
);
}
}
@@ -200,10 +201,7 @@ class MenuItemWithIcon extends StatelessWidget {
return Row(
children: <Widget>[
Icon(icon),
Padding(
padding: const EdgeInsets.only(left: 8.0, right: 8.0),
child: Text(title),
),
Padding(padding: const EdgeInsets.only(left: 8.0, right: 8.0), child: Text(title)),
Text(subtitle, style: Theme.of(context).textTheme.bodySmall),
],
);
@@ -223,10 +221,7 @@ class FancyImageItem extends StatelessWidget {
const ItemDescription(),
const ItemImageBox(),
const InfoBar(),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 8.0),
child: Divider(),
),
const Padding(padding: EdgeInsets.symmetric(horizontal: 8.0), child: Divider()),
const IconBar(),
const FatDivider(),
],
@@ -245,10 +240,7 @@ class FancyGalleryItem extends StatelessWidget {
const UserHeader('Ali Connors'),
ItemGalleryBox(index),
const InfoBar(),
const Padding(
padding: EdgeInsets.symmetric(horizontal: 8.0),
child: Divider(),
),
const Padding(padding: EdgeInsets.symmetric(horizontal: 8.0), child: Divider()),
const IconBar(),
const FatDivider(),
],
@@ -306,7 +298,9 @@ class IconWithText extends StatelessWidget {
children: <Widget>[
IconButton(
icon: Icon(icon),
onPressed: () { print('Pressed $title button'); },
onPressed: () {
print('Pressed $title button');
},
),
Text(title),
],
@@ -348,10 +342,7 @@ class FatDivider extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container(
height: 8.0,
color: Theme.of(context).dividerColor,
);
return Container(height: 8.0, color: Theme.of(context).dividerColor);
}
}
@@ -379,18 +370,24 @@ class UserHeader extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
RichText(text: TextSpan(
style: Theme.of(context).textTheme.bodyMedium,
children: <TextSpan>[
TextSpan(text: userName, style: const TextStyle(fontWeight: FontWeight.bold)),
const TextSpan(text: ' shared a new '),
const TextSpan(text: 'photo', style: TextStyle(fontWeight: FontWeight.bold)),
],
)),
RichText(
text: TextSpan(
style: Theme.of(context).textTheme.bodyMedium,
children: <TextSpan>[
TextSpan(text: userName, style: const TextStyle(fontWeight: FontWeight.bold)),
const TextSpan(text: ' shared a new '),
const TextSpan(text: 'photo', style: TextStyle(fontWeight: FontWeight.bold)),
],
),
),
Row(
children: <Widget>[
Text('Yesterday at 11:55 • ', style: Theme.of(context).textTheme.bodySmall),
Icon(Icons.people, size: 16.0, color: Theme.of(context).textTheme.bodySmall!.color),
Icon(
Icons.people,
size: 16.0,
color: Theme.of(context).textTheme.bodySmall!.color,
),
],
),
],
@@ -410,7 +407,9 @@ class ItemDescription extends StatelessWidget {
Widget build(BuildContext context) {
return const Padding(
padding: EdgeInsets.all(8.0),
child: Text('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'),
child: Text(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
),
);
}
}
@@ -431,7 +430,9 @@ class ItemImageBox extends StatelessWidget {
const SizedBox(
height: 230.0,
child: Image(
image: AssetImage('packages/flutter_gallery_assets/places/india_chettinad_silk_maker.png')
image: AssetImage(
'packages/flutter_gallery_assets/places/india_chettinad_silk_maker.png',
),
),
),
Theme(
@@ -441,11 +442,15 @@ class ItemImageBox extends StatelessWidget {
children: <Widget>[
IconButton(
icon: const Icon(Icons.edit),
onPressed: () { print('Pressed edit button'); },
onPressed: () {
print('Pressed edit button');
},
),
IconButton(
icon: const Icon(Icons.zoom_in),
onPressed: () { print('Pressed zoom button'); },
onPressed: () {
print('Pressed zoom button');
},
),
],
),
@@ -463,9 +468,7 @@ class ItemImageBox extends StatelessWidget {
text: const TextSpan(
style: TextStyle(color: Colors.white),
children: <TextSpan>[
TextSpan(
text: 'Photo by '
),
TextSpan(text: 'Photo by '),
TextSpan(
style: TextStyle(fontWeight: FontWeight.bold),
text: 'Chris Godley',
@@ -476,8 +479,7 @@ class ItemImageBox extends StatelessWidget {
),
),
],
)
,
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
@@ -503,9 +505,7 @@ class ItemGalleryBox extends StatelessWidget {
@override
Widget build(BuildContext context) {
final List<String> tabNames = <String>[
'A', 'B', 'C', 'D',
];
final List<String> tabNames = <String>['A', 'B', 'C', 'D'];
return SizedBox(
height: 200.0,
@@ -515,46 +515,56 @@ class ItemGalleryBox extends StatelessWidget {
children: <Widget>[
Expanded(
child: TabBarView(
children: tabNames.map<Widget>((String tabName) {
return Container(
key: PageStorageKey<String>(tabName),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
child: Column(
children: <Widget>[
Expanded(
child: ColoredBox(
color: Theme.of(context).primaryColor,
child: Center(
child: Text(tabName, style: Theme.of(context).textTheme.headlineSmall!.copyWith(color: Colors.white)),
),
),
),
Row(
children:
tabNames.map<Widget>((String tabName) {
return Container(
key: PageStorageKey<String>(tabName),
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Card(
child: Column(
children: <Widget>[
IconButton(
icon: const Icon(Icons.share),
onPressed: () { print('Pressed share'); },
),
IconButton(
icon: const Icon(Icons.event),
onPressed: () { print('Pressed event'); },
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Text('This is item $tabName'),
child: ColoredBox(
color: Theme.of(context).primaryColor,
child: Center(
child: Text(
tabName,
style: Theme.of(
context,
).textTheme.headlineSmall!.copyWith(color: Colors.white),
),
),
),
),
Row(
children: <Widget>[
IconButton(
icon: const Icon(Icons.share),
onPressed: () {
print('Pressed share');
},
),
IconButton(
icon: const Icon(Icons.event),
onPressed: () {
print('Pressed event');
},
),
Expanded(
child: Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Text('This is item $tabName'),
),
),
],
),
],
),
],
),
),
),
),
);
}).toList(),
);
}).toList(),
),
),
const TabPageSelector(),
@@ -572,11 +582,7 @@ class BottomBar extends StatelessWidget {
Widget build(BuildContext context) {
return Container(
decoration: BoxDecoration(
border: Border(
top: BorderSide(
color: Theme.of(context).dividerColor,
),
),
border: Border(top: BorderSide(color: Theme.of(context).dividerColor)),
),
child: const Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -606,7 +612,9 @@ class BottomBarButton extends StatelessWidget {
children: <Widget>[
IconButton(
icon: Icon(icon),
onPressed: () { print('Pressed: $title'); },
onPressed: () {
print('Pressed: $title');
},
),
Text(title, style: Theme.of(context).textTheme.bodySmall),
],
@@ -616,7 +624,7 @@ class BottomBarButton extends StatelessWidget {
}
class GalleryDrawer extends StatelessWidget {
const GalleryDrawer({ super.key });
const GalleryDrawer({super.key});
void _changeTheme(BuildContext context, bool value) {
ComplexLayoutApp.of(context)?.lightTheme = value;
@@ -642,31 +650,42 @@ class GalleryDrawer extends StatelessWidget {
key: const Key('scroll-switcher'),
title: const Text('Scroll Mode'),
onTap: () {
_changeScrollMode(context, currentMode == ScrollMode.complex ? ScrollMode.tile : ScrollMode.complex);
Navigator.pop(context);
_changeScrollMode(
context,
currentMode == ScrollMode.complex ? ScrollMode.tile : ScrollMode.complex,
);
Navigator.pop(context);
},
trailing: Text(currentMode == ScrollMode.complex ? 'Tile' : 'Complex'),
),
ListTile(
leading: const Icon(Icons.brightness_5),
title: const Text('Light'),
onTap: () { _changeTheme(context, true); },
onTap: () {
_changeTheme(context, true);
},
selected: ComplexLayoutApp.of(context)!.lightTheme,
trailing: Radio<bool>(
value: true,
groupValue: ComplexLayoutApp.of(context)!.lightTheme,
onChanged: (bool? value) { _changeTheme(context, value!); },
onChanged: (bool? value) {
_changeTheme(context, value!);
},
),
),
ListTile(
leading: const Icon(Icons.brightness_7),
title: const Text('Dark'),
onTap: () { _changeTheme(context, false); },
onTap: () {
_changeTheme(context, false);
},
selected: !ComplexLayoutApp.of(context)!.lightTheme,
trailing: Radio<bool>(
value: false,
groupValue: ComplexLayoutApp.of(context)!.lightTheme,
onChanged: (bool? value) { _changeTheme(context, value!); },
onChanged: (bool? value) {
_changeTheme(context, value!);
},
),
),
const Divider(),
@@ -674,10 +693,14 @@ class GalleryDrawer extends StatelessWidget {
leading: const Icon(Icons.hourglass_empty),
title: const Text('Animate Slowly'),
selected: timeDilation != 1.0,
onTap: () { ComplexLayoutApp.of(context)!.toggleAnimationSpeed(); },
onTap: () {
ComplexLayoutApp.of(context)!.toggleAnimationSpeed();
},
trailing: Checkbox(
value: timeDilation != 1.0,
onChanged: (bool? value) { ComplexLayoutApp.of(context)!.toggleAnimationSpeed(); },
onChanged: (bool? value) {
ComplexLayoutApp.of(context)!.toggleAnimationSpeed();
},
),
),
],
@@ -694,10 +717,7 @@ class FancyDrawerHeader extends StatelessWidget {
return Container(
color: Colors.purple,
height: 200.0,
child: const SafeArea(
bottom: false,
child: Placeholder(),
),
child: const SafeArea(bottom: false, child: Placeholder()),
);
}
}

View File

@@ -24,17 +24,11 @@ Iterable<PointerEvent> dragInputEvents(
final Offset startLocation = center - totalMove / 2;
// The issue is about 120Hz input on 90Hz refresh rate device.
// We test 90Hz input on 60Hz device here, which shows similar pattern.
final int moveEventCount = totalTime.inMicroseconds * frequency ~/ const Duration(seconds: 1).inMicroseconds;
final int moveEventCount =
totalTime.inMicroseconds * frequency ~/ const Duration(seconds: 1).inMicroseconds;
final Offset movePerEvent = totalMove / moveEventCount.toDouble();
yield PointerAddedEvent(
timeStamp: epoch,
position: startLocation,
);
yield PointerDownEvent(
timeStamp: epoch,
position: startLocation,
pointer: 1,
);
yield PointerAddedEvent(timeStamp: epoch, position: startLocation);
yield PointerDownEvent(timeStamp: epoch, position: startLocation, pointer: 1);
for (int t = 0; t < moveEventCount + 1; t++) {
final Offset position = startLocation + movePerEvent * t.toDouble();
yield PointerMoveEvent(
@@ -45,19 +39,10 @@ Iterable<PointerEvent> dragInputEvents(
);
}
final Offset position = startLocation + totalMove;
yield PointerUpEvent(
timeStamp: epoch + totalTime,
position: position,
pointer: 1,
);
yield PointerUpEvent(timeStamp: epoch + totalTime, position: position, pointer: 1);
}
enum TestScenario {
resampleOn90Hz,
resampleOn59Hz,
resampleOff90Hz,
resampleOff59Hz,
}
enum TestScenario { resampleOn90Hz, resampleOn59Hz, resampleOff90Hz, resampleOff59Hz }
class ResampleFlagVariant extends TestVariant<TestScenario> {
ResampleFlagVariant(this.binding);
@@ -69,7 +54,7 @@ class ResampleFlagVariant extends TestVariant<TestScenario> {
late TestScenario currentValue;
bool get resample => switch (currentValue) {
TestScenario.resampleOn90Hz || TestScenario.resampleOn59Hz => true,
TestScenario.resampleOn90Hz || TestScenario.resampleOn59Hz => true,
TestScenario.resampleOff90Hz || TestScenario.resampleOff59Hz => false,
};
@@ -83,8 +68,8 @@ class ResampleFlagVariant extends TestVariant<TestScenario> {
@override
String describeValue(TestScenario value) {
return switch (value) {
TestScenario.resampleOn90Hz => 'resample on with 90Hz input',
TestScenario.resampleOn59Hz => 'resample on with 59Hz input',
TestScenario.resampleOn90Hz => 'resample on with 90Hz input',
TestScenario.resampleOn59Hz => 'resample on with 59Hz input',
TestScenario.resampleOff90Hz => 'resample off with 90Hz input',
TestScenario.resampleOff59Hz => 'resample off with 59Hz input',
};
@@ -108,61 +93,67 @@ class ResampleFlagVariant extends TestVariant<TestScenario> {
Future<void> main() async {
final WidgetsBinding widgetsBinding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
assert(widgetsBinding is IntegrationTestWidgetsFlutterBinding);
final IntegrationTestWidgetsFlutterBinding binding = widgetsBinding as IntegrationTestWidgetsFlutterBinding;
final IntegrationTestWidgetsFlutterBinding binding =
widgetsBinding as IntegrationTestWidgetsFlutterBinding;
binding.framePolicy = LiveTestWidgetsFlutterBindingFramePolicy.benchmarkLive;
binding.reportData ??= <String, dynamic>{};
final ResampleFlagVariant variant = ResampleFlagVariant(binding);
testWidgets('Smoothness test', (WidgetTester tester) async {
app.main();
await tester.pumpAndSettle();
final Finder scrollerFinder = find.byKey(const ValueKey<String>('complex-scroll'));
final ListView scroller = tester.widget<ListView>(scrollerFinder);
final ScrollController? controller = scroller.controller;
final List<int> frameTimestamp = <int>[];
final List<double> scrollOffset = <double>[];
final List<Duration> delays = <Duration>[];
binding.addPersistentFrameCallback((Duration timeStamp) {
if (controller?.hasClients ?? false) {
// This if is necessary because by the end of the test the widget tree
// is destroyed.
frameTimestamp.add(timeStamp.inMicroseconds);
scrollOffset.add(controller!.offset);
}
});
Duration now() => binding.currentSystemFrameTimeStamp;
Future<void> scroll() async {
// Extra 50ms to avoid timeouts.
final Duration startTime = const Duration(milliseconds: 500) + now();
for (final PointerEvent event in dragInputEvents(
startTime,
tester.getCenter(scrollerFinder),
frequency: variant.frequency,
)) {
await tester.binding.delayed(event.timeStamp - now());
// This now measures how accurate the above delayed is.
final Duration delay = now() - event.timeStamp;
if (delays.length < frameTimestamp.length) {
while (delays.length < frameTimestamp.length - 1) {
delays.add(Duration.zero);
}
delays.add(delay);
} else if (delays.last < delay) {
delays.last = delay;
testWidgets(
'Smoothness test',
(WidgetTester tester) async {
app.main();
await tester.pumpAndSettle();
final Finder scrollerFinder = find.byKey(const ValueKey<String>('complex-scroll'));
final ListView scroller = tester.widget<ListView>(scrollerFinder);
final ScrollController? controller = scroller.controller;
final List<int> frameTimestamp = <int>[];
final List<double> scrollOffset = <double>[];
final List<Duration> delays = <Duration>[];
binding.addPersistentFrameCallback((Duration timeStamp) {
if (controller?.hasClients ?? false) {
// This if is necessary because by the end of the test the widget tree
// is destroyed.
frameTimestamp.add(timeStamp.inMicroseconds);
scrollOffset.add(controller!.offset);
}
tester.binding.handlePointerEventForSource(event, source: TestBindingEventSource.test);
}
}
});
for (int n = 0; n < 5; n++) {
await scroll();
}
variant.result = scrollSummary(scrollOffset, delays, frameTimestamp);
await tester.pumpAndSettle();
scrollOffset.clear();
delays.clear();
await tester.idle();
}, semanticsEnabled: false, variant: variant);
Duration now() => binding.currentSystemFrameTimeStamp;
Future<void> scroll() async {
// Extra 50ms to avoid timeouts.
final Duration startTime = const Duration(milliseconds: 500) + now();
for (final PointerEvent event in dragInputEvents(
startTime,
tester.getCenter(scrollerFinder),
frequency: variant.frequency,
)) {
await tester.binding.delayed(event.timeStamp - now());
// This now measures how accurate the above delayed is.
final Duration delay = now() - event.timeStamp;
if (delays.length < frameTimestamp.length) {
while (delays.length < frameTimestamp.length - 1) {
delays.add(Duration.zero);
}
delays.add(delay);
} else if (delays.last < delay) {
delays.last = delay;
}
tester.binding.handlePointerEventForSource(event, source: TestBindingEventSource.test);
}
}
for (int n = 0; n < 5; n++) {
await scroll();
}
variant.result = scrollSummary(scrollOffset, delays, frameTimestamp);
await tester.pumpAndSettle();
scrollOffset.clear();
delays.clear();
await tester.idle();
},
semanticsEnabled: false,
variant: variant,
);
}
/// Calculates the smoothness measure from `scrollOffset` and `delays` list.
@@ -215,15 +206,15 @@ Map<String, dynamic> scrollSummary(
double jankyCount = 0;
double absJerkAvg = 0;
int lostFrame = 0;
for (int i = 1; i < scrollOffset.length-1; i += 1) {
if (frameTimestamp[i+1] - frameTimestamp[i-1] > 40E3 ||
for (int i = 1; i < scrollOffset.length - 1; i += 1) {
if (frameTimestamp[i + 1] - frameTimestamp[i - 1] > 40E3 ||
(i >= delays.length || delays[i] > const Duration(milliseconds: 16))) {
// filter data points from slow frame building or input simulation artifact
lostFrame += 1;
continue;
}
//
final double absJerk = (scrollOffset[i-1] + scrollOffset[i+1] - 2*scrollOffset[i]).abs();
final double absJerk = (scrollOffset[i - 1] + scrollOffset[i + 1] - 2 * scrollOffset[i]).abs();
absJerkAvg += absJerk;
if (absJerk > 0.5) {
jankyCount += 1;

View File

@@ -8,9 +8,6 @@ import 'package:integration_test/integration_test_driver.dart' as driver;
Future<void> main() => driver.integrationDriver(
responseDataCallback: (Map<String, dynamic>? data) async {
await driver.writeResponseData(
data,
testOutputFilename: 'scroll_smoothness_test',
);
}
await driver.writeResponseData(data, testOutputFilename: 'scroll_smoothness_test');
},
);

View File

@@ -47,26 +47,39 @@ void main() {
expect(
await driver.setSemantics(true),
isTrue,
reason: 'Could not toggle semantics to on because semantics were already '
'on, but the test needs to toggle semantics to measure the initial '
'semantics tree generation in isolation.'
reason:
'Could not toggle semantics to on because semantics were already '
'on, but the test needs to toggle semantics to measure the initial '
'semantics tree generation in isolation.',
);
});
final Iterable<TimelineEvent>? semanticsEvents = timeline.events?.where((TimelineEvent event) => event.name == 'SEMANTICS');
final Iterable<TimelineEvent>? semanticsEvents = timeline.events?.where(
(TimelineEvent event) => event.name == 'SEMANTICS',
);
if (semanticsEvents?.length != 2) {
fail('Expected exactly two "SEMANTICS" events, got ${semanticsEvents?.length}:\n$semanticsEvents');
fail(
'Expected exactly two "SEMANTICS" events, got ${semanticsEvents?.length}:\n$semanticsEvents',
);
}
final Duration semanticsTreeCreation = Duration(microseconds: semanticsEvents!.last.timestampMicros! - semanticsEvents.first.timestampMicros!);
final Duration semanticsTreeCreation = Duration(
microseconds:
semanticsEvents!.last.timestampMicros! - semanticsEvents.first.timestampMicros!,
);
final String jsonEncoded = json.encode(<String, dynamic>{'initialSemanticsTreeCreation': semanticsTreeCreation.inMilliseconds});
File(p.join(testOutputsDirectory, 'complex_layout_semantics_perf.json')).writeAsStringSync(jsonEncoded);
final String jsonEncoded = json.encode(<String, dynamic>{
'initialSemanticsTreeCreation': semanticsTreeCreation.inMilliseconds,
});
File(
p.join(testOutputsDirectory, 'complex_layout_semantics_perf.json'),
).writeAsStringSync(jsonEncoded);
}, timeout: Timeout.none);
});
}
String _adbPath() {
final String? androidHome = Platform.environment['ANDROID_HOME'] ?? Platform.environment['ANDROID_SDK_ROOT'];
final String? androidHome =
Platform.environment['ANDROID_HOME'] ?? Platform.environment['ANDROID_SDK_ROOT'];
if (androidHome == null) {
return 'adb';
} else {

View File

@@ -21,16 +21,16 @@ const Duration pauses = Duration(milliseconds: 500);
Future<void> main() async {
final Completer<void> ready = Completer<void>();
runApp(GestureDetector(
onTap: () {
debugPrint('==== MEMORY BENCHMARK ==== TAPPED ====');
ready.complete();
},
behavior: HitTestBehavior.opaque,
child: const IgnorePointer(
child: ComplexLayoutApp(),
runApp(
GestureDetector(
onTap: () {
debugPrint('==== MEMORY BENCHMARK ==== TAPPED ====');
ready.complete();
},
behavior: HitTestBehavior.opaque,
child: const IgnorePointer(child: ComplexLayoutApp()),
),
));
);
await SchedulerBinding.instance.endOfFrame;
debugPrint('==== MEMORY BENCHMARK ==== READY ====');
@@ -41,12 +41,7 @@ Future<void> main() async {
await Future<void>.delayed(const Duration(milliseconds: 200));
// remove onTap handler, enable pointer events for app
runApp(GestureDetector(
child: const IgnorePointer(
ignoring: false,
child: ComplexLayoutApp(),
),
));
runApp(GestureDetector(child: const IgnorePointer(ignoring: false, child: ComplexLayoutApp())));
await SchedulerBinding.instance.endOfFrame;
final WidgetController controller = LiveWidgetController(WidgetsBinding.instance);