I recently shifted from using DropdownButton to using DropdownMenu widget in my flutter application, however I cannot seem to remove the border even after setting the border states.
DropdownMenu<T>(
initialSelection: value,
dropdownMenuEntries: items ?? [],
onSelected: (selectedValue) {
onChanged?.call(selectedValue);
},
width: MediaQuery.of(context).size.width,
hintText: hintText,
leadingIcon: leadingIcon,
trailingIcon: trailingIcon,
textStyle: AppTextStyles.textFieldValue,
inputDecorationTheme: InputDecorationTheme(
filled: true,
fillColor: AppColors.white,
hintStyle: AppTextStyles.textFieldValue.copyWith(
color: AppColors.textFieldPrefix,
),
border: OutlineInputBorder(
borderSide: BorderSide(
color: AppColors.textFieldBorder,
width: 1.sp,
),
borderRadius: BorderRadius.circular(10.r),
),
constraints: BoxConstraints(maxHeight: height),
),
),
The code above just returns a black border around the dropdownMenu. Removing it then places a black underline border.
Container(
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
border: Border.all(color: AppColors.textFieldBorder),
borderRadius: BorderRadius.circular(10.r),
),
child: DropdownMenu<T>(
initialSelection: value, // Set the initial selection
dropdownMenuEntries: items ?? [], // Pass the items
onSelected: (selectedValue) {
onChanged?.call(selectedValue); // Call the onChanged callback
},
width: MediaQuery.of(context).size.width, // Match the width
hintText: hintText,
leadingIcon: leadingIcon,
trailingIcon: trailingIcon,
textStyle: AppTextStyles.textFieldValue,
inputDecorationTheme: InputDecorationTheme(
filled: true,
fillColor: AppColors.white,
hintStyle: AppTextStyles.textFieldValue.copyWith(
color: AppColors.textFieldPrefix,
),
constraints: BoxConstraints(maxHeight: height),
),
),
),
This displays the desired border, but places a black underline at the bottom
2
Answers
Editing the outlineBorder (type BorderSide) property instead of the other border properties of type InputBorder fixed it.
If you want to remove the underline border from the
DropdownMenu
, you can addborder: InputBorder.none
property to theinputDecorationTheme
property of yourDropdownMenu
widget.Also, if you want to remove any border of your
DropdownMenu
, you can remove theborder
property of theContainer
widget.The provided code will be changed to: