简体   繁体   中英

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.

For vertically centered hint text : Add a contentPadding , eg, contentPadding: EdgeInsets.symmetric(vertical: 2) to the TextField .

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,
            ),
          ),
        ),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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