I am using DropDownSearch in flutter, and I am giving it a list for menuItems. Currently, it has only a single item in it, but the menu is really long and showing a lot of blank space in it. How can I reduce it??
My code:
Expanded(
child: DropdownSearch<Branch>(
items: userP.branch ?? [],
onChanged: (item) {
setState(() {
_selectedBranch = item;
Provider.of<MainProvider>(context, listen: false)
.setSelectedBranchId(item!.id!);
});
},
selectedItem: _selectedBranch,
dropdownDecoratorProps: const DropDownDecoratorProps(
baseStyle: TextStyle(
overflow: TextOverflow.ellipsis,
),
dropdownSearchDecoration: InputDecoration(
labelText: 'Branch',
labelStyle: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w400,
color: AppColors.textPrimary,
),
floatingLabelAlignment: FloatingLabelAlignment.start,
contentPadding: EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
border: OutlineInputBorder(),
),
),
itemAsString: (Branch data) {
return data.branchName ?? "";
},
popupProps: PopupPropsMultiSelection.menu(
showSearchBox: false,
fit: FlexFit.tight,
itemBuilder: (context, branch, val) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: DropdownMenuItem(
child: Text(branch.branchName ?? ""),
),
);
},
),
),
),
Here is a picture:
2
Answers
try this:
There is a property under popupProps which has an attribute called constraints through which you can set the height and width of the dropdown menu.
This is the implementation:
Hope this helps you.