Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter Remove bottom underline from DropDropdownButton

Tags:

flutter

I have a drop down menu that is positioned in my app bar. However it seems to have default with an underline. The flutter docs say that is defaults to 0.0 which cant be the case and I can see the underline. How do I remove this underline.

return Container(
  decoration: BoxDecoration(
    color: Colors.white,
    borderRadius: BorderRadius.all(Radius.circular(30)),
  ),
  margin: EdgeInsets.all(10.0),
  padding: EdgeInsets.all(5.0),
  width: MediaQuery.of(context).size.width * 0.30,
  child: Center(
    child: DropdownButton(
      items: _dropdownValues.map((value) => DropdownMenuItem(child: Text(value), value: value)).toList(),
        onChanged: (String value) {
          setState(() {
            _currentlySelected = value;
          });
        },
      isExpanded: false,
      value: _currentlySelected,
    )
  )
); 

Design:

enter image description here

like image 695
Ross Avatar asked Aug 09 '19 18:08

Ross


2 Answers

I manage to find the answer. Flutter has DropdownButtonHideUnderline which was super helpful. I just wrapped DropdownButton in the DropdownButtonHideUnderline.

Code:

return Container(
    decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(30)),
    ),
    margin: EdgeInsets.all(10.0),
    padding: EdgeInsets.all(5.0),
    width: MediaQuery.of(context).size.width * 0.30,
    child: Center(
        child: DropdownButtonHideUnderline(
            child: DropdownButton(
                items: _dropdownValues.map((value) => DropdownMenuItem(child: Text(value), value: value)).toList(),
                onChanged: (String value) {
                setState(() {
                    _currentlySelected = value;
                });
                },
                isExpanded: false,
                value: _currentlySelected,
            )
        )
    )
);
like image 182
Ross Avatar answered Oct 14 '22 10:10

Ross


Another alternative is to use the underline constructor of DropdownButton and set the color to transparent.

underline: Container(color: Colors.transparent),

In your case:

child: DropdownButton(
    items: _dropdownValues.map((value) => DropdownMenuItem(child: Text(value), value: value)).toList(),
    onChanged: (String value) {
    setState(() {
        _currentlySelected = value;
    });
    },
    isExpanded: false,
    underline: Container(color: Colors.transparent),
    value: _currentlySelected,
)
like image 34
RyanNa Avatar answered Oct 14 '22 09:10

RyanNa