From 3fcc1069e99d81c652178beac63609a2411c7a6b Mon Sep 17 00:00:00 2001 From: Hans Muller Date: Thu, 23 Aug 2018 12:05:47 -0700 Subject: [PATCH] Made the memory_nav benchmark a little more robust (#20938) --- .../flutter_gallery/test_memory/memory_nav.dart | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/flutter_gallery/test_memory/memory_nav.dart b/examples/flutter_gallery/test_memory/memory_nav.dart index cce1dc9eeec..ffb52f5dca7 100644 --- a/examples/flutter_gallery/test_memory/memory_nav.dart +++ b/examples/flutter_gallery/test_memory/memory_nav.dart @@ -17,6 +17,11 @@ Future endOfAnimation() async { } while (SchedulerBinding.instance.hasScheduledFrame); } +Rect boundsFor(WidgetController controller, Finder item) { + final RenderBox box = controller.renderObject(item); + return box.localToGlobal(Offset.zero) & box.size; +} + Future main() async { MaterialPageRoute.debugEnableFadingRoutes = true; // ignore: deprecated_member_use final Completer ready = new Completer(); @@ -59,12 +64,21 @@ Future main() async { await new Future.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').last); + await controller.tap(find.byTooltip('Back')); await endOfAnimation(); }