Keep TextFields visible when keyboard comes up (#18291)

Fixes #10826.

Also in this PR: If you focus a text field, scroll it out of view and then start typing it will scroll back into view.
This commit is contained in:
Michael Goderbauer
2018-06-15 10:11:10 -07:00
committed by GitHub
parent e713b3349a
commit 409007827b
7 changed files with 345 additions and 12 deletions

View File

@@ -0,0 +1,72 @@
// Copyright 2018 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_driver/driver_extension.dart';
import 'keys.dart' as keys;
void main() {
enableFlutterDriverExtension();
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Keyboard & TextField',
theme: new ThemeData(primarySwatch: Colors.blue),
home: new MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final ScrollController _controller = new ScrollController();
double offset = 0.0;
@override
void initState() {
super.initState();
_controller.addListener(() {
setState(() {
offset = _controller.offset;
});
});
}
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Column(
children: <Widget>[
new Text('$offset',
key: const ValueKey<String>(keys.kOffsetText),
),
new Expanded(
child: new ListView(
key: const ValueKey<String>(keys.kListView),
controller: _controller,
children: <Widget>[
new Container(
height: MediaQuery.of(context).size.height,
),
const TextField(
key: const ValueKey<String>(keys.kDefaultTextField),
),
],
),
),
],
),
);
}
}

View File

@@ -5,3 +5,5 @@
const String kDefaultTextField = 'default_textfield';
const String kHeightText = 'height_text';
const String kUnfocusButton = 'unfocus_button';
const String kOffsetText = 'offset_text';
const String kListView = 'list_view';