main.dart
import 'package:flutter/material.dart';
void main() => runApp(FlutterExample());
class FlutterExample extends StatelessWidget {
const FlutterExample({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Example',
theme: ThemeData(primarySwatch: Colors.red),
home: const StateExample()
);
}
}
class StateExample extends StatefulWidget {
const StateExample({Key? key}) : super(key: key);
@override
_StateExampleState createState() => _StateExampleState();
}
enum colors { red, green, blue }
class _StateExampleState extends State<StateExample> {
colors _color = colors.green;
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF5F5F5),
appBar: AppBar(
title: const Text("Flutter - Radio Button Size")
),
body: bodyContent()
);
}
bodyContent() {
return Column(
children: [
ListTile(
title: const Text("Red"),
tileColor: Colors.blue[100],
contentPadding: const EdgeInsets.symmetric(
horizontal: 15, vertical: 5
),
leading: Transform.scale(
scale: 2,
child: Radio<colors>(
value: colors.red,
groupValue: _color,
onChanged: (colors? value){
setState(() {
_color = value??_color;
});
},)
),
),
ListTile(
title: const Text("Green"),
tileColor: Colors.blue[100],
contentPadding: const EdgeInsets.symmetric(
horizontal: 15, vertical: 5
),
leading: Transform.scale(
scale: 2,
child: Radio<colors>(
value: colors.green,
groupValue: _color,
onChanged: (colors? value){
setState(() {
_color = value??_color;
});
},
),)
),
ListTile(
title: const Text("Blue"),
tileColor: Colors.blue[100],
contentPadding: const EdgeInsets.symmetric(
horizontal: 15, vertical: 5
),
leading: Transform.scale(
scale: 2,
child: Radio<colors>(
value: colors.blue,
groupValue: _color,
onChanged: (colors? value){
setState(() {
_color = value??_color;
});
},
),)
)
],
);
}
}
More flutter tutorials
- flutter – How to create rounded corners ToggleButtons
- flutter – How to use ToggleButtons onPressed
- flutter – How to show vertical ToggleButtons
- flutter – Checkbox checked color
- flutter – Checkbox onChanged
- flutter – CheckboxListTile left
- flutter – CheckboxListTile subtitle and icon
- flutter – Radio button horizontal
- flutter – Radio button color
- flutter – Radio button with text
- flutter – Radio button list
- flutter – Radio button onChanged
- flutter – Radio button default selected
- flutter – Slider label
- flutter – RangeSlider example