首页 > 解决方案 > 如何将 HelperText 居中对齐?

问题描述

TextFormField 有一个 hintText 和一个 HelperText ,但我似乎可以找到一种方法将 helperText 居中对齐,这是我的代码:

child: Container(

                  child: TextFormField(
                    textAlign: TextAlign.center,
                    style: TextStyle(fontSize: 21),
                    decoration: InputDecoration(

                      hintText: "hint text",
                      focusedBorder: UnderlineInputBorder(

                          borderSide: BorderSide(color: primaryColor)),
                      helperText: "THIS IS THE HELPER TEXT TO BE ALIGNED ",
                       

                      helperStyle:
                          TextStyle(color: oASDC, fontSize: 15),

                    ),
                    onChanged: (value) {
                      setState(() {.......});
                    },
                  ),
                ),

有没有办法将帮助文本居中对齐?

标签: flutterdart

解决方案


据我了解,的位置helperText就像是的位置errorText

问题 1 问题 2

根据这些问题,似乎没有解决办法。

但是,如果您只需要 text ,您可以轻松地在Text下面添加小部件TextFormField

像这样:

Container(
                child: Column(
                  children: [
                    TextFormField(
                      textAlign: TextAlign.center,
                      style: TextStyle(fontSize: 21),
                      decoration: InputDecoration(
                        hintText: "hint text",
                        focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: primaryColor),),
                        // helperText: "THIS IS THE HELPER TEXT TO BE ALIGNED ",

                        helperStyle: TextStyle(color: oASDC, fontSize: 15),
                      ),
                      onChanged: (value) {
                        // setState(() {.......});
                      },
                    ),
                    Text(
                      'THIS IS THE HELPER TEXT TO BE ALIGNED',
                      textAlign: TextAlign.center,
                    ),
                  ],
                ),
              ),

推荐阅读