diff --git a/lib/src/Toggles/Switcher/switcher.toggle.dart b/lib/src/Toggles/Switcher/switcher.toggle.dart index f636f6f..f1e89fd 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 bool Function(bool)? onStateChanged; + final Future Function(bool)? onStateChanged; //s1 -- Configuration final AstromicToggleConfiguration? configuration; //s1 -- Style @@ -86,13 +86,14 @@ class AstromicSwitcherToggleState extends State { } //SECTION - Action Callbacks - _onTap(bool newValue) { + _onTap(bool newValue) async { + if (widget.onStateChanged != null) { + _currentState = await widget.onStateChanged!(_currentState); + } else { + _currentState = newValue; + } setState(() { - if (widget.onStateChanged != null) { - _currentState = widget.onStateChanged!(_currentState); - } else { - _currentState = newValue; - } + // }); } //!SECTION diff --git a/lib/src/Toggles/toggles.astromic.dart b/lib/src/Toggles/toggles.astromic.dart index 74fcc8c..c3b2890 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, - bool Function(bool)? onStateChanged, + Future Function(bool)? onStateChanged, AstromicToggleConfiguration? configuration, AstromicSwitcherToggleStyle Function(bool isEnabled, bool isSelected)? style, Widget Function(bool isEnabled, bool isSelected)? label,