From 357cf7282e323cbf2579c01c266ff89799f9c1b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Chiotti?= <44336112+maelchiotti@users.noreply.github.com> Date: Sun, 2 Feb 2025 18:19:37 +0100 Subject: [PATCH] [372] feat: add checklist note --- lib/app.dart | 6 +- lib/common/actions/notes/add.dart | 2 + lib/common/constants/paddings.dart | 6 +- .../navigation/app_bars/editor_app_bar.dart | 2 +- lib/common/preferences/preference_key.dart | 2 +- .../preferences/watched_preferences.dart | 2 +- lib/common/system/quick_actions_utils.dart | 4 +- lib/common/system/share_utils.dart | 4 +- lib/l10n/translations/app_en.arb | 8 ++ lib/models/note/note.dart | 12 +- lib/models/note/types/checklist_note.dart | 125 ++++++++++++++++++ .../note_type.dart} | 10 +- .../plain_text_note.dart | 9 +- .../{rich_text => types}/rich_text_note.dart | 7 +- lib/pages/editor/editor_page.dart | 34 ++--- .../checklist_editor/checklist_editor.dart | 47 +++++++ .../widgets/plain_text/plain_text_editor.dart | 30 +++-- .../widgets/rich_text/rich_text_editor.dart | 69 +++++----- lib/pages/editor/widgets/title_editor.dart | 40 +++--- lib/pages/notes/widgets/add_note_fab.dart | 14 +- .../settings_notes_types_page.dart | 2 +- .../settings_notes_types_rich_text_page.dart | 2 +- lib/services/backup/backup_service.dart | 42 +++++- lib/services/database_service.dart | 1 + lib/services/notes/notes_service.dart | 24 +++- pubspec.lock | 16 +++ pubspec.yaml | 1 + 27 files changed, 408 insertions(+), 113 deletions(-) create mode 100644 lib/models/note/types/checklist_note.dart rename lib/models/note/{notes_types.dart => types/note_type.dart} (88%) rename lib/models/note/{plain_text => types}/plain_text_note.dart (92%) rename lib/models/note/{rich_text => types}/rich_text_note.dart (97%) create mode 100644 lib/pages/editor/widgets/checklist_editor/checklist_editor.dart diff --git a/lib/app.dart b/lib/app.dart index e1607247..22afc5dc 100644 --- a/lib/app.dart +++ b/lib/app.dart @@ -4,6 +4,7 @@ import 'package:after_layout/after_layout.dart'; import 'package:back_button_interceptor/back_button_interceptor.dart'; import 'package:dynamic_color/dynamic_color.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_checklist/checklist.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'common/actions/labels/select.dart'; @@ -135,7 +136,10 @@ class _AppState extends ConsumerState with AfterLayoutMixin { theme: lightTheme, darkTheme: darkTheme, themeMode: themeMode, - localizationsDelegates: AppLocalizations.localizationsDelegates, + localizationsDelegates: [ + ...AppLocalizations.localizationsDelegates, + ChecklistLocalizations.delegate, + ], supportedLocales: SupportedLanguage.locales, locale: LocaleUtils().appLocale, debugShowCheckedModeBanner: false, diff --git a/lib/common/actions/notes/add.dart b/lib/common/actions/notes/add.dart index 2b29cbc3..6942edae 100644 --- a/lib/common/actions/notes/add.dart +++ b/lib/common/actions/notes/add.dart @@ -21,6 +21,8 @@ Future addNote(BuildContext context, WidgetRef ref, {String? con note = content == null ? PlainTextNote.empty() : PlainTextNote.content(content); case == RichTextNote: note = content == null ? RichTextNote.empty() : RichTextNote.content(content); + case == ChecklistNote: + note = ChecklistNote.empty(); default: throw Exception('Unknown note type when creating a new note: $NoteType'); } diff --git a/lib/common/constants/paddings.dart b/lib/common/constants/paddings.dart index 39af31d7..0b6980b8 100644 --- a/lib/common/constants/paddings.dart +++ b/lib/common/constants/paddings.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; + import 'constants.dart'; // ignore_for_file: avoid_classes_with_only_static_members @@ -40,7 +41,10 @@ class Paddings { /// Padding for a page. static EdgeInsetsDirectional get page => const EdgeInsetsDirectional.all(16); - /// Padding for a page except the bottom. + /// Padding for a page (horizontal). + static EdgeInsetsDirectional get pageHorizontal => const EdgeInsetsDirectional.symmetric(horizontal: 16); + + /// Padding for a page (except the bottom). static EdgeInsetsDirectional get pageButBottom => const EdgeInsetsDirectional.only(top: 16, start: 16, end: 16); /// Padding for the end of the app bar. diff --git a/lib/common/navigation/app_bars/editor_app_bar.dart b/lib/common/navigation/app_bars/editor_app_bar.dart index 046dfd63..06d4d066 100644 --- a/lib/common/navigation/app_bars/editor_app_bar.dart +++ b/lib/common/navigation/app_bars/editor_app_bar.dart @@ -2,7 +2,7 @@ import 'package:fleather/fleather.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; -import '../../../models/note/notes_types.dart'; +import '../../../models/note/types/note_type.dart'; import '../../../pages/editor/sheets/about_sheet.dart'; import '../../../providers/notifiers/notifiers.dart'; import '../../actions/notes/copy.dart'; diff --git a/lib/common/preferences/preference_key.dart b/lib/common/preferences/preference_key.dart index d50a7e3e..df35ca2d 100644 --- a/lib/common/preferences/preference_key.dart +++ b/lib/common/preferences/preference_key.dart @@ -13,7 +13,7 @@ enum PreferenceKey { editorFont('systemDefault'), // Notes types - availableNotesTypes>(['plainText', 'richText']), + availableNotesTypes>(['plainText', 'richText', 'checklist']), defaultShortcutNoteType('plainText'), // Rich text notes diff --git a/lib/common/preferences/watched_preferences.dart b/lib/common/preferences/watched_preferences.dart index bc8f196c..eb3622f5 100644 --- a/lib/common/preferences/watched_preferences.dart +++ b/lib/common/preferences/watched_preferences.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; -import '../../models/note/notes_types.dart'; +import '../../models/note/types/note_type.dart'; import '../ui/theme_utils.dart'; import 'enums/bin_swipe_action.dart'; import 'enums/font.dart'; diff --git a/lib/common/system/quick_actions_utils.dart b/lib/common/system/quick_actions_utils.dart index b9fd8ced..5084350e 100644 --- a/lib/common/system/quick_actions_utils.dart +++ b/lib/common/system/quick_actions_utils.dart @@ -3,7 +3,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:quick_actions/quick_actions.dart'; import '../../models/note/note.dart'; -import '../../models/note/notes_types.dart'; +import '../../models/note/types/note_type.dart'; import '../actions/notes/add.dart'; import '../localization/localizations_utils.dart'; @@ -25,6 +25,8 @@ class QuickActionsUtils { addNote(context, ref); case NoteType.richText: addNote(context, ref); + default: + throw Exception('This note type cannot be created from a shortcut: $defaultShortcutNoteType'); } } }); diff --git a/lib/common/system/share_utils.dart b/lib/common/system/share_utils.dart index e58a7960..438a6f8c 100644 --- a/lib/common/system/share_utils.dart +++ b/lib/common/system/share_utils.dart @@ -6,7 +6,7 @@ import 'package:parchment_delta/parchment_delta.dart'; import 'package:receive_sharing_intent/receive_sharing_intent.dart'; import '../../models/note/note.dart'; -import '../../models/note/notes_types.dart'; +import '../../models/note/types/note_type.dart'; import '../actions/notes/add.dart'; import '../constants/constants.dart'; @@ -49,5 +49,7 @@ void _processSharedData(WidgetRef ref, List data) { addNote(context, ref, content: content); case NoteType.richText: addNote(context, ref, content: content); + default: + throw Exception('This note type cannot be created from a shortcut: $defaultShortcutNoteType'); } } diff --git a/lib/l10n/translations/app_en.arb b/lib/l10n/translations/app_en.arb index ccb56a3d..9b4389ef 100644 --- a/lib/l10n/translations/app_en.arb +++ b/lib/l10n/translations/app_en.arb @@ -731,6 +731,10 @@ "@tooltip_fab_add_rich_text_note": { "description": "Floating action button in the notes page to add a new rich text note." }, + "tooltip_fab_add_checklist_note": "Add a checklist note", + "@tooltip_fab_add_checklist_note": { + "description": "Floating action button in the notes page to add a new checklist note." + }, "tooltip_fab_add_label": "Add a label", "@tooltip_fab_add_label": { "description": "Floating action button in the labels page to add a new label." @@ -1068,5 +1072,9 @@ "note_type_rich_text": "Rich text", "@note_type_rich_text": { "description": "Note with rich text." + }, + "note_type_checklist": "Checklist", + "@note_type_checklist": { + "description": "Note with a checklist." } } \ No newline at end of file diff --git a/lib/models/note/note.dart b/lib/models/note/note.dart index 5340169b..791c8512 100644 --- a/lib/models/note/note.dart +++ b/lib/models/note/note.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:collection/collection.dart'; import 'package:fleather/fleather.dart'; +import 'package:flutter_checklist/checklist.dart'; import 'package:isar/isar.dart'; import 'package:json_annotation/json_annotation.dart'; @@ -10,13 +11,15 @@ import '../../common/files/encryption_utils.dart'; import '../../common/preferences/enums/sort_method.dart'; import '../../common/preferences/preference_key.dart'; import '../label/label.dart'; -import 'notes_types.dart'; +import 'types/note_type.dart'; part 'note.g.dart'; -part 'plain_text/plain_text_note.dart'; +part 'types/checklist_note.dart'; -part 'rich_text/rich_text_note.dart'; +part 'types/plain_text_note.dart'; + +part 'types/rich_text_note.dart'; /// Converts the [labels] to a JSON-compatible list of strings. List labelToJson(IsarLinks