Complete Code For Custom Radio BUtton In Flutter
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
centerTitle: true,
backgroundColor: Colors.lightGreen,
title: Text("Custom Radio Button"),
),
body: SafeArea(
child : Center(
child:Radiobutton(),
)
)
),
);
}
}
class Radiobutton extends StatefulWidget {
@override
RadioButtonWidget createState() => RadioButtonWidget();
}
class RadioButtonWidget extends State {
String radioItem = '';
Widget build(BuildContext context) {
return Column(
children: <Widget>[
RadioListTile(
controlAffinity: ListTileControlAffinity.trailing,
groupValue: radioItem,
title: Text('Item 1'),
value: 'Item 1',
onChanged: (val) {
setState(() {
radioItem = val;
});
},
),
RadioListTile(
controlAffinity: ListTileControlAffinity.trailing,
groupValue: radioItem,
title: Text('Item 2'),
value: 'Item 2',
onChanged: (val) {
setState(() {
radioItem = val;
});
},
),
RadioListTile(
controlAffinity: ListTileControlAffinity.trailing,
groupValue: radioItem,
title: Text('Item 3'),
value: 'Item 3',
onChanged: (val) {
setState(() {
radioItem = val;
});
},
),
Text('$radioItem', style: TextStyle(fontSize: 23),)
],
);
}
}