@@ -16,10 +16,14 @@ class GSSelect extends StatefulWidget {
16
16
final GSSelectSizes ? size;
17
17
final GSSelectVariants ? variant;
18
18
final GSStyle ? style;
19
- final GSSelectHeaderText hintText ;
19
+ final GSSelectHeaderText initialLabel ;
20
20
final GSSelectIcon icon;
21
21
final GSSelectContent content;
22
- final ValueChanged <String >? onChanged;
22
+ final ValueChanged <String >? onValueChange;
23
+ final bool isDisabled;
24
+ final bool closeOnOverlayClick;
25
+ final Function ()? onClose;
26
+ final Function ()? onOpen;
23
27
24
28
const GSSelect ({
25
29
super .key,
@@ -28,10 +32,14 @@ class GSSelect extends StatefulWidget {
28
32
required this .options,
29
33
this .disabledOptions,
30
34
required this .icon,
31
- required this .hintText ,
35
+ required this .initialLabel ,
32
36
this .style,
33
- this .onChanged,
37
+ this .onValueChange,
38
+ this .isDisabled = false ,
39
+ this .closeOnOverlayClick = true ,
34
40
required this .content,
41
+ this .onClose,
42
+ this .onOpen,
35
43
});
36
44
37
45
@override
@@ -57,6 +65,11 @@ class _GSSelectState extends State<GSSelect> {
57
65
overlayEntry? .remove ();
58
66
overlayEntry = null ;
59
67
hoveredIndex = null ;
68
+ WidgetsBinding .instance.addPostFrameCallback ((_) {
69
+ if (widget.onClose != null ) {
70
+ widget.onClose !();
71
+ }
72
+ });
60
73
}
61
74
62
75
void _selectOption (String option) {
@@ -171,6 +184,11 @@ class _GSSelectState extends State<GSSelect> {
171
184
172
185
void toggleDropdown () {
173
186
if (overlayEntry == null ) {
187
+ WidgetsBinding .instance.addPostFrameCallback ((_) {
188
+ if (widget.onOpen != null ) {
189
+ widget.onOpen !();
190
+ }
191
+ });
174
192
final renderBox =
175
193
_key.currentContext! .findRenderObject () as RenderBox ;
176
194
final size = renderBox.size;
@@ -180,7 +198,7 @@ class _GSSelectState extends State<GSSelect> {
180
198
builder: (context) => Stack (
181
199
children: [
182
200
GestureDetector (
183
- onTap: _removeOverlay,
201
+ onTap: widget.closeOnOverlayClick ? _removeOverlay : null ,
184
202
behavior: HitTestBehavior .translucent,
185
203
child: Container (
186
204
color: const Color .fromARGB (0 , 228 , 9 , 9 ),
@@ -245,7 +263,7 @@ class _GSSelectState extends State<GSSelect> {
245
263
),
246
264
const SizedBox (width: 6.0 ),
247
265
Text (
248
- widget.hintText .text,
266
+ widget.initialLabel .text,
249
267
style: currentTextStyle? .copyWith (
250
268
color: textStyler.color
251
269
? .getColor (context)
@@ -284,9 +302,13 @@ class _GSSelectState extends State<GSSelect> {
284
302
onPressed: () {
285
303
if (! isDisabled) {
286
304
_selectOption (option);
287
- if (widget.onChanged != null ) {
288
- widget.onChanged !(option);
289
- }
305
+ WidgetsBinding .instance
306
+ .addPostFrameCallback ((_) {
307
+ if (widget.onValueChange !=
308
+ null ) {
309
+ widget.onValueChange !(option);
310
+ }
311
+ });
290
312
}
291
313
},
292
314
// select options
@@ -409,65 +431,71 @@ class _GSSelectState extends State<GSSelect> {
409
431
selectVariant: selectVariant,
410
432
headerFontSize: headerFontSize,
411
433
textSize: textSize,
412
- child: IntrinsicWidth (
413
- child: FocusableActionDetector (
414
- onShowHoverHighlight: (value) {
415
- setState (() => _isHovered = value);
416
- },
417
- child: CompositedTransformTarget (
418
- link: _layerLink,
419
- child: GsGestureDetector (
420
- key: _key,
421
- onPressed: toggleDropdown,
422
- // select box
423
- child: Container (
424
- padding: widget.style? .padding ??
425
- triggerStyler.padding ??
426
- const EdgeInsets .symmetric (horizontal: 15 ),
427
- height: triggerStyler.height,
428
- width: triggerStyler.width,
429
- decoration: BoxDecoration (
430
- color: const Color .fromARGB (0 , 0 , 0 , 0 ),
431
- // triggerStyler.bg?.getColor(context),
432
- border: widget.variant == GSSelectVariants .underlined
433
- ? Border (
434
- bottom: BorderSide (
435
- color: borderColor ??
436
- triggerStyler.borderColor!
437
- .getColor (context),
434
+ child: Opacity (
435
+ opacity: widget.isDisabled == true ? 0.7 : 1 ,
436
+ child: IntrinsicWidth (
437
+ child: FocusableActionDetector (
438
+ onShowHoverHighlight: (value) {
439
+ widget.isDisabled == true
440
+ ? null
441
+ : setState (() => _isHovered = value);
442
+ },
443
+ child: CompositedTransformTarget (
444
+ link: _layerLink,
445
+ child: GsGestureDetector (
446
+ key: _key,
447
+ onPressed:
448
+ widget.isDisabled == true ? null : toggleDropdown,
449
+ // select box
450
+ child: Container (
451
+ padding: widget.style? .padding ??
452
+ triggerStyler.padding ??
453
+ const EdgeInsets .symmetric (horizontal: 15 ),
454
+ height: triggerStyler.height,
455
+ width: triggerStyler.width,
456
+ decoration: BoxDecoration (
457
+ color: const Color .fromARGB (0 , 0 , 0 , 0 ),
458
+ // triggerStyler.bg?.getColor(context),
459
+ border: widget.variant == GSSelectVariants .underlined
460
+ ? Border (
461
+ bottom: BorderSide (
462
+ color: borderColor ??
463
+ triggerStyler.borderColor!
464
+ .getColor (context),
465
+ width: borderWidth ??
466
+ triggerStyler.borderBottomWidth ??
467
+ 0 ,
468
+ ),
469
+ )
470
+ : Border .all (
438
471
width: borderWidth ??
439
472
triggerStyler.borderBottomWidth ??
440
473
0 ,
474
+ color: borderColor ??
475
+ triggerStyler.borderColor!
476
+ .getColor (context),
477
+ ),
478
+ borderRadius: BorderRadius .circular (
479
+ triggerStyler.borderRadius ?? 0 ),
480
+ ),
481
+ child: Row (
482
+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
483
+ mainAxisSize: MainAxisSize .min,
484
+ children: [
485
+ if (selectedOption != null )
486
+ Expanded (
487
+ child: Text (
488
+ selectedOption! ,
489
+ overflow: TextOverflow .fade,
490
+ softWrap: false ,
491
+ style: currentTextStyle,
441
492
),
442
493
)
443
- : Border .all (
444
- width: borderWidth ??
445
- triggerStyler.borderBottomWidth ??
446
- 0 ,
447
- color: borderColor ??
448
- triggerStyler.borderColor!
449
- .getColor (context),
450
- ),
451
- borderRadius: BorderRadius .circular (
452
- triggerStyler.borderRadius ?? 0 ),
453
- ),
454
- child: Row (
455
- mainAxisAlignment: MainAxisAlignment .spaceBetween,
456
- mainAxisSize: MainAxisSize .min,
457
- children: [
458
- if (selectedOption != null )
459
- Expanded (
460
- child: Text (
461
- selectedOption! ,
462
- overflow: TextOverflow .fade,
463
- softWrap: false ,
464
- style: currentTextStyle,
465
- ),
466
- )
467
- else
468
- widget.hintText,
469
- widget.icon
470
- ],
494
+ else
495
+ widget.initialLabel,
496
+ widget.icon
497
+ ],
498
+ ),
471
499
),
472
500
),
473
501
),
0 commit comments