Home > Software design >  how too style DropdownSearch Selected Item in flutter
how too style DropdownSearch Selected Item in flutter

Time:07-13

I am using dropdown_search How to style Selected Item in the dropdown?? I am trying searching the best way but am not able to do that, please suggest me some ways.

  DropdownSearch(
            favoriteItemsAlignment: MainAxisAlignment.center,
            autoValidateMode: AutovalidateMode.always,
            mode: modes,
            showSearchBox: true,
            maxHeight: maxHeight,
            popupItemBuilder: dropdownItemSuggestion,
            dropdownSearchDecoration: InputDecoration(
              disabledBorder: InputBorder.none,errorText: errormsg,
              hintText: dropdownHintText,
              hintStyle: UtilsMethods.mediumTextStyle(AppColor.grey, 14),
            ),
            items: dropdownItem,
            onChanged: dropdownOnChanged,
            selectedItem: dropdownSelectedItem ,       ///I want to style this text
    
    
          ),

CodePudding user response:

You can use dropdownBuilder to decorate the selected item,

DropdownSearch<String>(
  dropdownBuilder: (context, selectedItem) {
    return Text(
      selectedItem ?? "",
      style: TextStyle(
        color: Colors.green,
      ),
    );
  },
  popupProps: PopupProps.menu(
    showSelectedItems: true,
    disabledItemFn: (String s) => s.startsWith('I'),
  ),
  items: ["Brazil", "Italia (Disabled)", "Tunisia", 'Canada'],
  selectedItem: "Brazil",
)

More about dropdown_search

  • Related