Sample Form — Part 2— Flutter

Mathiazhagan Dinesh
3 min readJan 11, 2019

In part 1, we learned to create TextFormField for name, email, and password. In this part, we are going to create DropDown, CheckBox, Radio, and Button.

Update 1: RaisedButton is updated to ElevatedButton.

DropdownButton

A material design button for selecting from a list of items.

DropdownMenuItem

An item in a menu created by a DropdownButton.

To create DropDown, we need to create a list of DropdownMenuItem with any type. In the below example, loadGenderList() method is invoked before form creation. genderList holds the drop-down values.

value

value holds the selected value.

isExpanded

Set the dropdown’s inner contents to horizontally fill its parent. If isExpanded is true, the inner width is expanded to fill its surrounding container.

ListTile

A single fixed-height row that typically contains some text as well as a leading or trailing icon.

RadioListTile

A ListTile with a Radio. Tapping anywhere in the tile selects the radio button. In the below example, we are adding the list of RadioListTile widgets.

groupValue

The currently selected value for this group of radio buttons.

onChanged

Called when the value of the RadioListTile should change.

CheckboxListTile

A ListTile with a Checkbox. Tapping anywhere in the tile toggles the checkbox.

title

The primary content of the list tile.

subtitle

Additional content displayed below the title.

controlAffinity

Where to place the control relative to the text.

ElevatedButton

_formKey.currentState.validate() invokes all the validator method and returns true only if all the validator returns true.

_formKey.currentState.save() invokes all the onSaved method.

onPressed

The callback is called when the button is tapped or otherwise activated.

onPressedSubmit() prints all the form value in the console and show a SnackBar when the RaisedButton is pressed.

Now, we learned to create a form. Let’s have a look at the screenshot of the app and the console log.

codepen.io

--

--