【发布时间】:2019-06-04 12:44:40
【问题描述】:
我正在尝试创建一个简单的待办事项应用程序,底部有一个浮动操作按钮,单击该按钮时会显示一个警报对话框以将项目添加到列表中。 每次单击按钮时,键盘都会向上推动操作按钮,导致溢出错误。 打开键盘时,有什么办法可以避免向上推动操作按钮? 这是我拍的快照: Snapshot 源码下方:
import 'package:flutter/material.dart';
import '../model/todo_item.dart';
class ToDoScreen extends StatefulWidget {
@override
_ToDoScreenState createState() => _ToDoScreenState();
}
class _ToDoScreenState extends State<ToDoScreen> {
TextEditingController _textEditingController = TextEditingController();
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.blueAccent,
body: Column(
children: <Widget>[ToDoItem("Going for a Walk", "12 January, 2019")],
),
floatingActionButton: FloatingActionButton(
tooltip: 'Add Item',
child: Icon(Icons.add),
backgroundColor: Colors.red,
onPressed: _showFormDialog,
),
);
}
void _showFormDialog() {
var alert = AlertDialog(
content: Row(
children: <Widget>[
Expanded(
child: TextField(
controller: _textEditingController,
autofocus: true,
decoration: InputDecoration(
labelText: "Item",
hintText: "eg. Buy Vegetables",
icon: Icon(Icons.note_add)),
),
)
],
),
actions: <Widget>[
FlatButton(
onPressed: () {
// _handleSubmit(_textEditingController.text);
_textEditingController.clear();
},
child: Text("Save ToDo"),
),
FlatButton(
onPressed: () {
Navigator.pop(context);
},
child: Text("Cancel"),
)
],
);
showDialog(context: context, builder: (BuildContext context) => alert);
}
}
【问题讨论】:
-
使用
ListView而不是Column -
感谢您的回复。是的,我知道我可以使用 ListView 而不是 Column 但我的问题是如何停止浮动按钮以在每次打开键盘时被提升。有什么办法可以解决这个问题吗?
标签: android mobile flutter flutter-layout