icemanbsi / searchable_dropdown

MIT License
107 stars 162 forks source link

Is it possible to disable the search field and hide? #123

Closed raLaaaa closed 3 years ago

raLaaaa commented 3 years ago

Hey, thanks for the awesome library I think the title should be pretty clear :) I couldnt find an attribute to disable it :(

lcuis commented 3 years ago

Hello @raLaaaa ,

If you want to disable the searchable_dropdown widget, you can set the onChanged parameter to null as shown in the below example for the search_choices plugin.

SearchChoices.single(
        items: [
          DropdownMenuItem(
            child: Text("one item"),
            value: "one item",
          )
        ],
        value: "one item",
        hint: "Select one",
        searchHint: "Select one",
        disabledHint: "Disabled",
        onChanged: null,
        dialogBox: true,
        isExpanded: true,
      )

This also works with the searchable_dropdown plugin. image

If you want to disable the search field, you can use the searchInputDecoration argument for the search_choices plugin as follows:

SearchChoices.single(
        items: items,
        value: selectedValueSingleDialog,
        onChanged: (value) {
          setState(() {
            selectedValueSingleDialog = value;
          });
        },
        isExpanded: true,
        searchInputDecoration: InputDecoration(
          enabled: false,
          prefixIcon: Icon(
            Icons.search,
            size: 24,
          ),
          contentPadding: EdgeInsets.symmetric(vertical: 12),
        ),
      )

image

If you want to remove the search bar with the search_choices plugin, you can use the buildDropDownDialog parameter as follows for example:

SearchChoices.single(
        items: items,
        value: selectedValueSingleDialog,
        onChanged: (value) {
          setState(() {
            selectedValueSingleDialog = value;
          });
        },
        isExpanded: true,
        buildDropDownDialog: (Widget titleBar,
            Widget searchBar,
            Widget list,
            Widget closeButton,
            BuildContext dropDownContext,) {
          return (AnimatedContainer(
            padding: MediaQuery.of(dropDownContext).viewInsets,
            duration: const Duration(milliseconds: 300),
            child: Card(
              margin: EdgeInsets.symmetric(
                  vertical: 10,
                  horizontal: 10),
              child: Container(
                padding: EdgeInsets.symmetric(vertical: 15, horizontal: 15),
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  mainAxisSize: MainAxisSize.min,
                  children: <Widget>[
                    titleBar,
                    list,
                    closeButton,
                  ],
                ),
              ),
            ),
          ));
        },
      )

image