gpt4 book ai didi

flutter - 如何在 Flutter 中将静态单元(文本)添加到 TextFormField?

转载 作者:行者123 更新时间:2023-12-05 09:36:48 25 4
gpt4 key购买 nike

我目前有这个带有提示文本的 TextFormField:

Current TextFormField

目标是在 TextFormField 中添加单位,无论用户是否正在输入。它应该看起来像这样:

goal

如何实现?另外,如何使值居中?

这是我当前的 TextFormField 代码:

TextFormField(
decoration: InputDecoration(
hintText: '0.0',
contentPadding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 5.0),
filled: true,
fillColor: Colors.white24,
floatingLabelBehavior: FloatingLabelBehavior.never,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
borderSide: BorderSide.none,
),
counterText: '',
),
),

最佳答案

TextFormField 修饰可以是suffixText 属性

     TextFormField(
controller: c,
// align to center
textAlign: TextAlign.center,
decoration: InputDecoration(
hintText: '0.0',
// show kg
suffixText: 'Kg',
)

文本可以使用 textAlign 属性居中

关于flutter - 如何在 Flutter 中将静态单元(文本)添加到 TextFormField?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64947031/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com