How to Implement Dropdown Menu on Elevated Button in Flutter

Elevated Button doesn't have any dropdown implementation, but with a little trick, you can implement Dropdown Menu on Elevated Button using Dropdown Menu. In this example, we are going to show to add Dropdown menu on Elevated Button. 

ElevatedButton(
    style: ElevatedButton.styleFrom(primary: Colors.redAccent), //Elevated Button Background
    onPressed: (){}, //make onPressed callback empty
    child:DropdownButton(
      style: TextStyle(color: Colors.white), //Dropdown font color
      dropdownColor: Colors.redAccent, //dropdown menu background color
      icon: Icon(Icons.arrow_downward, color:Colors.white), //dropdown indicator icon
      underline: Container(), //make underline empty
      value: selectval,
      onChanged: (value){
        setState(() {
            selectval = value.toString();
        });
      },
      items: listitems.map((itemone){
          return DropdownMenuItem(
            value: itemone,
            child: Text(itemone)
          );
      }).toList(),
  ),
)

You can do the same with other Button widgets or any widget you want.

Elevated Button with Dropdown Dropdown Menu when Clicked on Elevated Button

In this way, you can implement the Dropdown Menu on Elevated Button in Flutter.

No any Comments on this Article


Please Wait...