-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathReUseAbleDropDownWidgetWithRiverPod
76 lines (66 loc) · 2.24 KB
/
ReUseAbleDropDownWidgetWithRiverPod
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
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:liveproject/utilis/theme/themecolors.dart';
// Create a provider for managing the selected value state
final selectedDropDownValueProvider = StateNotifierProvider.autoDispose<SelectedValueNotifier, String?>((ref) {
return SelectedValueNotifier();
});
// StateNotifier to manage the selected value
class SelectedValueNotifier extends StateNotifier<String?> {
SelectedValueNotifier() : super(null);
void setSelectedValue(String? value) {
state = value;
}
}
class ReusableDropdown extends ConsumerWidget {
final String hintText;
final List<String> items;
const ReusableDropdown({super.key,
required this.hintText,
required this.items,
});
@override
Widget build(BuildContext context, WidgetRef ref) {
final selectedValue = ref.watch(selectedDropDownValueProvider);
return Container(
height: 50.0,
decoration: BoxDecoration(
color: Themecolor.white,
borderRadius: BorderRadius.circular(15),
),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 12.0),
child: DropdownButtonFormField<String>(
decoration: InputDecoration(
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
hintText: hintText,
),
value: selectedValue,
onChanged: (value) {
ref.read(selectedDropDownValueProvider.notifier).setSelectedValue(value);
},
items: items.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(
value,
style: const TextStyle(color: Colors.black),
),
);
}).toList(),
),
),
);
}
}
class Themecolor {
Themecolor._();
static const Color primary = Color(0xFF03008B);
static const Color icon = Color(0xFF008000);
static const Color white = Color(0xFFFFFFFF);
static const Color black = Color(0xFF333333);
static const Color border = Color(0xFFE9EBED);
static const Color red = Color(0xFFFF0000);
static const Color flushbar = Color.fromARGB(255, 138, 136, 220);
}