• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2017 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
5import 'package:flutter/material.dart';
6import 'package:flutter_driver/driver_extension.dart';
7
8/// This sample application creates a hard to render frame, causing the
9/// driver script to race the GPU thread. If the driver script wins the
10/// race, it will screenshot the previous frame. If the GPU thread wins
11/// it, it will screenshot the latest frame.
12void main() {
13  enableFlutterDriverExtension();
14
15  runApp(Toggler());
16}
17
18class Toggler extends StatefulWidget {
19  @override
20  State<Toggler> createState() => TogglerState();
21}
22
23class TogglerState extends State<Toggler> {
24  bool _visible = false;
25
26  @override
27  Widget build(BuildContext context) {
28    return MaterialApp(
29      home: Scaffold(
30        appBar: AppBar(
31          title: const Text('FlutterDriver test'),
32        ),
33        body: Material(
34          child: Column(
35            children: <Widget>[
36              FlatButton(
37                key: const ValueKey<String>('toggle'),
38                child: const Text('Toggle visibility'),
39                onPressed: () {
40                  setState(() {
41                    _visible = !_visible;
42                  });
43                },
44              ),
45              Expanded(
46                child: ListView(
47                  children: _buildRows(_visible ? 10 : 0),
48                ),
49              ),
50            ],
51          ),
52        ),
53      ),
54    );
55  }
56}
57
58List<Widget> _buildRows(int count) {
59  return List<Widget>.generate(count, (int i) {
60    return Row(
61      children: _buildCells(i / count),
62    );
63  });
64}
65
66/// Builds cells that are known to take time to render causing a delay on the
67/// GPU thread.
68List<Widget> _buildCells(double epsilon) {
69  return List<Widget>.generate(15, (int i) {
70    return Expanded(
71      child: Material(
72        // A magic color that the test will be looking for on the screenshot.
73        color: const Color(0xffff0102),
74        borderRadius: BorderRadius.all(Radius.circular(i.toDouble() + epsilon)),
75        elevation: 5.0,
76        child: const SizedBox(height: 10.0, width: 10.0),
77      ),
78    );
79  });
80}
81