Get Selected Item Value from Drop Down Button List in Flutter Example

DropdownButton widget has a property named as value which is used to hold current drop down button list selected item. It also has a property named as onChanged which is called each time when drop down item is changed. We could pass here a String named as data which is hold the current selected item and store that item into dropdownValue variable using State. So in this tutorial we would Get Selected Item Value from Drop Down Button List in Flutter iOS Android Example.

Get Selected Item Value from Drop Down Button List in Flutter iOS Android Example:

1. Import material.dart package in your app’s main.dart file.

2. Call our main MyApp class using void main runApp() method.

3. Create our main class named as MyApp extends with State less widget. In this class we would call DropDown() class directly.

4. Create a class named as DropDown extends StatefulWidget. In this class we would createState() method to enable mutable state in given class tree.

5. Create a class named as DropDownWidget extends State. This is our main widget class in which we would make drop down button list.

6. Create 2 Sting variables named as dropdownValue and holder and assign default values.

7. Create Sting List named as actorsName and set some random names in it. This list is used to set our Drop down button list items.

8. Create a function named as getDropDownItem(). In this function we would store the selected item into another variable using State.

9. Create DropdownButton widget in widget build area in DropDownWidget class.

10. Create 1 Text widget and 1 Raised button widget.

11. Complete source code for main.dart file:

Screenshots:

Get Selected Item Value from Drop Down Button List in Flutter Example

3 Comments

  1. flutter dart dropdown get selected value

  2. How do I get the value if I have multiple Drop Down Button?

Leave a Reply

Your email address will not be published. Required fields are marked *