Flutter Radio Button
A radio button is the options button which we use to hold the value when you have more than two options and you want to select only one. So it is different from checkbox because you can only select true or false but Radio buttons can select from multiple options. We always arrange the radio button in a group of two or more and displayed as empty circular holes (for unselected) or a dot in the hole (for selected). We can also add labels.
groupValue: This property specifies the currently selected item for the radio button group.
title: This property specifies the radio button label.
value: This property specifies the backhand value, which is represented by a radio button.
onChanged: We can add the function that will be called whenever the user selects the radio button.
Let see an radio button example:
import 'package:flutter/material.dart'; void main() => runApp(MyApp()); class MyApp extends StatelessWidget { String _title = 'Radio Button Example'; @override Widget build(BuildContext context) { return MaterialApp( title: _title, home: Scaffold( appBar: AppBar(title: const Text(_title)), body: Center( child: MyStatefulWidget(), ), ), ); } } enum BestTutorSite { javatpoint, w3schools, tutorialandexample } class MyStatefulWidget extends StatefulWidget { MyStatefulWidget({Key key}) : super(key: key); @override _MyStatefulWidgetState createState() => _MyStatefulWidgetState(); } class _MyStatefulWidgetState extends State{ BestTutorSite _site = BestTutorSite.javatpoint; Widget build(BuildContext context) { return Column( children: [ ListTile( title: const Text('www.javatpoint.com'), leading: Radio( value: BestTutorSite.javatpoint, groupValue: _site, onChanged: (BestTutorSite value) { setState(() { _site = value; }); }, ), ), ListTile( title: const Text('www.w3school.com'), leading: Radio( value: BestTutorSite.w3schools, groupValue: _site, onChanged: (BestTutorSite value) { setState(() { _site = value; }); }, ), ), ListTile( title: const Text('www.tutorialandexample.com'), leading: Radio( value: BestTutorSite.tutorialandexample, groupValue: _site, onChanged: (BestTutorSite value) { setState(() { _site = value; }); }, ), ), ], ); } }