简体   繁体   English

flutter 填充到文本字段中的文本

[英]flutter padding to text in textfield

I have given the textfield a custom height with a container around it.我给文本字段一个自定义高度,周围有一个容器。 The icons are stlii in the middle but the text is not in the center of the textfield.图标在中间,但文本不在文本字段的中心。 Do somebody know a way to fix this problem?有人知道解决这个问题的方法吗?

Container(
                          height: 45,
                          child: TextFormField(
                            decoration: InputDecoration(
                              filled: true,
                              fillColor: Colors.grey[100],
                              border: OutlineInputBorder(
                                borderRadius: BorderRadius.circular(20),
                                borderSide: BorderSide(
                                  width: 0,
                                  style: BorderStyle.none,
                                ),
                              ),
                              hintText: 'Hint Text',
                            ),
                            style: TextStyle(
                              fontSize: 18,
                            ),
                          ),
                        ),

For horizontally centered hint text : The hint text aligns according to the TextFormField 's textAlign , so adding textAlign: TextAlign.center to the TextFormField will center the hint text horizontally.对于水平居中提示文本:提示文本根据TextFormFieldtextAlign对齐,因此将textAlign: TextAlign.center添加到TextFormField将使提示文本水平居中。

For vertically centered hint text : Add a contentPadding , eg, contentPadding: EdgeInsets.symmetric(vertical: 2) to the TextField .对于垂直居中的提示文本:向TextField添加contentPadding ,例如contentPadding: EdgeInsets.symmetric(vertical: 2)

Container(
          height: 45,
          child: TextFormField(
            textAlign: TextAlign.center, // this is new
            decoration: InputDecoration(
              filled: true,
              contentPadding: EdgeInsets.symmetric(vertical: 2), // this is new
              fillColor: Colors.grey[100],
              border: OutlineInputBorder(
                borderRadius: BorderRadius.circular(20),
                borderSide: BorderSide(
                  width: 0,
                  style: BorderStyle.none,
                ),
              ),
              hintText: 'Hint Text',
            ),
            style: TextStyle(
              fontSize: 18,
            ),
          ),
        ),

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

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