Home > Back-end >  How to create dropdow widget when click on button?
How to create dropdow widget when click on button?

Time:12-21

image description here

so how to create it? I tried to find out but still can't find a way

CodePudding user response:

You can simply use a dropdown widget and wrap it with visibility widget which will be updated on the basis of that button click:

        bool visible=false;

        ElevatedButton(onPressed: (){
          visible=!visible;    //onPressing the click button it will update visible variable
        }, child: Text('Click')),

        Visibility(
          visible: visible,    //which will make the dropdown visible
            child: DropdownButton(items: items, onChanged: (){}))

CodePudding user response:

Make use of Visibility widget

bool isDropDownVisible = false

 Visibility(
 visible: isDropDownVisible,
 child: DropdownButton(
 // DropDown Code
 )

Now while onButtonClick set it as a below:

setState(() {
isCheckSelected =! isCheckSelected;
});
  • Related