Add a tile scrolling test to complex_layout app (#9537)
* Add a tile scrolling test to complex_layout app * - Review comments and fix analyzer failures. * Use ListView.builder pattern.
This commit is contained in:
committed by
GitHub
parent
f645245ffd
commit
4e7a38b118
@@ -11,6 +11,8 @@ void main() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum ScrollMode { complex, tile }
|
||||||
|
|
||||||
class ComplexLayoutApp extends StatefulWidget {
|
class ComplexLayoutApp extends StatefulWidget {
|
||||||
@override
|
@override
|
||||||
ComplexLayoutAppState createState() => new ComplexLayoutAppState();
|
ComplexLayoutAppState createState() => new ComplexLayoutAppState();
|
||||||
@@ -24,8 +26,7 @@ class ComplexLayoutAppState extends State<ComplexLayoutApp> {
|
|||||||
return new MaterialApp(
|
return new MaterialApp(
|
||||||
theme: lightTheme ? new ThemeData.light() : new ThemeData.dark(),
|
theme: lightTheme ? new ThemeData.light() : new ThemeData.dark(),
|
||||||
title: 'Advanced Layout',
|
title: 'Advanced Layout',
|
||||||
home: const ComplexLayout()
|
home: scrollMode == ScrollMode.complex ? const ComplexLayout() : const TileScrollLayout());
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _lightTheme = true;
|
bool _lightTheme = true;
|
||||||
@@ -36,6 +37,14 @@ class ComplexLayoutAppState extends State<ComplexLayoutApp> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScrollMode _scrollMode = ScrollMode.complex;
|
||||||
|
ScrollMode get scrollMode => _scrollMode;
|
||||||
|
set scrollMode(ScrollMode mode) {
|
||||||
|
setState(() {
|
||||||
|
_scrollMode = mode;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void toggleAnimationSpeed() {
|
void toggleAnimationSpeed() {
|
||||||
setState(() {
|
setState(() {
|
||||||
timeDilation = (timeDilation != 1.0) ? 1.0 : 5.0;
|
timeDilation = (timeDilation != 1.0) ? 1.0 : 5.0;
|
||||||
@@ -43,6 +52,32 @@ class ComplexLayoutAppState extends State<ComplexLayoutApp> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TileScrollLayout extends StatelessWidget {
|
||||||
|
const TileScrollLayout({ Key key }) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return new Scaffold(
|
||||||
|
appBar: new AppBar(title: const Text('Tile Scrolling Layout')),
|
||||||
|
body: new ListView.builder(
|
||||||
|
key: const Key('tiles-scroll'),
|
||||||
|
itemCount: 200,
|
||||||
|
itemBuilder: (BuildContext context, int index) {
|
||||||
|
return new Padding(
|
||||||
|
padding:const EdgeInsets.all(5.0),
|
||||||
|
child: new Material(
|
||||||
|
elevation: index % 5 + 1,
|
||||||
|
color: Colors.white,
|
||||||
|
child: new IconBar(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
),
|
||||||
|
drawer: const GalleryDrawer(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class ComplexLayout extends StatefulWidget {
|
class ComplexLayout extends StatefulWidget {
|
||||||
const ComplexLayout({ Key key }) : super(key: key);
|
const ComplexLayout({ Key key }) : super(key: key);
|
||||||
|
|
||||||
@@ -73,7 +108,7 @@ class ComplexLayoutState extends State<ComplexLayout> {
|
|||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new Expanded(
|
new Expanded(
|
||||||
child: new ListView.builder(
|
child: new ListView.builder(
|
||||||
key: const Key('main-scroll'), // this key is used by the driver test
|
key: const Key('complex-scroll'), // this key is used by the driver test
|
||||||
itemBuilder: (BuildContext context, int index) {
|
itemBuilder: (BuildContext context, int index) {
|
||||||
if (index % 2 == 0)
|
if (index % 2 == 0)
|
||||||
return new FancyImageItem(index, key: new ValueKey<int>(index));
|
return new FancyImageItem(index, key: new ValueKey<int>(index));
|
||||||
@@ -571,12 +606,22 @@ class GalleryDrawer extends StatelessWidget {
|
|||||||
ComplexLayoutApp.of(context).lightTheme = value;
|
ComplexLayoutApp.of(context).lightTheme = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _changeScrollMode(BuildContext context, ScrollMode mode) {
|
||||||
|
ComplexLayoutApp.of(context).scrollMode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final ScrollMode currentMode = ComplexLayoutApp.of(context).scrollMode;
|
||||||
return new Drawer(
|
return new Drawer(
|
||||||
child: new ListView(
|
child: new ListView(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
new FancyDrawerHeader(),
|
new FancyDrawerHeader(),
|
||||||
|
new ListTile(
|
||||||
|
key: const Key('scroll-switcher'),
|
||||||
|
onTap: () { _changeScrollMode(context, currentMode == ScrollMode.complex ? ScrollMode.tile : ScrollMode.complex); },
|
||||||
|
trailing: new Text(currentMode == ScrollMode.complex ? 'Tile' : 'Complex')
|
||||||
|
),
|
||||||
new ListTile(
|
new ListTile(
|
||||||
leading: const Icon(Icons.brightness_5),
|
leading: const Icon(Icons.brightness_5),
|
||||||
title: const Text('Light'),
|
title: const Text('Light'),
|
||||||
|
|||||||
@@ -19,28 +19,38 @@ void main() {
|
|||||||
driver.close();
|
driver.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('measure', () async {
|
Future<Null> testScrollPerf(String listKey, String summaryName) async {
|
||||||
final Timeline timeline = await driver.traceAction(() async {
|
final Timeline timeline = await driver.traceAction(() async {
|
||||||
// Find the scrollable stock list
|
// Find the scrollable stock list
|
||||||
final SerializableFinder stockList = find.byValueKey('main-scroll');
|
final SerializableFinder list = find.byValueKey(listKey);
|
||||||
expect(stockList, isNotNull);
|
expect(list, isNotNull);
|
||||||
|
|
||||||
// Scroll down
|
// Scroll down
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
await driver.scroll(stockList, 0.0, -300.0, const Duration(milliseconds: 300));
|
await driver.scroll(list, 0.0, -300.0, const Duration(milliseconds: 300));
|
||||||
await new Future<Null>.delayed(const Duration(milliseconds: 500));
|
await new Future<Null>.delayed(const Duration(milliseconds: 500));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scroll up
|
// Scroll up
|
||||||
for (int i = 0; i < 5; i++) {
|
for (int i = 0; i < 5; i++) {
|
||||||
await driver.scroll(stockList, 0.0, 300.0, const Duration(milliseconds: 300));
|
await driver.scroll(list, 0.0, 300.0, const Duration(milliseconds: 300));
|
||||||
await new Future<Null>.delayed(const Duration(milliseconds: 500));
|
await new Future<Null>.delayed(const Duration(milliseconds: 500));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
final TimelineSummary summary = new TimelineSummary.summarize(timeline);
|
final TimelineSummary summary = new TimelineSummary.summarize(timeline);
|
||||||
summary.writeSummaryToFile('complex_layout_scroll_perf', pretty: true);
|
summary.writeSummaryToFile(summaryName, pretty: true);
|
||||||
summary.writeTimelineToFile('complex_layout_scroll_perf', pretty: true);
|
summary.writeTimelineToFile(summaryName, pretty: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
test('complex_layout_scroll_perf', () async {
|
||||||
|
await testScrollPerf('complex-scroll', 'complex_layout_scroll_perf');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('tiles_scroll_perf', () async {
|
||||||
|
await driver.tap(find.byTooltip('Open navigation menu'));
|
||||||
|
await driver.tap(find.byValueKey('scroll-switcher'));
|
||||||
|
await testScrollPerf('tiles-scroll', 'tiles_scroll_perf');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user