-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy path19. flutter_radio_button.dart
72 lines (66 loc) · 2.22 KB
/
19. flutter_radio_button.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import 'package:flutter/material.dart';
import 'package:ig_posts/features/1.flutter_frost_glass.view.dart';
import 'package:ig_posts/features/5.flutter_swiggy_button.dart';
import 'package:provider/provider.dart';
class ButtonNotifier extends ChangeNotifier {
String? radioValue;
void setRadioValue({required String kValue}) {
radioValue = kValue;
notifyListeners();
}
}
class FlutterClassicButtons extends StatelessWidget {
const FlutterClassicButtons({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
ButtonNotifier buttonNotifier({required bool renderUI}) =>
Provider.of<ButtonNotifier>(context, listen: renderUI);
List values = [
"India 🇮🇳",
"Germany 🇩🇪",
"China 🇨🇳",
"England 🏴",
"Poland 🇵🇱",
"Japan 🇯🇵",
"Romania 🇷🇴",
"Argentina 🇦🇷",
];
radioButtons() {
return ListView.builder(
shrinkWrap: true,
itemCount: values.length,
itemBuilder: (BuildContext context, int index) {
return RadioListTile<String>(
title: Text(values[index], style: regulerText),
value: values[index],
groupValue: buttonNotifier(renderUI: true).radioValue,
onChanged: (value) {
buttonNotifier(renderUI: false)
.setRadioValue(kValue: values[index]);
});
},
);
}
return Scaffold(
backgroundColor: bgColor,
appBar: AppBar(
backgroundColor: bgColorFaint,
title: Text("Flutter Radio Buttons ⭕️", style: boldText())),
body: Column(
children: [
const SizedBox(height: 20),
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.white),
borderRadius: BorderRadius.circular(25)),
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Text(buttonNotifier(renderUI: true).radioValue ?? "",
style: boldText()))),
const SizedBox(height: 20),
radioButtons(),
],
),
);
}
}