flutter - 将输入字段和按钮放置在屏幕中央
问题描述
我想要一个简单的输入字段,下面有按钮,我试图把它放在屏幕的中央。
这是我的代码:
Widget build(BuildContext context) {
return new Container(
decoration: new BoxDecoration(color: Colors.white10),
child: new Center(
child: Column(
children: <Widget>[
TextField(
decoration: InputDecoration(border: OutlineInputBorder())),
IconButton(
icon: Icon(Icons.volume_up),
tooltip: 'Increase volume by 10%',
onPressed: () { setState(() { _volume *= 1.1; }); },)
],
)
),
);
}
但是,即使我使用Center()
小部件,它也会进入屏幕顶部。
解决方案
你想要的只是垂直居中,使用mainAxisAlignment
和crossAxisAlignment
Widget build(BuildContext context) {
return new Container(
decoration: new BoxDecoration(color: Colors.white10),
child: new Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
TextField(
decoration: InputDecoration(border: OutlineInputBorder())),
IconButton(
icon: Icon(Icons.volume_up),
tooltip: 'Increase volume by 10%',
onPressed: () { setState(() { _volume *= 1.1; }); },)
],
)
),
);
}
推荐阅读
- c# - 如何在 C# 中使用表情符号构建 unicode 字符串?
- codeblocks - 如何为 WinBGIm 安装此修复程序?
- c# - 如何将 uint[] c# 传递给 c++ dll?
- angular - Angular 以编程方式将服务注入函数
- docker - docker-compose 报错无效类型,应该是字符串
- linux - 为什么终端和 bash 脚本的结果不同?
- javascript - 如何在 Firebase 身份验证中检查是否从 Google 重定向?
- mongodb - mongo 将单个对象转换为一个元素数组
- java - 从路径读取文件夹内的文件
- octave - 如何在 Octave GUI 中删除过去的工作目录?