Added headless switch

Fixed UI
This commit is contained in:
Alessandro Autiero
2022-10-04 17:28:10 +02:00
parent 9a759ac9e3
commit c27dbaa306
20 changed files with 389 additions and 225 deletions

View File

@@ -3,17 +3,17 @@ import 'package:get/get.dart';
import 'package:system_theme/system_theme.dart';
class SmartSwitch extends StatefulWidget {
final String label;
final String? label;
final bool enabled;
final Function()? onDisabledPress;
final Rx<bool> value;
const SmartSwitch(
{Key? key,
required this.label,
required this.value,
this.enabled = true,
this.onDisabledPress})
required this.value,
this.label,
this.enabled = true,
this.onDisabledPress})
: super(key: key);
@override
@@ -23,22 +23,32 @@ class SmartSwitch extends StatefulWidget {
class _SmartSwitchState extends State<SmartSwitch> {
@override
Widget build(BuildContext context) {
return widget.label == null ? _createSwitch() : _createLabel();
}
InfoLabel _createLabel() {
return InfoLabel(
label: widget.label,
child: Obx(() => ToggleSwitch(
enabled: widget.enabled,
onDisabledPress: widget.onDisabledPress,
checked: widget.value.value,
onChanged: _onChanged,
style: ToggleSwitchThemeData.standard(ThemeData(
checkedColor: _toolTipColor.withOpacity(_checkedOpacity),
uncheckedColor: _toolTipColor.withOpacity(_uncheckedOpacity),
borderInputColor: _toolTipColor.withOpacity(_uncheckedOpacity),
accentColor: _bodyColor
.withOpacity(widget.value.value
? _checkedOpacity
: _uncheckedOpacity)
.toAccentColor())))));
label: widget.label!,
child: _createSwitch()
);
}
Widget _createSwitch() {
return Obx(() => ToggleSwitch(
enabled: widget.enabled,
onDisabledPress: widget.onDisabledPress,
checked: widget.value.value,
onChanged: _onChanged,
style: ToggleSwitchThemeData.standard(ThemeData(
checkedColor: _toolTipColor.withOpacity(_checkedOpacity),
uncheckedColor: _toolTipColor.withOpacity(_uncheckedOpacity),
borderInputColor: _toolTipColor.withOpacity(_uncheckedOpacity),
accentColor: _bodyColor
.withOpacity(widget.value.value
? _checkedOpacity
: _uncheckedOpacity)
.toAccentColor())))
);
}
Color get _toolTipColor =>