driver.dart 2.71 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8
// 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_driver/driver_extension.dart';

void main() {
9
  enableFlutterDriverExtension();
10
  runApp(const DriverTestApp());
11 12 13
}

class DriverTestApp extends StatefulWidget {
14
  const DriverTestApp({super.key});
15

16 17
  @override
  State<StatefulWidget> createState() {
18
    return DriverTestAppState();
19 20 21 22 23
  }
}

class DriverTestAppState extends State<DriverTestApp> {
  bool present = true;
24
  Letter _selectedValue = Letter.a;
25 26 27

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

enum Letter { a, b, c }