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(); }