Row Widget Radio Button
Complete Code For Row Widget Radio Button In Flutter
main.dart
import 'package:flutter/material.dart';
void main(){
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
String radioButtonItem = 'ONE';
int id = 1;
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Colors.indigo,
title: Text("Row Widget Radio Button"),
),
body: Padding(
padding: const EdgeInsets.all(20.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Yes',
style: new TextStyle(
fontSize: 15.0,
color: Colors.black45
)
),
Radio(
value: 1,
groupValue: id,
onChanged: (val) {
setState(() {
radioButtonItem = 'ONE';
id = 1;
});
},
),
Text('No',
style: new TextStyle(
fontSize: 15.0,
color: Colors.black45
)),
Radio(
value: 2,
groupValue: id,
onChanged: (val) {
setState(() {
radioButtonItem = 'TWO';
id = 2;
});
},
),
],
),
),
);
}
}