Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove underline from DropdownButtonFormField

Tags:

flutter

dart

How can I remove the underline from DropdownButtonFormField (check photo below), I have tried various combinations of options with InputDecortaion couldn't find any way.

DropdownButtonFormField

SizedBox(
  width: 100.0,
  child: DropdownButtonFormField<int>(
    decoration: InputDecoration(
        border: UnderlineInputBorder(
            borderSide:
                BorderSide(color: Colors.white))),
    value: 2,
    items: <DropdownMenuItem<int>>[
      DropdownMenuItem<int>(
        value: 1,
        child: Text("Owner"),
      ),
      DropdownMenuItem<int>(
        value: 2,
        child: Text("Member"),
      ),
    ],
  ),
like image 648
Harsh Bhikadia Avatar asked Dec 03 '18 06:12

Harsh Bhikadia


People also ask

How do you get rid of the underline in Flutter?

To remove TextField underline/border in Flutter, you can simply set the border property to InputBorder. none. This will remove the underline for all states such as Focused, Enabled, Error, Disabled.

How do you change the dropdown underline color in Flutter?

To change underline color use the underline property of the Dropdown widget and then assign the Container widget with height and color property. Inside the Dropdown widget, and add the underline property and assign the Container widget. Inside the Container , add the color property and assign the color.


3 Answers

Just wrap DropdownButton inside DropdownButtonHideUnderline like this :

new DropdownButtonHideUnderline(  child: DropdownButton() ) 
like image 66
Krishna Jangid Avatar answered Sep 19 '22 22:09

Krishna Jangid


Setting the underline property to SizedBox() makes it invisible too:

...  DropdownButton(   underline: SizedBox(),  ... 
like image 24
Boy Avatar answered Sep 21 '22 22:09

Boy


One way of Doing it :

In your Code - change decoration: InputDecoration to decoration: InputDecoration.collapsed

body: SizedBox(
          width: 100.0,
          child: DropdownButtonFormField<int>(
            decoration: InputDecoration.collapsed(hintText: ''),
            value: 2,
            ...

OR

In your Code - instead of border Use enabledBorder: UnderlineInputBorder

DropdownButtonFormField<int>(
          decoration: InputDecoration(
              enabledBorder: UnderlineInputBorder(
                  borderSide: BorderSide(color: Colors.white))),
          value: 2,
          items: <DropdownMenuItem<int>>[
          ....
like image 45
anmol.majhail Avatar answered Sep 20 '22 22:09

anmol.majhail