Dropdown
We use the Dropdown Button to display any Dropdown List item as we can change its style according to the requirement. We can customize the dropDown widget with given properties like background color, hint, items, and many more. Let’s see some of the properties of the dropdown button for example.
1. Items
We will use this property to define items displayed in the dropdown list as text values. We can define the items directly or we can define using a list.
Firstly we can see how to define items directly. We are declaring one global variable and set value 1 so in the dropDown value, we can not see an empty value. and with the use of DropdownMenuItem() we can see the value of that particular item. Let's see the example of how to use items directly:-
The second way is to use items property as a list of values and set that values in the Text widget.
2. Value
We will use value property to set the selected item from the dropdown button. When the user selects the option from the dropdown on the onChanged() method it will be invoked with the value of the dropdownMenuItem. We can get the value of the selected item and set that value in the setState() method so we can see the updated value of dropDown.
We have already seen the example in which we have declared value and set the value after that onChanged() updated the selected value in dropDownButton.
3. hint
As the name said hint in the dropdown button will display the down indicator with empty value or text.to set the default text you can use the hint property. As we have set Text "Please select your state".
4. elevation
We will use elevation property to elevate the dropdown list. The value can be from 1 to 9.
5. style
We want to style the items of dropDown then we can use the style in DropdownMenuItem() and if you want to style the hint then use this property in hint property.
6. icon
You can set the dropDown icon as per requirement. For that need to use the icon property and we can set the Icon Widget and icon which we want to show.
7. iconDisabledColor
This property is used to set icon color when the dropdown button is disabled. To show this your button value should be null to see this output you need to null the onChange method.
8. iconEnabledColor
This property is used to set the icon color of the dropdown button. This color will apply only if the button is enabled meaning not null value.
9. iconSize
IconSize property is used to define the size of the dropdown button icon.
10. isExpanded
This property is used to expand the dropdown button to full width. you need to set up the value to true will expand and false will keep the button width to default. If you want some space from the right and left so you can wrap the DropdownButton into the padding or you can use margin as per your comfort.
11. dropdownColor
DropdownColor property is used to set the color of the dropdown list. Here in the example, I have set the amber color and also change the color of values to black.
Comments
Post a Comment