Skip to content

Commit 712ea69

Browse files
authored
dev4 (#447)
* [445] refactor: localizations * [445] misc: minor changes * [445] fix: migration and backup issues
1 parent 8639e69 commit 712ea69

91 files changed

Lines changed: 867 additions & 738 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@ fastlane/localmaterialnotes_fastlane-supply_key.json
5555
fastlane/README.md
5656
fastlane/report.xml
5757

58-
# Tests
59-
integration_test/test_bundle.dart
60-
6158
# Generated files
6259
*.g.dart
6360

lib/app.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ class _AppState extends ConsumerState<App> with AfterLayoutMixin<App> {
5353

5454
@override
5555
FutureOr<void> afterFirstLayout(BuildContext context) {
56-
SystemUtils().setQuickActions();
56+
// Using the context provided by afterFirstLayout doesn't work
57+
SystemUtils().setQuickActions(rootNavigatorKey.currentContext!);
5758
}
5859

5960
@override

lib/common/actions/labels/add.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
44
import '../../../models/label/label.dart';
55
import '../../../pages/labels/dialogs/label_dialog.dart';
66
import '../../../providers/labels/labels/labels_provider.dart';
7-
import '../../constants/constants.dart';
7+
import '../../extensions/build_context_extension.dart';
88

99
/// Adds a label.
1010
Future<void> addLabel(BuildContext context, WidgetRef ref) async {
1111
final label = await showAdaptiveDialog<Label>(
1212
context: context,
1313
useRootNavigator: false,
14-
builder: (context) => LabelDialog(title: l.dialog_label_add),
14+
builder: (context) => LabelDialog(title: context.l.dialog_label_add),
1515
);
1616

1717
if (label == null) {

lib/common/actions/labels/delete.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
33

44
import '../../../models/label/label.dart';
55
import '../../../providers/labels/labels/labels_provider.dart';
6-
import '../../constants/constants.dart';
76
import '../../dialogs/confirmation_dialog.dart';
7+
import '../../extensions/build_context_extension.dart';
88
import 'select.dart';
99

1010
/// Deletes the [label].
@@ -15,9 +15,9 @@ import 'select.dart';
1515
Future<bool> deleteLabel(BuildContext context, WidgetRef ref, {required Label label}) async {
1616
if (!await askForConfirmation(
1717
context,
18-
l.dialog_delete_label,
19-
l.dialog_delete_label_body(1),
20-
l.dialog_delete_label,
18+
context.l.dialog_delete_label,
19+
context.l.dialog_delete_label_body(1),
20+
context.l.dialog_delete_label,
2121
irreversible: true,
2222
)) {
2323
return false;
@@ -34,9 +34,9 @@ Future<bool> deleteLabel(BuildContext context, WidgetRef ref, {required Label la
3434
Future<bool> deleteLabels(BuildContext context, WidgetRef ref, {required List<Label> labels}) async {
3535
if (!await askForConfirmation(
3636
context,
37-
l.dialog_delete_label,
38-
l.dialog_delete_label_body(labels.length),
39-
l.dialog_delete_label,
37+
context.l.dialog_delete_label,
38+
context.l.dialog_delete_label_body(labels.length),
39+
context.l.dialog_delete_label,
4040
irreversible: true,
4141
)) {
4242
return false;

lib/common/actions/labels/edit.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
44
import '../../../models/label/label.dart';
55
import '../../../pages/labels/dialogs/label_dialog.dart';
66
import '../../../providers/labels/labels/labels_provider.dart';
7-
import '../../constants/constants.dart';
7+
import '../../extensions/build_context_extension.dart';
88

99
/// Opens the dialog to edit the [label].
1010
Future<void> editLabel(BuildContext context, WidgetRef ref, {required Label label}) async {
1111
final editedLabel = await showAdaptiveDialog<Label>(
1212
context: context,
1313
useRootNavigator: false,
14-
builder: (context) => LabelDialog(title: l.dialog_label_edit, label: label),
14+
builder: (context) => LabelDialog(title: context.l.dialog_label_edit, label: label),
1515
);
1616

1717
if (editedLabel == null) {

lib/common/actions/labels/lock.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1+
import 'package:flutter/material.dart';
12
import 'package:flutter_riverpod/flutter_riverpod.dart';
23
import 'package:local_auth/local_auth.dart';
34

45
import '../../../models/label/label.dart';
56
import '../../../providers/labels/labels/labels_provider.dart';
6-
import '../../constants/constants.dart';
7+
import '../../extensions/build_context_extension.dart';
78
import '../../preferences/preference_key.dart';
89
import 'select.dart';
910

1011
/// Toggles whether the [labels] are locked.
11-
Future<bool> toggleLockLabels(WidgetRef ref, {required List<Label> labels}) async {
12+
Future<bool> toggleLockLabels(BuildContext context, WidgetRef ref, {required List<Label> labels}) async {
1213
final lockLabelPreference = PreferenceKey.lockLabel.preferenceOrDefault;
1314
final anyLocked = labels.any((label) => label.locked);
1415

1516
// If the lock label setting is enabled and a label was locked, then ask to authenticate
1617
if (lockLabelPreference && anyLocked) {
17-
final bool authenticated = await LocalAuthentication().authenticate(localizedReason: l.lock_page_reason_action);
18+
final bool authenticated = await LocalAuthentication().authenticate(
19+
localizedReason: context.l.lock_page_reason_action,
20+
);
1821

1922
if (!authenticated) {
2023
return false;

lib/common/actions/notes/archive.dart

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import '../../../providers/notes/notes_provider.dart';
77
import '../../../providers/notifiers/notifiers.dart';
88
import '../../constants/constants.dart';
99
import '../../dialogs/confirmation_dialog.dart';
10+
import '../../extensions/build_context_extension.dart';
1011
import '../../ui/snack_bar_utils.dart';
1112
import 'select.dart';
1213
import 'unarchive.dart';
@@ -21,7 +22,12 @@ Future<bool> archiveNote(
2122
bool pop = false,
2223
bool cancel = true,
2324
}) async {
24-
if (!await askForConfirmation(context, l.dialog_archive, l.dialog_archive_body(1), l.dialog_archive)) {
25+
if (!await askForConfirmation(
26+
context,
27+
context.l.dialog_archive,
28+
context.l.dialog_archive_body(1),
29+
context.l.dialog_archive,
30+
)) {
2531
return false;
2632
}
2733

@@ -36,9 +42,10 @@ Future<bool> archiveNote(
3642
.read(notesProvider(status: NoteStatus.available, label: currentLabelFilter).notifier)
3743
.setArchived([note], true);
3844

39-
if (succeeded && cancel) {
45+
if (succeeded && cancel && context.mounted) {
4046
SnackBarUtils().show(
41-
text: l.snack_bar_archived(1),
47+
context,
48+
text: context.l.snack_bar_archived(1),
4249
onCancel: (globalRef) async => await unarchiveNote(context, globalRef, note: note, cancel: false),
4350
);
4451
}
@@ -50,7 +57,12 @@ Future<bool> archiveNote(
5057
///
5158
/// Returns `true` if the [notes] were archived, `false` otherwise.
5259
Future<bool> archiveNotes(BuildContext context, WidgetRef ref, {required List<Note> notes, bool cancel = true}) async {
53-
if (!await askForConfirmation(context, l.dialog_archive, l.dialog_archive_body(notes.length), l.dialog_archive)) {
60+
if (!await askForConfirmation(
61+
context,
62+
context.l.dialog_archive,
63+
context.l.dialog_archive_body(notes.length),
64+
context.l.dialog_archive,
65+
)) {
5466
return false;
5567
}
5668

@@ -62,9 +74,10 @@ Future<bool> archiveNotes(BuildContext context, WidgetRef ref, {required List<No
6274
exitNotesSelectionMode(context, ref, notesStatus: NoteStatus.available);
6375
}
6476

65-
if (succeeded && cancel) {
77+
if (succeeded && cancel && context.mounted) {
6678
SnackBarUtils().show(
67-
text: l.snack_bar_archived(notes.length),
79+
context,
80+
text: context.l.snack_bar_archived(notes.length),
6881
onCancel: (globalRef) async => await unarchiveNotes(context, globalRef, notes: notes, cancel: false),
6982
);
7083
}

lib/common/actions/notes/copy.dart

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
1+
import 'package:flutter/material.dart';
12
import 'package:flutter/services.dart';
23

34
import '../../../models/note/note.dart';
4-
import '../../constants/constants.dart';
5+
import '../../extensions/build_context_extension.dart';
56
import '../../ui/snack_bar_utils.dart';
67

78
/// Copies the content of the [note] to the clipboard.
8-
Future<void> copyNote({required Note note}) async {
9+
Future<void> copyNote(BuildContext context, {required Note note}) async {
910
await Clipboard.setData(ClipboardData(text: note.contentPreview));
1011

11-
SnackBarUtils().show(text: l.snack_bar_copied(1));
12+
if (!context.mounted) {
13+
return;
14+
}
15+
16+
if (context.mounted) {
17+
SnackBarUtils().show(context, text: context.l.snack_bar_copied(1));
18+
}
1219
}
1320

1421
/// Copies the content of the [notes] to the clipboard.
15-
Future<void> copyNotes({required List<Note> notes}) async {
22+
Future<void> copyNotes(BuildContext context, {required List<Note> notes}) async {
1623
final text = notes.map((note) => note.contentPreview).join('\n\n\n').trim();
1724

1825
await Clipboard.setData(ClipboardData(text: text));
1926

20-
SnackBarUtils().show(text: l.snack_bar_copied(notes.length));
27+
if (context.mounted) {
28+
SnackBarUtils().show(context, text: context.l.snack_bar_copied(notes.length));
29+
}
2130
}

lib/common/actions/notes/delete.dart

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import '../../../providers/notes/notes_provider.dart';
77
import '../../../providers/notifiers/notifiers.dart';
88
import '../../constants/constants.dart';
99
import '../../dialogs/confirmation_dialog.dart';
10+
import '../../extensions/build_context_extension.dart';
1011
import '../../ui/snack_bar_utils.dart';
1112
import 'archive.dart';
1213
import 'restore.dart';
@@ -22,7 +23,12 @@ Future<bool> deleteNote(
2223
bool pop = false,
2324
bool cancel = true,
2425
}) async {
25-
if (!await askForConfirmation(context, l.dialog_delete, l.dialog_delete_body(1), l.dialog_delete)) {
26+
if (!await askForConfirmation(
27+
context,
28+
context.l.dialog_delete,
29+
context.l.dialog_delete_body(1),
30+
context.l.dialog_delete,
31+
)) {
2632
return false;
2733
}
2834

@@ -39,9 +45,10 @@ Future<bool> deleteNote(
3945
.read(notesProvider(status: NoteStatus.available, label: currentLabelFilter).notifier)
4046
.setDeleted([note], true);
4147

42-
if (succeeded && cancel) {
48+
if (succeeded && cancel && context.mounted) {
4349
SnackBarUtils().show(
44-
text: l.snack_bar_deleted(1),
50+
context,
51+
text: context.l.snack_bar_deleted(1),
4552
onCancel:
4653
(globalRef) async =>
4754
wasArchived
@@ -57,7 +64,12 @@ Future<bool> deleteNote(
5764
///
5865
/// Returns `true` if the [notes] were deleted, `false` otherwise.
5966
Future<bool> deleteNotes(BuildContext context, WidgetRef ref, {required List<Note> notes, bool cancel = true}) async {
60-
if (!await askForConfirmation(context, l.dialog_delete, l.dialog_delete_body(notes.length), l.dialog_delete)) {
67+
if (!await askForConfirmation(
68+
context,
69+
context.l.dialog_delete,
70+
context.l.dialog_delete_body(notes.length),
71+
context.l.dialog_delete,
72+
)) {
6173
return false;
6274
}
6375

@@ -71,9 +83,10 @@ Future<bool> deleteNotes(BuildContext context, WidgetRef ref, {required List<Not
7183
exitNotesSelectionMode(context, ref, notesStatus: NoteStatus.available);
7284
}
7385

74-
if (succeeded && cancel) {
86+
if (succeeded && cancel && context.mounted) {
7587
SnackBarUtils().show(
76-
text: l.snack_bar_deleted(notes.length),
88+
context,
89+
text: context.l.snack_bar_deleted(notes.length),
7790
onCancel:
7891
(globalRef) async =>
7992
wereArchived
@@ -91,9 +104,9 @@ Future<bool> deleteNotes(BuildContext context, WidgetRef ref, {required List<Not
91104
Future<bool> permanentlyDeleteNote(BuildContext context, WidgetRef ref, {required Note note, bool pop = false}) async {
92105
if (!await askForConfirmation(
93106
context,
94-
l.dialog_permanently_delete,
95-
l.dialog_permanently_delete_body(1),
96-
l.dialog_permanently_delete,
107+
context.l.dialog_permanently_delete,
108+
context.l.dialog_permanently_delete_body(1),
109+
context.l.dialog_permanently_delete,
97110
irreversible: true,
98111
)) {
99112
return false;
@@ -121,9 +134,9 @@ Future<bool> permanentlyDeleteNote(BuildContext context, WidgetRef ref, {require
121134
Future<bool> permanentlyDeleteNotes(BuildContext context, WidgetRef ref, {required List<Note> notes}) async {
122135
if (!await askForConfirmation(
123136
context,
124-
l.dialog_permanently_delete,
125-
l.dialog_permanently_delete_body(notes.length),
126-
l.dialog_permanently_delete,
137+
context.l.dialog_permanently_delete,
138+
context.l.dialog_permanently_delete_body(notes.length),
139+
context.l.dialog_permanently_delete,
127140
irreversible: true,
128141
)) {
129142
return false;
@@ -142,9 +155,9 @@ Future<bool> permanentlyDeleteNotes(BuildContext context, WidgetRef ref, {requir
142155
Future<bool> emptyBin(BuildContext context, WidgetRef ref) async {
143156
if (!await askForConfirmation(
144157
context,
145-
l.dialog_empty_bin,
146-
l.dialog_empty_bin_body,
147-
l.dialog_empty_bin,
158+
context.l.dialog_empty_bin,
159+
context.l.dialog_empty_bin_body,
160+
context.l.dialog_empty_bin,
148161
irreversible: true,
149162
)) {
150163
return false;

lib/common/actions/notes/labels.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import '../../../pages/editor/dialogs/labels_selection_dialog.dart';
88
import '../../../providers/labels/labels_list/labels_list_provider.dart';
99
import '../../../providers/notes/notes_provider.dart';
1010
import '../../../providers/notifiers/notifiers.dart';
11-
import '../../constants/constants.dart';
11+
import '../../extensions/build_context_extension.dart';
1212
import '../../ui/snack_bar_utils.dart';
1313
import 'select.dart';
1414

1515
/// Asks the user to select the labels for the [note].
1616
Future<List<Label>?> selectLabels(BuildContext context, WidgetRef ref, {required Note note}) async {
1717
if (ref.read(labelsListProvider).value == null || ref.read(labelsListProvider).value!.isEmpty) {
18-
SnackBarUtils().show(text: l.snack_bar_no_labels);
18+
SnackBarUtils().show(context, text: context.l.snack_bar_no_labels);
1919

2020
return null;
2121
}
@@ -51,7 +51,7 @@ Future<List<Label>?> selectLabels(BuildContext context, WidgetRef ref, {required
5151
/// Asks the user to select the labels to add to the [notes].
5252
Future<List<Label>?> addLabels(BuildContext context, WidgetRef ref, {required List<Note> notes}) async {
5353
if (ref.read(labelsListProvider).value == null || ref.read(labelsListProvider).value!.isEmpty) {
54-
SnackBarUtils().show(text: l.snack_bar_no_labels);
54+
SnackBarUtils().show(context, text: context.l.snack_bar_no_labels);
5555

5656
return null;
5757
}

0 commit comments

Comments
 (0)