keyboard_textfield.dart 1.79 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 11 12
// 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() {
  enableFlutterDriverExtension();

13
  runApp(const MyApp());
14 15 16
}

class MyApp extends StatelessWidget {
17 18
  const MyApp({Key key}) : super(key: key);

19 20
  @override
  Widget build(BuildContext context) {
21
    return MaterialApp(
22
      title: 'Keyboard & TextField',
23
      theme: ThemeData(primarySwatch: Colors.blue),
24
      home: const MyHomePage(),
25 26 27 28 29
    );
  }
}

class MyHomePage extends StatefulWidget {
30 31
  const MyHomePage({Key key}) : super(key: key);

32
  @override
33
  _MyHomePageState createState() => _MyHomePageState();
34 35 36
}

class _MyHomePageState extends State<MyHomePage> {
37
  final ScrollController _controller = ScrollController();
38 39 40 41 42 43 44 45 46 47 48 49 50 51
  double offset = 0.0;

  @override
  void initState() {
    super.initState();
    _controller.addListener(() {
      setState(() {
        offset = _controller.offset;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
52 53
    return Scaffold(
      body: Column(
54
        children: <Widget>[
55
          Text('$offset',
56 57
            key: const ValueKey<String>(keys.kOffsetText),
          ),
58 59
          Expanded(
            child: ListView(
60 61 62
              key: const ValueKey<String>(keys.kListView),
              controller: _controller,
              children: <Widget>[
63
                Container(
64 65 66
                  height: MediaQuery.of(context).size.height,
                ),
                const TextField(
67
                  key: ValueKey<String>(keys.kDefaultTextField),
68 69 70 71 72 73 74 75 76
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}