Dart 如何将提示文本对齐到文本字段的中心?
我正在尝试将对齐添加到文本字段内的提示文本。但它不起作用。如何把它带到中心?? 如何以曲线形状书写文本Dart 如何将提示文本对齐到文本字段的中心?,dart,flutter,Dart,Flutter,我正在尝试将对齐添加到文本字段内的提示文本。但它不起作用。如何把它带到中心?? 如何以曲线形状书写文本 Container( child: new TextFormField( controller: _pass, textAlign: TextAlign.center, decoration: new InputDecoration
Container(
child: new TextFormField(
controller: _pass,
textAlign: TextAlign.center,
decoration: new InputDecoration.collapsed(
hintText: " PASSWORD", ), )),
这以前可以用,但现在不行了。有一种方法你可以遵循 编辑
现在可以正常工作。文本提示将与输入文本具有相同的对齐方式。因此,您可以尝试下面的代码来实现您想要的:
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)),
),
);
您可以将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',
),
),
),
在TextFormField或textfield中使用
textAlign:textAlign.center、
这是密码
输出是这样的
我的问题是自动内容填充:
TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
contentPadding: EdgeInsets.all(0),
hintText: "hola mundo",
),
),
愉快的编码。textAlign:textAlign.center也将移动您的焦点,我在提示文本中用一些空格来修复它
hintText: ' this is centred text)',
注意:特定案例,但可能会帮助尝试此线程中其他所有内容的其他人
我有一个设计,我从中复制了所有的填充和对齐,但不知怎么的,我无法将提示文本居中,它总是离上边缘近一些像素
唯一有效的方法是发现设计中设置了特定的文本高度。在我应用之后,一切都完美地对齐了
InputDecoration(
hintStyle: TextStyle(
fontSize: _smallFontSize, // or whatever
height: 1.4, // <----- this was the key
),
// other properties...
);
输入装饰(
hintStyle:TextStyle(
fontSize:_smallFontSize,//或其他
高度:1.4,//到目前为止您尝试了什么?发布一些代码。请编辑您的问题以添加代码,并删除注释。请检查此@PhilippReichart我已编辑了代码。。有什么建议吗?@ShyjuM我已尝试过此方法。此方法仅适用于非常特定的情况,不可持续。如果文本字段缩小或增大文本将不再居中,如果文本发生更改,也不能保证文本居中。这可能因屏幕而异。这不是一般性的做法。我们不推荐这种方法。因为它取决于屏幕。