Show Get Selected Radio Button Group Value in Flutter RadioListTile

Radio button also known as RadioListTile widget in Flutter has a property named as onChanged which will calls every time when user select any given Radio button. We can call any function or task in this block of code which will execute each time user selects a Radio button. We are creating Radio button group using LIST in our tutorial so all we have to do is store the Checked item in given State variable. So in this tutorial we would Show Get Selected Radio Button Group Value in Flutter RadioListTile Android iOS Example. This is same as selecting item on button click event.

Contents in this project Show Get Selected Radio Button Group Value in Flutter RadioListTile Android iOS 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 MyApp class extends with StatelessWidget. We would also call RadioGroup() class here directly using their method. This would automatically draws the Widget build area of given class.

4. Create a class named as RadioGroup() extends with State full widget. In this class we would make a class object with createState() method. This method will allows to use States in given class tree.

5. Create a class named as NumberList. In this class we would create 2 Variables number and index and return both of them using constructor(). We would use this class to create items for Radio button group.

6. Create a class named as RadioGroupWidget extends State. This would be our main Widget class.

7. Create a String variable named as radioItemHolder with default value One. This is our default radio button selected value. Also this is used to hold selected radio button group value later on.

8. Create a integer variable named as id.

9. Create a List using NumberList class. We would use this list to create Radio buttons.

10. Create a Text widget and RadioListTile widget in widget build area in RadioGroupWidget class. As you can see in below code onChanged method we would save the selected item value in holder.

11. Complete source code for main.dart file:

Screenshots:

Show Get Selected Radio Button Group Value in Flutter RadioListTile

Leave a Reply

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