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:
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,
)
)
)
);
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,
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With