如何在文本文件中将提示文本对齐到中心?

pra*_* Dp 25 dart flutter

我正在尝试将对齐添加到文本字段中的提示文本。但它不起作用。如何把它带到中心?如何以曲线形状书写文字???

 Container(
           child: new TextFormField(
                       controller: _pass,
                       textAlign: TextAlign.center, 
                       decoration: new InputDecoration.collapsed(
                                             hintText: " PASSWORD", ), )),
Run Code Online (Sandbox Code Playgroud)

Tus*_*kam 29

textAlign: TextAlign.center,在 TextFormField 或 textfield 内使用

这是代码

在此处输入图片说明

像这样的输出

在此处输入图片说明


Ped*_*ina 10

我的问题是自动内容填充:

TextField(
     textAlign: TextAlign.center,
     decoration: InputDecoration(
     contentPadding: EdgeInsets.all(0),
     hintText: "hola mundo",
   ),
),
Run Code Online (Sandbox Code Playgroud)

快乐编码。


Tab*_*aba 9

textHint将有相同的对齐方式输入文本。所以你可以尝试下面的代码来实现你想要的:

TextFormField(
      keyboardType: TextInputType.number,
      maxLength: 5,
      textAlign: TextAlign.center,
      autofocus: true,
      initialValue: '',
      decoration: InputDecoration(
        hintText: 'some hint',
        counterText: "",
        contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
        border: OutlineInputBorder(borderRadius: BorderRadius.circular(5.0)),
      ),
    );
Run Code Online (Sandbox Code Playgroud)


小智 7

您可以将 textAlign: TextAlign.center 添加到您的代码中,这是我的代码及其工作原理:

new Padding(
                padding: new EdgeInsets.all(30.0),

                child:
                new TextField(
                  textAlign: TextAlign.center,

                  decoration: new InputDecoration(
                    border: new OutlineInputBorder(
                        borderSide: new BorderSide(color: Colors.teal)),
                    hintText: 'REF: 2',
                  ),
                ),
              ),
Run Code Online (Sandbox Code Playgroud)


Ale*_*dar 5

注意:特定情况,但可能会帮助其他尝试过此线程中其他所有内容的人。

我有一个设计,我从中复制了所有的填充和对齐方式,但不知何故我无法将提示文本居中,它总是靠近顶部边缘几个像素。

唯一有效的是发现设计中设置了特定的文本高度。在我应用之后,一切都完美地对齐了。

InputDecoration(
  hintStyle: TextStyle(
    fontSize: _smallFontSize, // or whatever
    height: 1.4, //                                <----- this was the key
  ),
  // other properties...
);
Run Code Online (Sandbox Code Playgroud)


aub*_*han -1

这以前可以用,但现在不行了。flutter repo 中有一个最近打开的问题,您可以关注

现在编辑 按预期工作。