driver.dart 2.83 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 11 12 13
  enableFlutterDriverExtension(handler: (String message) async {
    // TODO(cbernaschina) remove when test flakiness is resolved
    return 'driver';
  });
14 15 16 17 18 19 20 21 22 23 24 25
  runApp(new DriverTestApp());
}

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

class DriverTestAppState extends State<DriverTestApp> {
  bool present = true;
26
  Letter _selectedValue = Letter.a;
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55

  @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',
                    key: const ValueKey<String>('togglePresent'),
                  ),
                  onPressed: () {
                    setState(() {
                      present = !present;
                    });
                  },
                ),
              ],
            ),
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
            new Row(
              children: <Widget>[
                const Expanded(
                  child: const Text('hit testability'),
                ),
                new DropdownButton<Letter>(
                  key: const ValueKey<String>('dropdown'),
                  value: _selectedValue,
                  onChanged: (Letter newValue) {
                    setState(() {
                      _selectedValue = newValue;
                    });
                  },
                  items: <DropdownMenuItem<Letter>>[
                    const DropdownMenuItem<Letter>(
                      value: Letter.a,
                      child: const Text('Aaa', key: const ValueKey<String>('a')),
                    ),
                    const DropdownMenuItem<Letter>(
                      value: Letter.b,
                      child: const Text('Bbb', key: const ValueKey<String>('b')),
                    ),
                    const DropdownMenuItem<Letter>(
                      value: Letter.c,
                      child: const Text('Ccc', key: const ValueKey<String>('c')),
                    ),
                  ],
                ),
              ],
            ),
86 87 88 89 90 91
          ],
        ),
      ),
    );
  }
}
92 93

enum Letter { a, b, c }