I have a DropdownButton that when it's open looks like this.
Is it possible to make it narrower to adjust to the text?
This is my DropdownButton:
DropdownButton<dynamic>(
value: state.locale.languageCode,
items: [
DropdownMenuItem(
value: 'EN',
child: SizedBox(
child: Text(
'EN',
),
),
),
DropdownMenuItem(
value: 'DE',
child: SizedBox(
child: Text(
'DE',
),
),
),
],
onChanged: (newValue) {
dropdownCallback(newValue, state);
},
underline: DropdownButtonHideUnderline(child: Container()),
),
I have tried to wrap it in sized boxes, both the Button and Menu items, and it doesn't work. I can't find any parameters in the documentation to help me with it. Any ideas?
CodePudding user response:
Try to wrap your Dropdown with Container and Set width it hope its help to you
Container(
width: 25,
child: DropdownButton<dynamic>(
isExpanded: true,
items: [
DropdownMenuItem(
value: 'EN',
child: Text(
'EN',
),
),
DropdownMenuItem(
value: 'DE',
child: Text(
'DE',
),
),
],
onChanged: (newValue) {},
underline: DropdownButtonHideUnderline(child: Container()),
),
),
CodePudding user response:
You can Do like below.
Container(
width: 45,
child: DropdownButton<dynamic>(
value: "EN",
itemHeight: 50.0,
isExpanded: true,
items: [
DropdownMenuItem(
value: 'EN',
child: SizedBox(
child: Text(
'EN',
),
),
),
DropdownMenuItem(
value: 'DE',
child: SizedBox(
child: Text(
'DE',
),
),
),
],
onChanged: (newValue) {
// dropdownCallback(newValue, state);
},
underline: DropdownButtonHideUnderline(child: Container()),
// },
) ,
)