简体   繁体   English

如何将文本字段的值居中(颤动)

[英]How do I center the value of the textfield (flutter)

How do I center the value of the textfield (flutter).如何将文本字段的值居中(颤动)。 So that it always stays in the center no matter how big the word is?这样无论字有多大,它始终保持在中心? And also how do i remove the underline bar?还有我如何删除下划线?

new Container(

        alignment: Alignment(0.00 , 0.50),

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

@Anton, have you tried textAlign: TextAlign.center to center the text and decoration below to remove underline bar? @Anton,您是否尝试过textAlign: TextAlign.center将下面的文本和装饰居中以删除下划线?

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

Screenshot:截屏:

截屏

Border can be removed by using inputBorder.none.可以使用 inputBorder.none 删除边框。 TextAlign.center is used to set the text center but you have to use the inputDecoration.collapsed instead of inputDecoration. TextAlign.center 用于设置文本中心,但您必须使用 inputDecoration.collapsed 而不是 inputDecoration。

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

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

TextField( ....
decoration: InputDecoration( enabledBorder: const OutlineInputBorder( borderSide: const BorderSide(color: Colors.white), ), focusedBorder: const OutlineInputBorder( borderSide: const BorderSide(color: Colors.white), ), ), textAlign: TextAlign.center, );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM