如何使文本字段的值居中(抖动)

How do I center the value of the textfield (flutter)

如何使文本字段的值居中 (flutter)。这样无论字有多大,它都始终位于中心?还有我如何删除下划线?

new Container(

        alignment: Alignment(0.00 , 0.50),

       child: new TextField(                                 
    style: new TextStyle(
      fontSize: 40.0,
      height: 2.0,
      color: Colors.white                  
    )
  )

您可以使用 decoration 和 textAlign 属性,尝试下一个代码:

文本字段( ....<br> 装饰:输入装饰( enabledBorder: const OutlineInputBorder( borderSide: const BorderSide(颜色: Colors.white), ), focusedBorder: const OutlineInputBorder( borderSide: const BorderSide(颜色: Colors.white), ), ), textAlign: TextAlign.center, );

@Anton,你有没有试过textAlign: TextAlign.center将下面的文字和装饰居中以删除下划线?

TextField(
  textAlign: TextAlign.center,
  style: new TextStyle(
    fontSize: 22.0, fontWeight: FontWeight.bold),
  decoration: new InputDecoration.collapsed(
    hintText: "Name",
  )
)

截图:

可以使用 inputBorder.none 删除边框。 TextAlign.center 用于设置文本中心,但您必须使用 inputDecoration.collapsed 而不是 inputDecoration。

TextFormField(
                  textAlign: TextAlign.center,
                  decoration: InputDecoration.collapsed(
                   hintText: "Enter Your Name",
                      border: InputBorder.none
                  )
                ),