diff --git a/example/lib/pages/components/checkbox_example.dart b/example/lib/pages/components/checkbox_example.dart index 28e0f41a..4249cd27 100644 --- a/example/lib/pages/components/checkbox_example.dart +++ b/example/lib/pages/components/checkbox_example.dart @@ -78,6 +78,7 @@ Row getCheckBoxRow({required bool isEnabled, bool isSharp = true}) { ZetaCheckbox( rounded: !isSharp, onChanged: isEnabled ? (value) => {} : null, + value: false, ) ]); } diff --git a/lib/src/components/checkbox/checkbox.dart b/lib/src/components/checkbox/checkbox.dart index 5839df6b..6613302b 100644 --- a/lib/src/components/checkbox/checkbox.dart +++ b/lib/src/components/checkbox/checkbox.dart @@ -8,8 +8,7 @@ import '../../../zeta_flutter.dart'; class ZetaCheckbox extends FormField { /// Constructs a [ZetaCheckbox]. ZetaCheckbox({ - super.key, - this.value = false, + required this.value, this.label, this.onChanged, this.rounded = true, @@ -17,6 +16,7 @@ class ZetaCheckbox extends FormField { super.validator, super.autovalidateMode, super.restorationId, + super.key, }) : super( initialValue: value, enabled: onChanged != null, @@ -122,19 +122,7 @@ class _Checkbox extends StatefulWidget { } class _CheckboxState extends State<_Checkbox> { - bool get _checked => widget.useIndeterminate ? widget.value : (widget.value ?? false); - - bool? get _updatedValue { - if (widget.useIndeterminate) { - if (widget.value) { - return null; - } else { - return true; - } - } else { - return !_checked; - } - } + bool get _checked => widget.value; bool _isFocused = false; bool _isHovered = false; @@ -152,7 +140,7 @@ class _CheckboxState extends State<_Checkbox> { ? FocusableActionDetector( onFocusChange: (bool focus) => setState(() => _isFocused = focus), child: GestureDetector( - onTap: !widget.disabled ? () => widget.onChanged.call(_updatedValue) : null, + onTap: !widget.disabled ? () => widget.onChanged.call(!_checked) : null, child: _buildContent(context), ), ) @@ -164,17 +152,17 @@ class _CheckboxState extends State<_Checkbox> { Flex _buildContent(BuildContext context) { final theme = Zeta.of(context); - final icon = _checked && !_checked + final icon = !_checked ? const SizedBox.shrink() : Icon( - _checked + !widget.useIndeterminate ? widget.rounded ? ZetaIcons.check_mark_round : ZetaIcons.check_mark_sharp : widget.rounded ? ZetaIcons.remove_round : ZetaIcons.remove_sharp, - color: !widget.disabled ? theme.colors.white : theme.colors.textDisabled, + color: !widget.disabled ? theme.colors.white : theme.colors.iconDisabled, size: ZetaSpacing.x3_5, );