[FEAT] Dismiss handler for toggle

This commit is contained in:
2026-01-25 14:02:07 +02:00
parent ad116fd32b
commit 5690525bd0
2 changed files with 8 additions and 5 deletions

View File

@@ -32,7 +32,7 @@ class AstromicSwitcherToggle extends StatefulWidget {
/// If provided, you have to change the variable yourself in the onStateChanged! /// If provided, you have to change the variable yourself in the onStateChanged!
final bool? stateVariable; final bool? stateVariable;
final bool? initialState; final bool? initialState;
final void Function(bool)? onStateChanged; final bool Function(bool)? onStateChanged;
//s1 -- Configuration //s1 -- Configuration
final AstromicToggleConfiguration? configuration; final AstromicToggleConfiguration? configuration;
//s1 -- Style //s1 -- Style
@@ -88,8 +88,11 @@ class AstromicSwitcherToggleState extends State<AstromicSwitcherToggle> {
//SECTION - Action Callbacks //SECTION - Action Callbacks
_onTap(bool newValue) { _onTap(bool newValue) {
setState(() { setState(() {
if (widget.onStateChanged != null) {
_currentState = widget.onStateChanged!(_currentState);
} else {
_currentState = newValue; _currentState = newValue;
if (widget.onStateChanged != null) widget.onStateChanged!(_currentState); }
}); });
} }
//!SECTION //!SECTION
@@ -133,7 +136,7 @@ class AstromicSwitcherToggleState extends State<AstromicSwitcherToggle> {
inactiveIcon: _style.innerInactiveWidget, inactiveIcon: _style.innerInactiveWidget,
// //
padding: _style.togglePadding, padding: _style.togglePadding,
onToggle: !_config.isEnabled? (bool v){}: (bool s) => _onTap(s), onToggle: !_config.isEnabled ? (bool v) {} : (bool s) => _onTap(s),
), ),
//S1 -- Label Spacing //S1 -- Label Spacing
if (_config.withLabel) SizedBox(width: _style.labelSpacing), if (_config.withLabel) SizedBox(width: _style.labelSpacing),

View File

@@ -42,7 +42,7 @@ class AstromicToggles {
static Widget switcher({ static Widget switcher({
bool? stateVariable, bool? stateVariable,
bool? initialState, bool? initialState,
void Function(bool)? onStateChanged, bool Function(bool)? onStateChanged,
AstromicToggleConfiguration? configuration, AstromicToggleConfiguration? configuration,
AstromicSwitcherToggleStyle Function(bool isEnabled, bool isSelected)? style, AstromicSwitcherToggleStyle Function(bool isEnabled, bool isSelected)? style,
Widget Function(bool isEnabled, bool isSelected)? label, Widget Function(bool isEnabled, bool isSelected)? label,