flutter - 如何在TextFormField的左上角开始文本
问题描述
我有 TextFormField 并且我增加了这个字段的高度。我想从左上角开始文本,并使该文本在行尾中断。因此,如果有人会放很多文本,那么字段将有 X 行,而不仅仅是一个。
现在的样子:
它应该是什么样子
代码:
TextFormField(
controller: contentController,
decoration: InputDecoration(
contentPadding: new EdgeInsets.symmetric(
vertical: MediaQuery.of(context).size.height * .10,
horizontal: 10.0),
border: OutlineInputBorder(),
hintText: 'Treść',
fillColor: Color(0xffffffff),
filled: true,
prefixIcon: Icon(Icons.topic_rounded),
),
validator: (value) {
if (value == null || value.isEmpty) {
return ErrorMessages.NO_CONTENT_MESSAGE;
}
},
),
解决方案
您需要指定prefix
图标的高度,默认情况下它将位于中心。但是要让它在顶部,您需要添加Container()
您将在其中添加这样的图标。
TextFormField(
minLines: 4,
keyboardType: TextInputType.multiline,
maxLines: 4,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'Treść',
fillColor: Color(0xffffffff),
filled: true,
prefixIcon: Container(
width: 20,
height: 100,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Icon(Icons.topic_rounded),
),
Container(),
],
),
),
prefixIconConstraints: BoxConstraints(
minWidth: 35,
minHeight: 0,
),
),
validator: (value) {
if (value == null || value.isEmpty) {
return "error";
}
return null;
},
)
它看起来像这样
推荐阅读
- sap-ase - 如何恢复 Sybase 用户名和密码?
- django - 是否可以将 pipenv 用于 django-cookiecutter?
- java - java如何在内存中分配对象的属性?
- java - Eclipse SWT setPartName 有效, setTitleImage 无效。为什么?
- python-3.x - 多线程python3服务器
- sas - SAS: Changing labels by reading from table
- mongoose - 使用 typegoose 将项目添加到 Ref 数组
- python - 用python在树中查找匹配的节点
- python - python - 单元测试记录结果文件
- plsql - DML 发生后提示用户,然后执行 DDL 的设计模式?