键盘不能与一起正常使用TextField。
我在代码14下面放了代码TextField,但是例如在字段14中单击时,键盘没有出现,也不在TextField点击的下方。
您能帮我解决这个键盘问题吗?这个问题没有出现,也没有让我进入所选的领域吗?
import 'package:flutter/material.dart';
void main() {
runApp(new MaterialApp(home: new HomePage()));
}
class HomePage extends StatefulWidget {
@override
HomePageState createState() => new HomePageState();
}
class HomePageState extends State<HomePage> {
final TextEditingController _controller = new TextEditingController();
@override
Widget build(BuildContext context) {
return new Scaffold(
body: new Stack(
children: <Widget>[
new ListView(
shrinkWrap: true,
children: <Widget>[
new TextField(
controller: _controller,
decoration: new InputDecoration(
hintText: 'Type something 1',
),
),
new TextField(
controller: _controller,
decoration: new InputDecoration(
hintText: 'Type something 2',
),
),
new TextField(
controller: _controller,
decoration: new InputDecoration(
hintText: 'Type something 3',
),
),
new TextField(
controller: _controller,
decoration: new InputDecoration(
hintText: 'Type something 4',
),
),
new TextField(
controller: _controller,
decoration: new InputDecoration(
hintText: 'Type something 5',
),
),
new TextField(
controller: _controller,
decoration: new InputDecoration(
hintText: 'Type something 6',
),
),
new TextField(
controller: _controller,
decoration: new InputDecoration(
hintText: 'Type something 7',
),
),
new TextField(
controller: _controller,
decoration: new InputDecoration(
hintText: 'Type something 8',
),
),
new TextField(
controller: _controller,
decoration: new InputDecoration(
hintText: 'Type something 9',
),
),
new TextField(
controller: _controller,
decoration: new InputDecoration(
hintText: 'Type something 10',
),
),
new TextField(
controller: _controller,
decoration: new InputDecoration(
hintText: 'Type something 11',
),
),
new TextField(
controller: _controller,
decoration: new InputDecoration(
hintText: 'Type something 12',
),
),
new TextField(
controller: _controller,
decoration: new InputDecoration(
hintText: 'Type something 13',
),
),
new TextField(
controller: _controller,
decoration: new InputDecoration(
hintText: 'Type something 14',
),
),
],
)
]
)
);
}
}
Run Code Online (Sandbox Code Playgroud)
我有同样的问题,但就我而言,它在Key对象中
await showDialog(
context: context,
barrierDismissible: false,
builder: (context) {
final _textKey = GlobalKey<FormState>();
TextEditingController controller = TextEditingController();
return AlertDialog(
title: Text('Load conference'),
content: Form(
key: _textKey,
child: TextFormField(
controller: controller,
validator: (str) {
if (str.isEmpty) {
return 'Empty url';
} else if (str.length >= 4 && str.substring(0, 4).toLowerCase() != 'http') {
return 'Url has to start from \'http\'';
}
},
),
onChanged: () {
if (controller.text.isNotEmpty) {
_textKey.currentState.validate();
}
},
),
Run Code Online (Sandbox Code Playgroud)
通过设置键静态类字段解决了问题
static final _textKey = GlobalKey<FormState>();
Run Code Online (Sandbox Code Playgroud)
您不应该让所有文本字段共享相同的文本TextEditingController。每个控制器使用一个单独的控制器。
| 归档时间: |
|
| 查看次数: |
3719 次 |
| 最近记录: |