Skip to content

Instantly share code, notes, and snippets.

@anoochit
Created March 27, 2024 08:24
Show Gist options
  • Save anoochit/1cfaf48f16b918c41808f962a4bd9197 to your computer and use it in GitHub Desktop.
Save anoochit/1cfaf48f16b918c41808f962a4bd9197 to your computer and use it in GitHub Desktop.
consult radio button
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: 'Flutter Demo',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
bool radioValue = false;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Column(
children: [
ListTile(
leading: Radio<bool>(
value: false,
groupValue: radioValue,
onChanged: (value) {
setState(() {
radioValue = value!;
});
},
),
title: Text('False'),
),
ListTile(
leading: Radio<bool>(
value: true,
groupValue: radioValue,
onChanged: (value) {
setState(() {
radioValue = value!;
});
},
),
title: Text('True'),
),
Text('Current value is ${radioValue} ')
],
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment