Skip to content

Commit c537692

Browse files
added callback functions onOpen , onClose, onValueChange
1 parent e7afbdd commit c537692

File tree

8 files changed

+106
-75
lines changed

8 files changed

+106
-75
lines changed

example/lib/widgets/components/widgets/select_example.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,19 @@ GSSelect(
7878
body: BaseLayout(
7979
code: code,
8080
component: GSSelect(
81+
onClose: () {
82+
setState(() {});
83+
},
84+
onOpen: () {},
85+
onValueChange: (value) {},
8186
content: GSSelectContent(
8287
style: GSStyle(
8388
width: 300,
8489
height: 200,
8590
padding: const EdgeInsets.symmetric(horizontal: 15),
8691
),
8792
),
88-
hintText: const GSSelectHeaderText("Select option"),
93+
initialLabel: const GSSelectHeaderText("Select option"),
8994
style: GSStyle(
9095
width: 300,
9196
),

example/lib/widgets/storybook/widgets/select_story.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ final class SelectStory extends StoryWidget {
2323
height: 200,
2424
padding: const EdgeInsets.all(5)),
2525
),
26-
hintText: const GSSelectHeaderText("Select option"),
26+
initialLabel: const GSSelectHeaderText("Select option"),
2727
icon: const GSSelectIcon(
2828
iconData: Icons.arrow_drop_down_outlined,
2929
),

lib/src/widgets/gs_app/gs_app.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ class _GSAppState extends State<GSApp> {
284284
localeListResolutionCallback: widget.localeListResolutionCallback,
285285
supportedLocales: widget.supportedLocales,
286286
showPerformanceOverlay: widget.showPerformanceOverlay,
287-
checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages,
288-
checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers,
287+
// checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages,
288+
// checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers,
289289
showSemanticsDebugger: widget.showSemanticsDebugger,
290290
debugShowCheckedModeBanner: widget.debugShowCheckedModeBanner,
291291
shortcuts: widget.shortcuts,
@@ -310,8 +310,8 @@ class _GSAppState extends State<GSApp> {
310310
localeResolutionCallback: widget.localeResolutionCallback,
311311
supportedLocales: widget.supportedLocales,
312312
showPerformanceOverlay: widget.showPerformanceOverlay,
313-
checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages,
314-
checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers,
313+
// checkerboardRasterCacheImages: widget.checkerboardRasterCacheImages,
314+
// checkerboardOffscreenLayers: widget.checkerboardOffscreenLayers,
315315
showSemanticsDebugger: widget.showSemanticsDebugger,
316316
debugShowCheckedModeBanner: widget.debugShowCheckedModeBanner,
317317
shortcuts: widget.shortcuts,

lib/src/widgets/gs_form_control/gs_form_control.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Form Control Compatible Components:
1616
class GSFormControl extends StatefulWidget {
1717
final GlobalKey<FormState> formKey;
1818
final Widget child;
19-
final PopInvokedCallback? onPopInvoked;
19+
// final PopInvokedCallback? onPopInvoked;
2020
final VoidCallback? onChanged;
2121
final AutovalidateMode autovalidateMode;
2222
final bool? canPop;
@@ -32,7 +32,7 @@ class GSFormControl extends StatefulWidget {
3232
const GSFormControl({
3333
super.key,
3434
required this.child,
35-
this.onPopInvoked,
35+
// this.onPopInvoked,
3636
this.onChanged,
3737
this.autovalidateMode = AutovalidateMode.disabled,
3838
this.canPop,
@@ -84,7 +84,7 @@ class _GSFormControlState extends State<GSFormControl> {
8484
key: widget.formKey,
8585
canPop: widget.canPop,
8686
onChanged: widget.onChanged,
87-
onPopInvoked: widget.onPopInvoked,
87+
// onPopInvoked: widget.onPopInvoked,
8888
autovalidateMode: widget.autovalidateMode,
8989
child: widget.child,
9090
),

lib/src/widgets/gs_radio/gs_radio_icon.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import 'package:gluestack_ui/src/style/gs_config_style_internal.dart';
22
import 'package:gluestack_ui/src/style/style_resolver.dart';
33
import 'package:gluestack_ui/src/widgets/gs_radio/gs_radio_icon_style.dart';
44

5-
import 'package:gluestack_ui/src/widgets/gs_radio/gs_radio_raw.dart';
6-
75
class GSRadioIcon<T> extends StatelessWidget {
86
final Color? activeColor;
97
final bool autofocus;

lib/src/widgets/gs_radio/gs_radio_raw.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import 'package:flutter/foundation.dart';
22
import 'package:flutter/cupertino.dart';
33
import 'package:gluestack_ui/gluestack_ui.dart';
4-
import 'gs_toggleable.dart';
54

65
const Size _size = Size(18.0, 18.0);
76
const double _kOuterRadius = 8.0;

lib/src/widgets/gs_radio/public.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ export 'gs_radio_icon.dart';
22
export 'gs_radio_provider.dart';
33
export 'gs_radio_text.dart';
44
export 'gs_radio.dart';
5+
export 'gs_radio_raw.dart';

lib/src/widgets/gs_select/gs_select.dart

Lines changed: 91 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ class GSSelect extends StatefulWidget {
1616
final GSSelectSizes? size;
1717
final GSSelectVariants? variant;
1818
final GSStyle? style;
19-
final GSSelectHeaderText hintText;
19+
final GSSelectHeaderText initialLabel;
2020
final GSSelectIcon icon;
2121
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;
2327

2428
const GSSelect({
2529
super.key,
@@ -28,10 +32,14 @@ class GSSelect extends StatefulWidget {
2832
required this.options,
2933
this.disabledOptions,
3034
required this.icon,
31-
required this.hintText,
35+
required this.initialLabel,
3236
this.style,
33-
this.onChanged,
37+
this.onValueChange,
38+
this.isDisabled = false,
39+
this.closeOnOverlayClick = true,
3440
required this.content,
41+
this.onClose,
42+
this.onOpen,
3543
});
3644

3745
@override
@@ -57,6 +65,11 @@ class _GSSelectState extends State<GSSelect> {
5765
overlayEntry?.remove();
5866
overlayEntry = null;
5967
hoveredIndex = null;
68+
WidgetsBinding.instance.addPostFrameCallback((_) {
69+
if (widget.onClose != null) {
70+
widget.onClose!();
71+
}
72+
});
6073
}
6174

6275
void _selectOption(String option) {
@@ -171,6 +184,11 @@ class _GSSelectState extends State<GSSelect> {
171184

172185
void toggleDropdown() {
173186
if (overlayEntry == null) {
187+
WidgetsBinding.instance.addPostFrameCallback((_) {
188+
if (widget.onOpen != null) {
189+
widget.onOpen!();
190+
}
191+
});
174192
final renderBox =
175193
_key.currentContext!.findRenderObject() as RenderBox;
176194
final size = renderBox.size;
@@ -180,7 +198,7 @@ class _GSSelectState extends State<GSSelect> {
180198
builder: (context) => Stack(
181199
children: [
182200
GestureDetector(
183-
onTap: _removeOverlay,
201+
onTap: widget.closeOnOverlayClick ? _removeOverlay : null,
184202
behavior: HitTestBehavior.translucent,
185203
child: Container(
186204
color: const Color.fromARGB(0, 228, 9, 9),
@@ -245,7 +263,7 @@ class _GSSelectState extends State<GSSelect> {
245263
),
246264
const SizedBox(width: 6.0),
247265
Text(
248-
widget.hintText.text,
266+
widget.initialLabel.text,
249267
style: currentTextStyle?.copyWith(
250268
color: textStyler.color
251269
?.getColor(context)
@@ -284,9 +302,13 @@ class _GSSelectState extends State<GSSelect> {
284302
onPressed: () {
285303
if (!isDisabled) {
286304
_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+
});
290312
}
291313
},
292314
// select options
@@ -409,65 +431,71 @@ class _GSSelectState extends State<GSSelect> {
409431
selectVariant: selectVariant,
410432
headerFontSize: headerFontSize,
411433
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(
438471
width: borderWidth ??
439472
triggerStyler.borderBottomWidth ??
440473
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,
441492
),
442493
)
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+
),
471499
),
472500
),
473501
),

0 commit comments

Comments
 (0)