layout_bench.dart 1.34 KB
Newer Older
1 2
import 'dart:io';

Adam Barth's avatar
Adam Barth committed
3
import 'package:flutter_test/flutter_test.dart';
4
import 'package:flutter/material.dart';
Adam Barth's avatar
Adam Barth committed
5
import 'package:flutter/rendering.dart';
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
import 'package:stocks/main.dart' as stocks;
import 'package:stocks/stock_data.dart' as stock_data;

const int _kNumberOfIterations = 100000;
const bool _kRunForever = false;

void main() {
  assert(false); // Don't run in checked mode
  stock_data.StockDataFetcher.actuallyFetchData = false;

  testWidgets((WidgetTester tester) {
    stocks.main();
    tester.pump(); // Start startup animation
    tester.pump(const Duration(seconds: 1)); // Complete startup animation
    tester.tapAt(new Point(20.0, 20.0)); // Open drawer
    tester.pump(); // Start drawer animation
    tester.pump(const Duration(seconds: 1)); // Complete drawer animation
  });

25 26
  ViewConfiguration big = const ViewConfiguration(size: const Size(360.0, 640.0));
  ViewConfiguration small = const ViewConfiguration(size: const Size(355.0, 635.0));
27 28 29 30 31 32
  RenderView renderView = WidgetFlutterBinding.instance.renderView;

  Stopwatch watch = new Stopwatch()
    ..start();

  for (int i = 0; i < _kNumberOfIterations || _kRunForever; ++i) {
33
    renderView.configuration = (i % 2 == 0) ? big : small;
34
    WidgetFlutterBinding.instance.pipelineOwner.flushLayout();
35 36 37 38 39 40
  }

  watch.stop();
  print("Stock layout: " + watch.elapsed.toString());
  exit(0);
}