flutter - Flutter - 在appBar上居中TextField不起作用
问题描述
我有一个以文本字段为标题的应用栏,当我传入应用centerTitle: true
栏时,它不会居中并保持与左侧对齐。
这是我的代码
appBar: AppBar(
// Where user inputs the title of the note
centerTitle: true,
title: TextField(
// The style of the input field
decoration: InputDecoration(
hintText: 'Title',
icon: Icon(Icons.edit), // Edit icon
// The style of the hint text
hintStyle: TextStyle(
color: Colors.black,
fontSize: 18,
),
),
controller:
titleAndNoteController[0], // The controller of the input box
),
bottom: PreferredSize(
child: Opacity(
opacity: 0.25,
child: Divider(
color: Colors.black,
thickness: 1,
endIndent: 150,
indent: 150,
),
),
preferredSize: Size.fromHeight(4.0),
),
iconTheme: IconThemeData(color: Colors.black),
backgroundColor: Colors.transparent,
elevation: 0.0,
),
解决方案
在 TextField 小部件中使用 textAlign 参数,如下所示:
AppBar(
// Where user inputs the title of the note
centerTitle: true,
title: TextField(
textAlign : TextAlign.center,
// The style of the input field
decoration: InputDecoration(
hintText: 'Title',
icon: Icon(Icons.edit), // Edit icon
// The style of the hint text
hintStyle: TextStyle(
color: Colors.black,
fontSize: 18,
),
),
// The controller of the input box
),
),
结果:
推荐阅读
- python - 使用 PyODBC 和 SQL-Alchemy 同步数据更新
- r - 用 plotly 绘制线图时定义配色方案
- flutter - 如何将 PX 值转换为颤振字体大小
- ios - 本机脚本:从 6.5 迁移到 7.0 时,iOS 上的构建失败
- mysql - 如何检查数组是否包含sql中的特定字符串
- java - 将字符串转换为浮点数:输入字符串的 java.lang.numberformatexception:“10.00”
- python - 熊猫“滚动” groupby
- java - Firebase Admin SDK 导致“无法找到或加载主类”
- react-native - 使用 useEffect 和 asyncstorage 数据更新平面列表
- internet-explorer - Cygwin crontab 导航到 phpwebpage