我可以在 Flutter 中设置文本在文本字段中的位置吗?
can I set the position of text inside textfield in Flutter?
我有这样的代码
Stack(
children: [
TextFormField(
autofocus: true,
autocorrect: false,
maxLines: 1,
textAlign: TextAlign.center,
),
Positioned(
bottom: 14,
left: 0,
child: Text("Rp"),
),
],
),
我知道我可以使用 TextAlign.center
将文本设置在中心,但现在我想在文本字段中的文本开始处+距开始约 24 pt
我不能使用 TextAlign.start
,因为它会与 'Rp' 文本重叠。
怎么做?
为“Rp”文本使用前缀或后缀:
TextFormField(
decoration: InputDecoration(
prefix: ...,
suffix: ...,)
那么你可以使用textAlign
TextFormField(
decoration: InputDecoration(
prefixText: 'Rp',
),
),
试试下面的代码希望它对你有帮助你可以在 TextFormField 的 Inputdecoration 中使用前缀 属性 here and InputDecoration here
TextFormField(
autofocus: true,
autocorrect: false,
maxLines: 1,
textAlign: TextAlign.center,
decoration: InputDecoration(
prefix: Text('Rp'),
),
),
您的结果屏幕->
我有这样的代码
Stack(
children: [
TextFormField(
autofocus: true,
autocorrect: false,
maxLines: 1,
textAlign: TextAlign.center,
),
Positioned(
bottom: 14,
left: 0,
child: Text("Rp"),
),
],
),
我知道我可以使用 TextAlign.center
将文本设置在中心,但现在我想在文本字段中的文本开始处+距开始约 24 pt
我不能使用 TextAlign.start
,因为它会与 'Rp' 文本重叠。
怎么做?
为“Rp”文本使用前缀或后缀:
TextFormField(
decoration: InputDecoration(
prefix: ...,
suffix: ...,)
那么你可以使用textAlign
TextFormField(
decoration: InputDecoration(
prefixText: 'Rp',
),
),
试试下面的代码希望它对你有帮助你可以在 TextFormField 的 Inputdecoration 中使用前缀 属性 here and InputDecoration here
TextFormField(
autofocus: true,
autocorrect: false,
maxLines: 1,
textAlign: TextAlign.center,
decoration: InputDecoration(
prefix: Text('Rp'),
),
),
您的结果屏幕->