Skip to content

Commit

Permalink
updating indeterminate
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecoomber committed May 29, 2024
1 parent 4ea8e26 commit fba49bb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
1 change: 1 addition & 0 deletions example/lib/pages/components/checkbox_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Row getCheckBoxRow({required bool isEnabled, bool isSharp = true}) {
ZetaCheckbox(
rounded: !isSharp,
onChanged: isEnabled ? (value) => {} : null,
value: false,
)
]);
}
26 changes: 7 additions & 19 deletions lib/src/components/checkbox/checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import '../../../zeta_flutter.dart';
class ZetaCheckbox extends FormField<bool> {
/// Constructs a [ZetaCheckbox].
ZetaCheckbox({
super.key,
this.value = false,
required this.value,
this.label,
this.onChanged,
this.rounded = true,
this.useIndeterminate = false,
super.validator,
super.autovalidateMode,
super.restorationId,
super.key,
}) : super(
initialValue: value,
enabled: onChanged != null,
Expand Down Expand Up @@ -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;
Expand All @@ -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),
),
)
Expand All @@ -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,
);

Expand Down

0 comments on commit fba49bb

Please sign in to comment.