Skip to content

Commit

Permalink
feat: update checkbox, e.g. from sync
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasn committed Nov 18, 2024
1 parent f0347cb commit 8e0a12f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/features/tasks/state/checklist_item_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ class ChecklistItemController extends _$ChecklistItemController {
return res;
}

void toggleChecked() {
void toggleChecked({required bool checked}) {
final current = state.value;
final data = current?.data;
if (current != null && data != null) {
final updated = current.copyWith(
data: data.copyWith(
isChecked: !data.isChecked,
isChecked: checked,
),
);

Expand Down
15 changes: 13 additions & 2 deletions lib/features/tasks/ui/checkbox_item_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ class _CheckboxItemWidgetState extends State<CheckboxItemWidget> {
super.initState();
}

@override
void didChangeDependencies() {
setState(() {
_isChecked = widget.isChecked;
});

super.didChangeDependencies();
}

@override
Widget build(BuildContext context) {
return CheckboxListTile(
Expand Down Expand Up @@ -81,10 +90,12 @@ class _CheckboxItemWidgetState extends State<CheckboxItemWidget> {
)
: null,
onChanged: (bool? value) {
final isChecked = value ?? false;
setState(() {
_isChecked = value ?? false;
_isChecked = isChecked;
});
widget.onChanged(_isChecked);

widget.onChanged(isChecked);
},
);
}
Expand Down
4 changes: 3 additions & 1 deletion lib/features/tasks/ui/checkbox_item_wrapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class CheckboxItemWrapper extends ConsumerWidget {
return CheckboxItemWidget(
title: item.data.title,
isChecked: item.data.isChecked,
onChanged: (_) => ref.read(provider.notifier).toggleChecked(),
onChanged: (checked) => ref.read(provider.notifier).toggleChecked(
checked: checked,
),
onTitleChange: ref.read(provider.notifier).updateTitle,
);
},
Expand Down
27 changes: 18 additions & 9 deletions lib/features/tasks/ui/checklist_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ class _ChecklistWidgetState extends State<ChecklistWidget> {
),
secondChild: Row(
children: [
Text(widget.title),
Flexible(
child: Text(
widget.title,
softWrap: true,
maxLines: 3,
),
),
IconButton(
icon: const Icon(
Icons.edit,
Expand All @@ -73,14 +79,17 @@ class _ChecklistWidgetState extends State<ChecklistWidget> {
crossFadeState:
_isEditing ? CrossFadeState.showFirst : CrossFadeState.showSecond,
),
subtitle: ClipRRect(
borderRadius: BorderRadius.circular(3),
child: LinearProgressIndicator(
minHeight: 5,
color: successColor,
backgroundColor: successColor.desaturate().withOpacity(0.3),
value: widget.completionRate,
semanticsLabel: 'Checklist progress',
subtitle: Padding(
padding: const EdgeInsets.only(top: 10),
child: ClipRRect(
borderRadius: BorderRadius.circular(3),
child: LinearProgressIndicator(
minHeight: 5,
color: successColor,
backgroundColor: successColor.desaturate().withOpacity(0.3),
value: widget.completionRate,
semanticsLabel: 'Checklist progress',
),
),
),
children: [
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: lotti
description: Achieve your goals and keep your data private with Lotti.
publish_to: 'none'
version: 0.9.532+2733
version: 0.9.532+2735

msix_config:
display_name: LottiApp
Expand Down

0 comments on commit 8e0a12f

Please sign in to comment.