How do I remove content padding from TextField?

后端 未结 10 1726
深忆病人
深忆病人 2021-02-05 01:28

I am new to flutter and I am creating login form, for that I have used TextField and added prefix icon but I am getting some extra spaces in between textfields (user id and pin

相关标签:
10条回答
  • 2021-02-05 02:05

    I come a bit late, but the only thing you have to do is to use negative padding :

    TextField(
       decoration: InputDecoration(
          contentPadding: EdgeInsets.symmetric(vertical: -5),
          labelText: 'Description',
       )
     )
    
    0 讨论(0)
  • 2021-02-05 02:13

    By applying minus padding by using

    transform: Matrix4.translationValues(-10.0, 0.0, 0.0),
    

    put above line inside the icon container

    TextFormField(
              keyboardType: TextInputType.number,
              style: new TextStyle(color: Colors.white, fontSize: 17),
              decoration: new InputDecoration(
                  prefixIcon: Container(
                    transform: Matrix4.translationValues(-10.0, 0.0, 0.0),
                    child: Icon(
                      Icons.vpn_key,
                      color: Colors.white,
                    ),
                  ),
                  labelText: "Enter Password",
                  labelStyle: new TextStyle(color: Colors.white)),
            ),
    
    0 讨论(0)
  • 2021-02-05 02:14

    You can use contentPadding of InputDecoration. Here is sample code

    TextField(
       maxLines: 8,
       decoration: InputDecoration(
          contentPadding: EdgeInsets.symmetric(vertical: 5),
          labelText: 'Description',
          labelStyle: txtHintStyle,
       )
     )
    
    0 讨论(0)
  • 2021-02-05 02:15

    As of flutter 1.17.5 (and still the same in 1.2X) to completely remove or manipulate the padding manually, first you must set isDense: true and then you can adjust the contentPadding as you wanted or apply padding on the parent widget instead.

    TextField(
      inputDecorationTheme: InputDecorationTheme(
         isDense: true,
         contentPadding: EdgeInsets.symmetric(horizontal: 0, vertical: 0),
         ...
      ),
    )
    
    0 讨论(0)
  • 2021-02-05 02:15

    You can try this hack by reducing height of TextField

    SizedBox(
      height: 44, // set this
      child: TextField(),
    )
    
    0 讨论(0)
  • 2021-02-05 02:18

    I was able to easily achieve that by adding prefix constraints to the prefixIcon and wrapping the prefixIcon with padding like this

          TextFormField(
             enabled: true,
             decoration: InputDecoration(
             prefixIconConstraints:BoxConstraints(minWidth: 23, maxHeight: 20),
             prefixIcon: Padding(
                           padding: const EdgeInsets.only(right: 20),
                           child: Icon(
                                    Icons.email,
                                    color: clockColor,
                                   ),
                            ),
             hintText:"Email Address"
             hintStyle:TextStyle(color: hintColor, fontSize: 14),
           ),
        ),
    

    heres the output,hope this helps

    0 讨论(0)
提交回复
热议问题