dart Flutter Center对齐InputControl值旁边的后缀文本

gtlvzcf8  于 2023-05-11  发布在  Flutter
关注(0)|答案(1)|浏览(73)

我尝试将后缀文本居中对齐到输入值旁边,但无法执行此操作。使用css是非常简单的。
到目前为止我所尝试的

TextField(
              textAlign: TextAlign.center,
              decoration: InputDecoration(
                  labelText: 'Amount',
                  suffixText: "(700INR)", <- Would be dynamic based on input)
                  prefixText: "\$"),
              controller: amountController,
              keyboardType: TextInputType.number,
              onSubmitted: (_) => submitData(),
            )

已尝试AlignCenter小部件:电流输出。

预期输出这是我想要实现的(例如使用CSS)

68bkxrlz

68bkxrlz1#

您可以将其 Package 在Container小部件中

TextField(
  textAlign: TextAlign.center,
  decoration: InputDecoration(
    labelText: 'Amount',
    prefixText: "\$",
    suffix: Container(
      alignment: Alignment.center,
      width: 80, // adjust this value as needed
      child: Text("(700INR)"),
    ),
  ),
  controller: amountController,
  keyboardType: TextInputType.number,
  onSubmitted: (_) => submitData(),
)

相关问题