How do you provide a fixed height for the dropdown in Flutter? The dropdown menu height changes whenever the dropdown list appears, this happens after putting the tailing icon. and how to change the background color of the dropdown list.
DropdownMenu<String>(
requestFocusOnTap: true,
controller: controller.buyerController,
label: Text(controller.buyerLabel.value),
dropdownMenuEntries: controller.dropdownItems.map((option) {
return DropdownMenuEntry<String>(
value: option,
label: option,
);
}).toList(),
inputDecorationTheme: InputDecorationTheme(
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: const BorderSide(color: Colors.grey, width: 1.5),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(30),
borderSide: const BorderSide(color: Colors.black, width: 2.0),
),
filled: true,
fillColor: Colors.white,
),
width: widthValue,
trailingIcon: IconButton(
icon: const Icon(Icons.clear),
onPressed: () {
controller.clear("po");
},
),
onSelected: controller.buyerFilter,
),
The issue is DropdownMenu
was expecting an Icon
not IconButton
.
trailingIcon: IconButton(
icon: const Icon(Icons.clear),
onPressed: () {
controller.clear();
},
),
Can be replaced with
trailingIcon: InkWell(
child: const Icon(Icons.clear),
onTap: () {
controller.clear();
},
),
For the second part the background color for items are set in menuStyle
DropdownMenu<String>(
dropdownMenuEntries: [
DropdownMenuEntry(value: "1", label: "one"),
DropdownMenuEntry(value: "2", label: "two"),
],
menuStyle: MenuStyle(
backgroundColor: WidgetStateProperty.all(Colors.green),
),
),