Skip to content

Commit

Permalink
Fix onChanged being called on every controller update (#202)
Browse files Browse the repository at this point in the history
  • Loading branch information
helightdev authored Nov 27, 2024
1 parent 42ad3a2 commit c7c1d32
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions lib/src/components/slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,15 @@ class _ShadSliderState extends State<ShadSlider> {
initialValue: widget.initialValue!,
);

@override
void initState() {
super.initState();
controller.addListener(onChanged);
}

@override
void dispose() {
controller.removeListener(onChanged);
// dispose the internal controller
if (widget.controller == null) {
controller.dispose();
}
super.dispose();
}

void onChanged() {
widget.onChanged?.call(controller.value);
}

@override
Widget build(BuildContext context) {
final theme = ShadTheme.of(context);
Expand Down Expand Up @@ -182,7 +171,10 @@ class _ShadSliderState extends State<ShadSlider> {
mouseCursor: widget.enabled
? effectiveMouseCursor
: effectiveDisabledMouseCursor,
onChanged: widget.enabled ? (v) => controller.value = v : null,
onChanged: widget.enabled ? (v) {
controller.value = v;
widget.onChanged?.call(v);
} : null,
autofocus: widget.autofocus,
focusNode: widget.focusNode,
onChangeStart: widget.onChangeStart,
Expand Down

0 comments on commit c7c1d32

Please sign in to comment.