Ian Hickson | 872e88c | 2018-08-06 12:46:51 -0700 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // See //dev/devicelab/bin/tasks/flutter_gallery__memory_nav.dart |
| 6 | |
| 7 | import 'dart:async'; |
| 8 | |
| 9 | import 'package:flutter/material.dart'; |
| 10 | import 'package:flutter/scheduler.dart'; |
| 11 | import 'package:flutter_gallery/gallery/app.dart' show GalleryApp; |
| 12 | import 'package:flutter_test/flutter_test.dart'; |
| 13 | |
| 14 | Future<void> endOfAnimation() async { |
| 15 | do { |
| 16 | await SchedulerBinding.instance.endOfFrame; |
| 17 | } while (SchedulerBinding.instance.hasScheduledFrame); |
| 18 | } |
| 19 | |
| 20 | int iteration = 0; |
| 21 | |
| 22 | class LifecycleObserver extends WidgetsBindingObserver { |
| 23 | @override |
| 24 | void didChangeAppLifecycleState(AppLifecycleState state) { |
| 25 | debugPrint('==== MEMORY BENCHMARK ==== $state ===='); |
| 26 | debugPrint('This was lifecycle event number $iteration in this instance'); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | Future<void> main() async { |
Ian Hickson | 872e88c | 2018-08-06 12:46:51 -0700 | [diff] [blame] | 31 | runApp(const GalleryApp()); |
| 32 | await endOfAnimation(); |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame^] | 33 | await Future<Null>.delayed(const Duration(milliseconds: 50)); |
Ian Hickson | 872e88c | 2018-08-06 12:46:51 -0700 | [diff] [blame] | 34 | debugPrint('==== MEMORY BENCHMARK ==== READY ===='); |
Alexandre Ardhuin | d927c93 | 2018-09-12 08:29:29 +0200 | [diff] [blame^] | 35 | WidgetsBinding.instance.addObserver(LifecycleObserver()); |
Ian Hickson | 872e88c | 2018-08-06 12:46:51 -0700 | [diff] [blame] | 36 | } |