Radio Button Class

import "package:flutter/material.dart";

void main()
{
runApp(const MyApp());
}
class MyApp extends StatelessWidget
{
const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: "RadioButton Class",
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.grey,
),
home: const RadioPractice(),
);
}
}
class RadioPractice extends StatefulWidget
{
const RadioPractice({super.key});
@override
State<RadioPractice> createState()
{
return RadioPracticeState();
}
}
class RadioPracticeState extends State<RadioPractice>
{
int selectedOption = 0;
int selectedOption2 = 0;

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("RadioButton Practice"),
centerTitle: true,
backgroundColor: Colors.grey,
),
body: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
ListTile(
title: const Text("Option 1"),
leading: Radio<int>(
value: 1,
groupValue: selectedOption,
activeColor: Colors.red,
fillColor: MaterialStateProperty.all(Colors.red),
splashRadius: 20.0,
onChanged: (value) {
setState(() {
selectedOption = value!;
},);
},
),
),
ListTile(
title: const Text("Option 2"),
leading: Radio<int>(
value: 2,
groupValue: selectedOption,
activeColor: Colors.red,
fillColor: MaterialStateProperty.all(Colors.red),
splashRadius: 20.0,
onChanged: (value) {
setState(() {
selectedOption = value!;
},);
},
),
),
ListTile(
title: const Text("Male"),
leading: Radio<int>(
value: 3,
groupValue: selectedOption2,
activeColor: Colors.blue,
fillColor: MaterialStateProperty.all(Colors.blue),
splashRadius: 20.0,
onChanged: (value) {
setState(() {
selectedOption2 = value!;
},);
},
),
),
ListTile(
title: const Text("Female"),
leading: Radio<int>(
value: 4,
groupValue: selectedOption2,
activeColor: Colors.blue,
fillColor: MaterialStateProperty.all(Colors.blue),
splashRadius: 20.0,
onChanged: (value) {
setState(() {
selectedOption2 = value!;
},);
},
),
),
],
),
),
);
}
}

Comments

Popular posts from this blog

Second GET API Calling with Bloc simple Example in Flutter

Stack Container Scrollable Card widget UI with Custom Widget

Pagination with Bloc Pattern in Flutter