Skip to content

Commit 13cee3a

Browse files
Sandip KakadiyaSandip Kakadiya
authored andcommitted
dropdown & multiselect changes
1 parent 694afb5 commit 13cee3a

File tree

6 files changed

+532
-541
lines changed

6 files changed

+532
-541
lines changed

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,4 @@ packages:
261261
version: "4.2.0"
262262
sdks:
263263
dart: ">=2.9.0-14.0.dev <3.0.0"
264-
flutter: ">=1.18.0-6.0.pre <2.0.0"
264+
flutter: ">=1.18.0-6.0.pre <2.0.0"

lib/components/dropdown/gf_dropdown.dart

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import 'package:flutter/material.dart';
22

33
class GFDropdown<T> extends StatefulWidget {
4-
GFDropdown(
4+
///
5+
const GFDropdown(
56
{Key key,
67
@required this.items,
78
this.icon,
@@ -26,13 +27,13 @@ class GFDropdown<T> extends StatefulWidget {
2627
this.dropdownColor,
2728
this.padding = const EdgeInsets.all(5),
2829
this.borderRadius = const BorderRadius.all(Radius.circular(4)),
29-
this.borderColor});
30+
this.borderColor})
31+
: super(key: key);
3032

31-
DropdownButtonBuilder selectedItemBuilder;
33+
final DropdownButtonBuilder selectedItemBuilder;
3234
final List<DropdownMenuItem<T>> items;
3335

3436
/// The widget to use for the drop-down button's icon.
35-
///
3637
/// Defaults to an [Icon] with the [Icons.arrow_drop_down] glyph.
3738
final Widget icon;
3839

@@ -55,7 +56,6 @@ class GFDropdown<T> extends StatefulWidget {
5556
final Widget disabledHint;
5657

5758
/// Called when the user selects an item.
58-
///
5959
/// If the [onChanged] callback is null or the list of [DropdownButton.items]
6060
/// is null then the dropdown button will be disabled,
6161
final ValueChanged<T> onChanged;
@@ -114,38 +114,34 @@ class GFDropdown<T> extends StatefulWidget {
114114

115115
class _GFDropdownState extends State<GFDropdown> {
116116
@override
117-
Widget build(BuildContext context) {
118-
return Card(
117+
Widget build(BuildContext context) => Card(
119118
child: Container(
120-
padding: widget.padding,
121-
decoration: BoxDecoration(
122-
borderRadius: widget.borderRadius,
123-
border: Border.all(
124-
color: widget.borderColor != null
125-
? widget.borderColor
126-
: Colors.white)),
127-
child: DropdownButton(
128-
129-
items: widget.items,
130-
selectedItemBuilder: widget.selectedItemBuilder,
131-
value: widget.value,
132-
hint: widget.hint,
133-
disabledHint: widget.disabledHint,
134-
onChanged: widget.onChanged == null ? null : widget.onChanged,
135-
onTap: widget.onTap,
136-
elevation: widget.elevation,
137-
style: widget.style,
138-
icon: widget.icon,
139-
iconDisabledColor: widget.iconDisabledColor,
140-
iconEnabledColor: widget.iconEnabledColor,
141-
iconSize: widget.iconSize,
142-
isDense: widget.isDense,
143-
isExpanded: widget.isExpanded,
144-
itemHeight: widget.itemHeight,
145-
focusColor: widget.focusColor,
146-
focusNode: widget.focusNode,
147-
autofocus: widget.autofocus,
148-
dropdownColor: widget.dropdownColor,
149-
)));
150-
}
119+
padding: widget.padding,
120+
decoration: BoxDecoration(
121+
borderRadius: widget.borderRadius,
122+
border: Border.all(color: widget.borderColor ?? Colors.white)),
123+
child: DropdownButton(
124+
items: widget.items,
125+
selectedItemBuilder: widget.selectedItemBuilder,
126+
value: widget.value,
127+
hint: widget.hint,
128+
disabledHint: widget.disabledHint,
129+
onChanged: widget.onChanged,
130+
onTap: widget.onTap,
131+
elevation: widget.elevation,
132+
style: widget.style,
133+
icon: widget.icon,
134+
iconDisabledColor: widget.iconDisabledColor,
135+
iconEnabledColor: widget.iconEnabledColor,
136+
iconSize: widget.iconSize,
137+
isDense: widget.isDense,
138+
isExpanded: widget.isExpanded,
139+
itemHeight: widget.itemHeight,
140+
focusColor: widget.focusColor,
141+
focusNode: widget.focusNode,
142+
autofocus: widget.autofocus,
143+
dropdownColor: widget.dropdownColor,
144+
),
145+
),
146+
);
151147
}
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:getwidget/getwidget.dart';
3+
4+
class GFMultiSelect extends StatefulWidget {
5+
///
6+
const GFMultiSelect({
7+
this.titleText,
8+
this.selectedTextStyle =
9+
const TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
10+
this.color,
11+
this.avatar,
12+
this.padding = const EdgeInsets.all(0),
13+
this.margin = const EdgeInsets.all(5),
14+
this.size = GFSize.MEDIUM,
15+
this.type = GFCheckboxType.basic,
16+
this.checkColor = GFColors.WHITE,
17+
this.activebgColor = GFColors.WHITE,
18+
this.inactivebgColor = GFColors.WHITE,
19+
this.activeBorderColor = GFColors.WHITE,
20+
this.inactiveBorderColor = GFColors.WHITE,
21+
this.items,
22+
this.submitbutton,
23+
this.expandedicon = Icons.keyboard_arrow_down,
24+
this.collapsedicon = Icons.keyboard_arrow_up,
25+
this.dropdownbgColor = Colors.white,
26+
this.activeIcon = const Icon(
27+
Icons.check,
28+
size: 20,
29+
color: GFColors.DARK,
30+
),
31+
this.inactiveIcon,
32+
this.custombgColor = GFColors.SUCCESS,
33+
this.selected = false,
34+
Key key,
35+
}) : assert(selected != null),
36+
super(key: key);
37+
38+
///type of [String] used to pass text, alternative to title property and gets higher priority than title
39+
final String titleText;
40+
41+
/// The GFListTile's background color. Can be given [Color] or [GFColors]
42+
final Color color;
43+
44+
/// type of [Widget] or [GFAvatar] used to create rounded user profile
45+
final Widget avatar;
46+
47+
/// defines the margin of GFListTile
48+
final EdgeInsets margin;
49+
50+
/// defines the padding of GFListTile
51+
final EdgeInsets padding;
52+
53+
/// type of [GFCheckboxType] which is of four type is basic, sqaure, circular and custom
54+
final GFCheckboxType type;
55+
56+
/// type of [double] which is GFSize ie, small, medium and large and can use any double value
57+
final double size;
58+
59+
/// type pf [Color] used to change the checkcolor when the checkbox is active
60+
final Color checkColor;
61+
62+
/// type of [Color] used to change the backgroundColor of the active checkbox
63+
final Color activebgColor;
64+
65+
/// type of [Color] used to change the backgroundColor of the inactive checkbox
66+
final Color inactivebgColor;
67+
68+
/// type of [Color] used to change the border color of the active checkbox
69+
final Color activeBorderColor;
70+
71+
/// type of [Color] used to change the border color of the inactive checkbox
72+
final Color inactiveBorderColor;
73+
74+
/// Called when the user checks or unchecks the checkbox.
75+
// final ValueChanged<bool> onChanged;
76+
77+
///Used to set the current state of the checkbox
78+
// final bool value;
79+
80+
///type of Widget used to change the checkbox's active icon
81+
final Widget activeIcon;
82+
83+
///type of [Widget] used to change the checkbox's inactive icon
84+
final Widget inactiveIcon;
85+
86+
/// type of [Color] used to change the background color of the custom active checkbox only
87+
final Color custombgColor;
88+
89+
/// To have the list tile appear selected when the checkbox is checked, pass the same value to both.
90+
/// Normally, this property is left to its default value, false.
91+
final bool selected;
92+
93+
final List items;
94+
95+
final Widget submitbutton;
96+
97+
final Color dropdownbgColor;
98+
99+
final TextStyle selectedTextStyle;
100+
101+
final IconData expandedicon;
102+
103+
final IconData collapsedicon;
104+
105+
@override
106+
_GFMultiSelectState createState() => _GFMultiSelectState();
107+
}
108+
109+
class _GFMultiSelectState extends State<GFMultiSelect> {
110+
bool check = true;
111+
bool isdrop = false;
112+
bool check1 = false;
113+
114+
final _controller = TextEditingController();
115+
116+
final List _selectedTitles = [];
117+
118+
void _onItemSelect(bool selected, String title) {
119+
if (selected == true) {
120+
setState(() {
121+
_selectedTitles.add(title);
122+
});
123+
} else {
124+
setState(() {
125+
_selectedTitles.remove(title);
126+
});
127+
}
128+
}
129+
130+
@override
131+
void dispose() {
132+
if (_controller != null) {
133+
_controller.dispose();
134+
}
135+
super.dispose();
136+
}
137+
138+
@override
139+
Widget build(BuildContext context) => Column(
140+
children: [
141+
InkWell(
142+
onTap: () {
143+
setState(() {
144+
isdrop = !isdrop;
145+
});
146+
},
147+
child: Container(
148+
149+
// height: 40,
150+
width: MediaQuery.of(context).size.width,
151+
decoration: const BoxDecoration(
152+
border:
153+
Border(bottom: BorderSide(color: Colors.black12))),
154+
child: Container(
155+
child: Row(
156+
crossAxisAlignment: CrossAxisAlignment.start,
157+
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
158+
children: <Widget>[
159+
Expanded(
160+
child: Container(
161+
padding: const EdgeInsets.only(bottom: 10),
162+
child: Text(_selectedTitles.join(' , ').toString(),
163+
style: widget.selectedTextStyle),
164+
)),
165+
Icon(
166+
!isdrop ? widget.expandedicon : widget.collapsedicon,
167+
color: Colors.black87,
168+
size: 30,
169+
),
170+
],
171+
),
172+
))),
173+
isdrop
174+
? Container(
175+
decoration: BoxDecoration(
176+
color: widget.dropdownbgColor,
177+
boxShadow: const [
178+
BoxShadow(
179+
color: Colors.black12,
180+
blurRadius: 3,
181+
)
182+
],
183+
),
184+
height: 300,
185+
child: SingleChildScrollView(
186+
child: Column(
187+
children: [
188+
Column(
189+
children: List.generate(
190+
widget.items.length,
191+
(index) => GFCheckboxListTile(
192+
value: _selectedTitles
193+
.contains(widget.items[index]),
194+
onChanged: (bool selected) {
195+
_controller.text;
196+
print(selected);
197+
_onItemSelect(
198+
selected, widget.items[index]);
199+
},
200+
selected: widget.selected,
201+
avatar: widget.avatar,
202+
titleText: widget.items[index],
203+
color: widget.color,
204+
padding: widget.padding,
205+
margin: widget.margin,
206+
size: widget.size,
207+
activebgColor: widget.activebgColor,
208+
inactiveIcon: widget.inactiveIcon,
209+
activeBorderColor:
210+
widget.activeBorderColor,
211+
inactivebgColor: widget.inactivebgColor,
212+
activeIcon: widget.activeIcon,
213+
inactiveBorderColor:
214+
widget.inactiveBorderColor,
215+
custombgColor: widget.custombgColor,
216+
checkColor: widget.checkColor,
217+
type: widget.type,
218+
))),
219+
GFButton(
220+
onPressed: () {
221+
setState(() {
222+
isdrop = !isdrop;
223+
});
224+
},
225+
child: widget.submitbutton,
226+
)
227+
],
228+
),
229+
),
230+
)
231+
: Container(),
232+
],
233+
);
234+
}

0 commit comments

Comments
 (0)