【问题标题】:can I set the position of text inside textfield in Flutter?我可以在 Flutter 的文本字段中设置文本的位置吗?
【发布时间】:2021-10-11 06:45:35
【问题描述】:

我有这样的代码

       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”文本重叠。

怎么做?

【问题讨论】:

    标签: flutter textfield


    【解决方案1】:

    对“Rp”文本使用前缀或后缀:

    TextFormField(
      decoration: InputDecoration(
        prefix: ...,
        suffix: ...,)
    

    那么你可以使用textAlign

    【讨论】:

      【解决方案2】:

      试试下面的代码希望它对你有帮助你可以在 TextFormField here 和 InputDecoration here 的 Inputdecoration 中使用前缀属性

      TextFormField(
                  autofocus: true,
                  autocorrect: false,
                  maxLines: 1,
                  textAlign: TextAlign.center,
                  decoration: InputDecoration(
                    prefix: Text('Rp'),
                  ),
                ),
      

      您的结果屏幕->

      【讨论】:

        【解决方案3】:
        TextFormField(
              decoration: InputDecoration(
                prefixText: 'Rp',
              ),
            ),
        

        【讨论】:

          猜你喜欢
          • 2012-05-24
          • 2021-09-04
          • 2016-06-13
          • 1970-01-01
          • 1970-01-01
          • 2023-04-02
          • 1970-01-01
          • 1970-01-01
          • 2021-06-04
          相关资源
          最近更新 更多