From 455798cd877264c99db049d3cf34b62cbbd370a2 Mon Sep 17 00:00:00 2001 From: Matthias Nehlsen Date: Mon, 18 Nov 2024 02:49:47 +0100 Subject: [PATCH] feat: update checkbox, e.g. from sync --- .../state/checklist_item_controller.dart | 4 +- .../tasks/ui/checkbox_item_widget.dart | 85 ++++++++++++------- .../tasks/ui/checkbox_item_wrapper.dart | 4 +- lib/features/tasks/ui/checklist_widget.dart | 27 ++++-- pubspec.yaml | 2 +- 5 files changed, 79 insertions(+), 43 deletions(-) diff --git a/lib/features/tasks/state/checklist_item_controller.dart b/lib/features/tasks/state/checklist_item_controller.dart index 67cf1c1b3..ba708f4be 100644 --- a/lib/features/tasks/state/checklist_item_controller.dart +++ b/lib/features/tasks/state/checklist_item_controller.dart @@ -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, ), ); diff --git a/lib/features/tasks/ui/checkbox_item_widget.dart b/lib/features/tasks/ui/checkbox_item_widget.dart index 50bf997aa..463689275 100644 --- a/lib/features/tasks/ui/checkbox_item_widget.dart +++ b/lib/features/tasks/ui/checkbox_item_widget.dart @@ -35,39 +35,62 @@ class _CheckboxItemWidgetState extends State { super.initState(); } + @override + void didChangeDependencies() { + setState(() { + _isChecked = widget.isChecked; + }); + + super.didChangeDependencies(); + } + @override Widget build(BuildContext context) { return CheckboxListTile( - title: GestureDetector( - onTap: () { - setState(() { - _isEditing = true; - }); - }, - child: AnimatedCrossFade( - duration: checklistCrossFadeDuration, - firstChild: TitleTextField( - initialValue: widget.title, - onSave: (title) { - setState(() { - _isEditing = false; - }); - widget.onTitleChange?.call(title); - }, - resetToInitialValue: true, - onClear: () { - setState(() { - _isEditing = false; - }); - }, - ), - secondChild: SizedBox( - width: double.infinity, - child: Text(widget.title), + title: AnimatedCrossFade( + duration: checklistCrossFadeDuration, + firstChild: TitleTextField( + initialValue: widget.title, + onSave: (title) { + setState(() { + _isEditing = false; + }); + widget.onTitleChange?.call(title); + }, + resetToInitialValue: true, + onClear: () { + setState(() { + _isEditing = false; + }); + }, + ), + secondChild: SizedBox( + width: double.infinity, + child: Row( + children: [ + Flexible( + child: Text( + widget.title, + softWrap: true, + maxLines: 3, + ), + ), + IconButton( + icon: const Icon( + Icons.edit, + size: 20, + ), + onPressed: () { + setState(() { + _isEditing = !_isEditing; + }); + }, + ), + ], ), - crossFadeState: - _isEditing ? CrossFadeState.showFirst : CrossFadeState.showSecond, ), + crossFadeState: + _isEditing ? CrossFadeState.showFirst : CrossFadeState.showSecond, ), value: _isChecked, controlAffinity: ListTileControlAffinity.leading, @@ -81,10 +104,12 @@ class _CheckboxItemWidgetState extends State { ) : null, onChanged: (bool? value) { + final isChecked = value ?? false; setState(() { - _isChecked = value ?? false; + _isChecked = isChecked; }); - widget.onChanged(_isChecked); + + widget.onChanged(isChecked); }, ); } diff --git a/lib/features/tasks/ui/checkbox_item_wrapper.dart b/lib/features/tasks/ui/checkbox_item_wrapper.dart index 57aedf431..3107fc0f3 100644 --- a/lib/features/tasks/ui/checkbox_item_wrapper.dart +++ b/lib/features/tasks/ui/checkbox_item_wrapper.dart @@ -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, ); }, diff --git a/lib/features/tasks/ui/checklist_widget.dart b/lib/features/tasks/ui/checklist_widget.dart index 158872928..72be5c122 100644 --- a/lib/features/tasks/ui/checklist_widget.dart +++ b/lib/features/tasks/ui/checklist_widget.dart @@ -56,7 +56,13 @@ class _ChecklistWidgetState extends State { ), secondChild: Row( children: [ - Text(widget.title), + Flexible( + child: Text( + widget.title, + softWrap: true, + maxLines: 3, + ), + ), IconButton( icon: const Icon( Icons.edit, @@ -73,14 +79,17 @@ class _ChecklistWidgetState extends State { 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: [ diff --git a/pubspec.yaml b/pubspec.yaml index 411c088a5..8d8089cae 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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