flutter/examples/flutter_gallery/test_memory/memory_nav.dart
liyuqian 6c4b38b707
Enable fading animation during page transitions. (#21394)
The average frame time of page transitions on Moto G4 is now very
close to 16ms (the last 10 measurements on our dashboard are
between 15.5ms to 16.7ms and half of them are below 16ms).

It is now much faster than when we disabled it (which was at about
35ms). So I think that we should be able to enable it by default.
I'll leave the flag there until we implement the retained rendering
to bring the frame time comfortably below 16ms.

See https://github.com/flutter/flutter/issues/13736
2018-09-06 09:26:52 -07:00

86 lines
2.8 KiB
Dart

// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// See //dev/devicelab/bin/tasks/flutter_gallery__memory_nav.dart
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter_gallery/gallery/app.dart' show GalleryApp;
import 'package:flutter_test/flutter_test.dart';
Future<void> endOfAnimation() async {
do {
await SchedulerBinding.instance.endOfFrame;
} while (SchedulerBinding.instance.hasScheduledFrame);
}
Rect boundsFor(WidgetController controller, Finder item) {
final RenderBox box = controller.renderObject<RenderBox>(item);
return box.localToGlobal(Offset.zero) & box.size;
}
Future<void> main() async {
final Completer<void> ready = new Completer<void>();
runApp(new GestureDetector(
onTap: () {
debugPrint('Received tap.');
ready.complete();
},
behavior: HitTestBehavior.opaque,
child: const IgnorePointer(
ignoring: true,
child: GalleryApp(testMode: true),
),
));
await SchedulerBinding.instance.endOfFrame;
await new Future<Null>.delayed(const Duration(milliseconds: 50));
debugPrint('==== MEMORY BENCHMARK ==== READY ====');
await ready.future;
debugPrint('Continuing...');
// remove onTap handler, enable pointer events for app
runApp(new GestureDetector(
child: const IgnorePointer(
ignoring: false,
child: GalleryApp(testMode: true),
),
));
await SchedulerBinding.instance.endOfFrame;
final WidgetController controller = new LiveWidgetController(WidgetsBinding.instance);
debugPrint('Navigating...');
await controller.tap(find.text('Material'));
await new Future<Null>.delayed(const Duration(milliseconds: 150));
final Finder demoList = find.byKey(const Key('GalleryDemoList'));
final Finder demoItem = find.text('Text fields');
do {
await controller.drag(demoList, const Offset(0.0, -300.0));
await new Future<Null>.delayed(const Duration(milliseconds: 20));
} while (!demoItem.precache());
// Ensure that the center of the "Text fields" item is visible
// because that's where we're going to tap
final Rect demoItemBounds = boundsFor(controller, demoItem);
final Rect demoListBounds = boundsFor(controller, demoList);
if (!demoListBounds.contains(demoItemBounds.center)) {
await controller.drag(demoList, new Offset(0.0, demoListBounds.center.dy - demoItemBounds.center.dy));
await endOfAnimation();
}
for (int iteration = 0; iteration < 15; iteration += 1) {
debugPrint('Tapping... (iteration $iteration)');
await controller.tap(demoItem);
await endOfAnimation();
debugPrint('Backing out...');
await controller.tap(find.byTooltip('Back'));
await endOfAnimation();
}
debugPrint('==== MEMORY BENCHMARK ==== DONE ====');
}