Create Radio Button in Flutter Android iOS Example Tutorial

Radio button is used to select single item from multiple items in mobile applications. In flutter we used RadioListTile widget to create Radio buttons. Radio buttons gives us the functionality to automatically select single item from multiple list. User cannot select more that one item in radio button. Radio buttons is mostly used to define main information like make female, school college and etc. So in this tutorial we would Create Radio Button in Flutter Android iOS App Example Tutorial.

Contents in this project Create Radio Button in Flutter Android iOS Example Tutorial:

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

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

3. Create our main class named as MyApp extends with StatelessWidget. We are calling Radiobutton() method here which will call the Radiobutton class view here.

4. Create a class named as Radiobutton extends StatefulWidget. In this class we would call the createState() method which will enables mutable state in given location class.

5. Create a class named as RadioButtonWidget extends State.

6. Create a String variable named as radioItem and set its default value as empty. This variable is used as State and also used to hold selected radio button value.

7. Creating widget build area in RadioButtonWidget class. We would create Column widget here and put 2 RadioListTile components here. We would also create a Text widget to display the selected item.

  • groupValue : The current selected item for group of radio button.
  • title : We would pass here Text widget and this is also radio button label.
  • value : The backhand value represent by radio button.
  • onChanged¬† : Calls every time when user selects radio button.

8. Complete source code for main.dart file:

Screenshots:

Create Radio Button in Flutter Android iOS Example Tutorial

Leave a Reply

Your email address will not be published.