Skip to content

Commit

Permalink
feat: checklist completion progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasn committed Nov 18, 2024
1 parent fff9500 commit 39a6a56
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 3 deletions.
24 changes: 24 additions & 0 deletions lib/features/tasks/state/checklist_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:async';

import 'package:lotti/classes/journal_entities.dart';
import 'package:lotti/database/database.dart';
import 'package:lotti/features/tasks/state/checklist_item_controller.dart';
import 'package:lotti/get_it.dart';
import 'package:lotti/logic/persistence_logic.dart';
import 'package:lotti/services/db_notification.dart';
Expand Down Expand Up @@ -102,3 +103,26 @@ class ChecklistController extends _$ChecklistController {
}
}
}

@riverpod
class ChecklistCompletionController extends _$ChecklistCompletionController {
ChecklistCompletionController();

@override
Future<double> build({required String id}) async {
final checklistData =
ref.watch(checklistControllerProvider(id: id)).value?.data;

final linkedIds = checklistData?.linkedChecklistItems ?? <String>[];
final total = linkedIds.length;

final linkedChecklistItems = linkedIds
.map((id) => ref.watch(checklistItemControllerProvider(id: id)).value);

final completed = linkedChecklistItems
.where((item) => item?.data.isChecked ?? false)
.length;

return total == 0 ? 0.0 : completed / total;
}
}
151 changes: 151 additions & 0 deletions lib/features/tasks/state/checklist_controller.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions lib/features/tasks/ui/checklist_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ class ChecklistWidget extends StatefulWidget {
required this.itemIds,
required this.onTitleSave,
required this.onCreateChecklistItem,
this.completionRate = 0.0,
super.key,
});

final String title;
final List<String> itemIds;
final StringCallback onTitleSave;
final StringCallback onCreateChecklistItem;
final double completionRate;

@override
State<ChecklistWidget> createState() => _ChecklistWidgetState();
Expand Down Expand Up @@ -69,8 +71,8 @@ class _ChecklistWidgetState extends State<ChecklistWidget> {
crossFadeState:
_isEditing ? CrossFadeState.showFirst : CrossFadeState.showSecond,
),
subtitle: const LinearProgressIndicator(
value: 0.87,
subtitle: LinearProgressIndicator(
value: widget.completionRate,
semanticsLabel: 'Checklist progress',
),
children: [
Expand Down Expand Up @@ -107,6 +109,9 @@ class ChecklistWrapper extends ConsumerWidget {
final notifier = ref.read(provider.notifier);
final checklist = ref.watch(provider).value;

final completionRate =
ref.watch(checklistCompletionControllerProvider(id: entryId)).value;

if (checklist == null) {
return const SizedBox.shrink();
}
Expand All @@ -116,6 +121,7 @@ class ChecklistWrapper extends ConsumerWidget {
itemIds: checklist.data.linkedChecklistItems,
onTitleSave: notifier.updateTitle,
onCreateChecklistItem: notifier.createChecklistItem,
completionRate: completionRate ?? 0.0,
);
}
}
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.531+2731
version: 0.9.531+2732

msix_config:
display_name: LottiApp
Expand Down

0 comments on commit 39a6a56

Please sign in to comment.