-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy path15.flutter_dropdown.dart
110 lines (102 loc) · 3.79 KB
/
15.flutter_dropdown.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import 'package:flutter/material.dart';
import 'package:ig_posts/features/1.flutter_frost_glass.view.dart';
import 'package:provider/provider.dart';
class DropDownNotifier extends ChangeNotifier {
String? selectedItem;
void setSelectedItem({required String value}) {
selectedItem = value;
notifyListeners();
debugPrint(selectedItem);
}
void clearMenu() {
selectedItem = null;
notifyListeners();
}
}
class FlutterDropDownView extends StatelessWidget {
const FlutterDropDownView({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
DropDownNotifier downNotifier({required bool renderUI}) =>
Provider.of<DropDownNotifier>(context, listen: renderUI);
List<String> items = [
"India 🇮🇳",
"Chile 🇨🇱",
"France 🇫🇷",
"Argetina 🇦🇷",
"Indonesia 🇮🇩"
];
String? kSelectedData = downNotifier(renderUI: true).selectedItem;
String? parsedString = kSelectedData?.substring(kSelectedData.length - 5);
return Scaffold(
appBar: AppBar(
backgroundColor: bgColorFaint,
title: const Text("Clean Dropdown Menu 🚀")),
backgroundColor: bgColor,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
if (parsedString != null)
Text(parsedString,
style: const TextStyle(
fontWeight: FontWeight.bold, fontSize: 100)),
if (kSelectedData != null)
Text(
"The selected country is ${downNotifier(renderUI: true).selectedItem}",
style: const TextStyle(
fontWeight: FontWeight.bold, fontSize: 20)),
const SizedBox(height: 20),
DropdownButton<String>(
menuMaxHeight: 200,
icon: const Icon(Icons.arrow_forward_ios, size: 12),
dropdownColor: bgColorFaint,
hint: const Text("Select your country",
style: TextStyle(fontWeight: FontWeight.bold)),
borderRadius: BorderRadius.circular(25),
value: downNotifier(renderUI: true).selectedItem,
items: items.map((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style: const TextStyle(
fontWeight: FontWeight.bold, color: Colors.white),
));
}).toList(),
onChanged: (kValue) {
if (kValue != null) {
downNotifier(renderUI: false).setSelectedItem(value: kValue);
}
},
),
const SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if (kSelectedData != null)
ActionChip(
backgroundColor: Colors.red,
label: const Text("Clear",
style: TextStyle(fontWeight: FontWeight.bold)),
onPressed: () {
downNotifier(renderUI: false).clearMenu();
}),
const SizedBox(width: 20),
if (kSelectedData != null)
ActionChip(
backgroundColor: Colors.blue,
label: const Text("Continue",
style: TextStyle(fontWeight: FontWeight.bold)),
onPressed: () {
downNotifier(renderUI: false).clearMenu();
})
],
)
],
),
),
);
}
}