diff --git a/lib/src/Toggles/Switcher/switcher.toggle.dart b/lib/src/Toggles/Switcher/switcher.toggle.dart index 12734e2..f636f6f 100644 --- a/lib/src/Toggles/Switcher/switcher.toggle.dart +++ b/lib/src/Toggles/Switcher/switcher.toggle.dart @@ -32,7 +32,7 @@ class AstromicSwitcherToggle extends StatefulWidget { /// If provided, you have to change the variable yourself in the onStateChanged! final bool? stateVariable; final bool? initialState; - final void Function(bool)? onStateChanged; + final bool Function(bool)? onStateChanged; //s1 -- Configuration final AstromicToggleConfiguration? configuration; //s1 -- Style @@ -88,8 +88,11 @@ class AstromicSwitcherToggleState extends State { //SECTION - Action Callbacks _onTap(bool newValue) { setState(() { - _currentState = newValue; - if (widget.onStateChanged != null) widget.onStateChanged!(_currentState); + if (widget.onStateChanged != null) { + _currentState = widget.onStateChanged!(_currentState); + } else { + _currentState = newValue; + } }); } //!SECTION @@ -133,7 +136,7 @@ class AstromicSwitcherToggleState extends State { inactiveIcon: _style.innerInactiveWidget, // padding: _style.togglePadding, - onToggle: !_config.isEnabled? (bool v){}: (bool s) => _onTap(s), + onToggle: !_config.isEnabled ? (bool v) {} : (bool s) => _onTap(s), ), //S1 -- Label Spacing if (_config.withLabel) SizedBox(width: _style.labelSpacing), diff --git a/lib/src/Toggles/toggles.astromic.dart b/lib/src/Toggles/toggles.astromic.dart index 8e568b5..74fcc8c 100644 --- a/lib/src/Toggles/toggles.astromic.dart +++ b/lib/src/Toggles/toggles.astromic.dart @@ -42,7 +42,7 @@ class AstromicToggles { static Widget switcher({ bool? stateVariable, bool? initialState, - void Function(bool)? onStateChanged, + bool Function(bool)? onStateChanged, AstromicToggleConfiguration? configuration, AstromicSwitcherToggleStyle Function(bool isEnabled, bool isSelected)? style, Widget Function(bool isEnabled, bool isSelected)? label,