Flutter Button Widgets | RRTutors
Last updated Sep 27, 2021Flutter is actually a widget that offers different elements, one of them is essential in any interface since it is the element to process actions par excellence, such as the button. Flutter, like any emerging technology, offers a framework that contains a large number of buttons that we can use in our applications; and the buttons are not far behind
Buttons are the graphical control element which provides the users to make an event such as click actions, making choices, and many more. Buttons can be placed anywhere in our UI like dialogs, forms, cards, toolbars, etc.
Buttons are the Flutter widgets, which is a part of the material design library. Flutter provides several types of buttons that have different shapes, styles, and features
We can also create custom buttons in flutter with adding extra customization.
Flutter contains following buttons
- Raised Button
- MaterialButton
- FloatingActionButton
- FlatButton
- IconButton
- DropdownButton
- PopupMenuButton
- Buttonbar
RaisedButton
A raised button is based on a Material widget whose Material.elevation increases when the button is pressed
new RaisedButton( color: Colors.black, |
DropdownButton
DropDown Button is using to show list of data as dropdown.
We can say it is similar to spinner button.
var selected_values; return DropdownMenuItem( setState(() { }, ), |
DropdownButton having the properties like
Items: Which is the list of data which we are going to show as list.
Which is returns the DropdownMenuItems with Value and child properties.
onChanged: Which will trigger when we are selecting the items for dropdown list.
Here we can handled the selected data and change the state to apply UI updates.
Hint: Which will show the default text as hint.
In the abova example just pasing the list of String type data.
We can also pass the Object type(Generic type) data.
Data selected_values; return DropdownMenuItem( setState(() { }, ), |
In the above we are passing the Data type class object into list.
Some times we may get crash While selecting the value from drop down, because of mismatching the Object.
To avoid that we need to make boolean type validation in class Data on properties.
Now the Data class will become like
class Data{ |
Conclusion: In this flutter button example we cover what is button and different types of flutter buttons
Article Contributed By :
|
|
|
|
1454 Views |