driver.dart 2.75 KB
Newer Older
1 2 3 4 5 6 7 8 9
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_driver/driver_extension.dart';

void main() {
10
  enableFlutterDriverExtension();
11 12 13 14 15 16 17 18 19 20 21 22
  runApp(new DriverTestApp());
}

class DriverTestApp extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return new DriverTestAppState();
  }
}

class DriverTestAppState extends State<DriverTestApp> {
  bool present = true;
23
  Letter _selectedValue = Letter.a;
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: new Scaffold(
        appBar: new AppBar(
          title: const Text('FlutterDriver test'),
        ),
        body: new ListView(
          padding: const EdgeInsets.all(5.0),
          children: <Widget>[
            new Row(
              children: <Widget>[
                new Expanded(
                  child: new Text(present ? 'present' : 'absent'),
                ),
                new RaisedButton(
                  child: const Text(
                    'toggle',
43
                    key: ValueKey<String>('togglePresent'),
44 45 46 47 48 49 50 51 52
                  ),
                  onPressed: () {
                    setState(() {
                      present = !present;
                    });
                  },
                ),
              ],
            ),
53 54 55
            new Row(
              children: <Widget>[
                const Expanded(
56
                  child: Text('hit testability'),
57 58 59 60 61 62 63 64 65
                ),
                new DropdownButton<Letter>(
                  key: const ValueKey<String>('dropdown'),
                  value: _selectedValue,
                  onChanged: (Letter newValue) {
                    setState(() {
                      _selectedValue = newValue;
                    });
                  },
66
                  items: const <DropdownMenuItem<Letter>>[
67
                    DropdownMenuItem<Letter>(
68
                      value: Letter.a,
69
                      child: Text('Aaa', key: ValueKey<String>('a')),
70
                    ),
71
                    DropdownMenuItem<Letter>(
72
                      value: Letter.b,
73
                      child: Text('Bbb', key: ValueKey<String>('b')),
74
                    ),
75
                    DropdownMenuItem<Letter>(
76
                      value: Letter.c,
77
                      child: Text('Ccc', key: ValueKey<String>('c')),
78 79 80 81 82
                    ),
                  ],
                ),
              ],
            ),
83
            const TextField(
84
              key: ValueKey<String>('enter-text-field'),
85
            ),
86 87 88 89 90 91
          ],
        ),
      ),
    );
  }
}
92 93

enum Letter { a, b, c }