keyboard_resize.dart 1.86 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 9 10
// 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';

import 'keys.dart' as keys;

void main() {
11
  enableFlutterDriverExtension(handler: (String? message) async {
12
    // TODO(cbernaschina): remove when test flakiness is resolved
13 14
    return 'keyboard_resize';
  });
15
  runApp(const MyApp());
16 17 18
}

class MyApp extends StatelessWidget {
19
  const MyApp({super.key});
20

21 22
  @override
  Widget build(BuildContext context) {
23
    return MaterialApp(
24
      title: 'Text Editing',
25
      theme: ThemeData(primarySwatch: Colors.blue),
26
      home: const MyHomePage(),
27 28 29 30 31
    );
  }
}

class MyHomePage extends StatefulWidget {
32
  const MyHomePage({super.key});
33

34
  @override
35
  State<MyHomePage> createState() => _MyHomePageState();
36 37 38
}

class _MyHomePageState extends State<MyHomePage> {
39
  final TextEditingController _controller = TextEditingController();
40 41 42

  @override
  Widget build(BuildContext context) {
43
    final TextField textField = TextField(
44 45
      key: const Key(keys.kDefaultTextField),
      controller: _controller,
46
      focusNode: FocusNode(),
47
    );
48 49
    return Scaffold(
      body: Stack(
50
        fit: StackFit.expand,
51
        alignment: Alignment.bottomCenter,
52
        children: <Widget>[
53
          LayoutBuilder(
54
            builder: (BuildContext context, BoxConstraints constraints) {
55
              return Center(child: Text('${constraints.biggest.height}', key: const Key(keys.kHeightText)));
56 57 58 59 60
            }
          ),
          textField,
        ],
      ),
61
      floatingActionButton: FloatingActionButton(
62
        key: const Key(keys.kUnfocusButton),
63
        onPressed: () { textField.focusNode!.unfocus(); },
64
        tooltip: 'Unfocus',
65
        child: const Icon(Icons.done),
66 67 68 69
      ),
    );
  }
}