如何将 TextFormField 的文本在 Flutter 中垂直居中对齐?

新手上路,请多包涵

我是 Flutter Development 的新手并尝试了某些解决方法,但没有任何帮助。我希望我的文本在 TextFormField垂直 居中。

textAlign: TextAlign.start 将我的文字带到左边,但我希望它们也垂直居中。 textAlign: TextAlign.center 将我的文本置于中心,但我希望它们也从左侧开始。

这就是我得到的, 在此处输入图像描述

这就是我要的, 在此处输入图像描述

我的代码片段:

 @override
Widget build(BuildContext context) {
return new Form(
    key: _formKey,
    child: new SingleChildScrollView(
        child: new Theme(
      data: new ThemeData(
          primaryColor: const Color(0xFF102739),
          accentColor: const Color(0xFF102739),
          hintColor: const Color(0xFF102739)),
      child: new Column(
        children: <Widget>[
          new TextFormField(
            textAlign: TextAlign.center,
            maxLines: 1,
            autofocus: true,
            keyboardType: TextInputType.emailAddress,
            style: new TextStyle(
                color: const Color(0xFF0f2638),
                fontFamily: 'ProximaNova',
                fontStyle: FontStyle.italic,
                fontSize: 16.0),
            decoration: new InputDecoration(
                contentPadding: const EdgeInsets.only(
                    top: 8.0, bottom: 8.0, left: 10.0, right: 10.0),
                hintText: "YOUR E-MAIL",
                hintStyle: new TextStyle(
                    color: const Color(0x703D444E),
                    fontFamily: 'ProximaNova',
                    fontStyle: FontStyle.italic,
                    fontSize: 16.0),
                border: new UnderlineInputBorder(
                    borderSide: new BorderSide(
                        color: const Color(0xFF0f2638), width: 0.2))),
            validator: _validateEmail,
          ),
        ],
      ),
    )));
}

原文由 buzzingsilently 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 904
1 个回答

没有垂直对齐选项。您需要做的就是设置 contentPadding 用于定位:

 TextFormField(
    decoration: InputDecoration(
        contentPadding: EdgeInsets.zero
     )

截屏

原文由 mh. bitarafan 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题