diff --git a/lib/ui/dialogs/initial_interval_dialog.dart b/lib/ui/dialogs/initial_interval_dialog.dart index ff23fb9..47fe4f3 100644 --- a/lib/ui/dialogs/initial_interval_dialog.dart +++ b/lib/ui/dialogs/initial_interval_dialog.dart @@ -93,9 +93,11 @@ class InitialIntervalDialog extends HookWidget { onPressed: () { if (correctController.text.isEmpty || veryCorrectController.text.isEmpty) { - _snackbarService.showSnackbar( - message: 'Both intervals must be provided', - ); + if (!_snackbarService.isSnackbarOpen) { + _snackbarService.showSnackbar( + message: 'Both intervals must be provided', + ); + } return; } @@ -105,10 +107,12 @@ class InitialIntervalDialog extends HookWidget { if (correctInterval == 0 || veryCorrectInterval == 0 || correctInterval > veryCorrectInterval) { - _snackbarService.showSnackbar( - message: - 'Both intervals must be greater than 0 and the very correct answer interval must be larger', - ); + if (!_snackbarService.isSnackbarOpen) { + _snackbarService.showSnackbar( + message: + 'Both intervals must be greater than 0 and the very correct answer interval must be larger', + ); + } return; } diff --git a/lib/ui/dialogs/search_filter_dialog.dart b/lib/ui/dialogs/search_filter_dialog.dart index ea4ffc4..27ebc16 100644 --- a/lib/ui/dialogs/search_filter_dialog.dart +++ b/lib/ui/dialogs/search_filter_dialog.dart @@ -1,18 +1,20 @@ import 'package:flutter/material.dart'; -import 'package:sagase/app/app.locator.dart'; import 'package:sagase/services/dictionary_service.dart' show SearchFilter; -import 'package:sagase/services/shared_preferences_service.dart'; import 'package:stacked_services/stacked_services.dart'; class SearchFilterDialog extends StatelessWidget { final DialogRequest request; final Function(DialogResponse) completer; - const SearchFilterDialog({ + final SearchFilter searchFilter; + final bool properNounsEnabled; + + SearchFilterDialog({ required this.request, required this.completer, super.key, - }); + }) : searchFilter = request.data.$1, + properNounsEnabled = request.data.$2; @override Widget build(BuildContext context) { @@ -41,7 +43,7 @@ class SearchFilterDialog extends StatelessWidget { toggleable: true, title: const Text('Vocab'), groupValue: SearchFilter.vocab, - value: request.data, + value: searchFilter, onChanged: (_) => completer( DialogResponse(data: SearchFilter.vocab), ), @@ -50,7 +52,7 @@ class SearchFilterDialog extends StatelessWidget { toggleable: true, title: const Text('Kanji'), groupValue: SearchFilter.kanji, - value: request.data, + value: searchFilter, onChanged: (_) => completer( DialogResponse(data: SearchFilter.kanji), ), @@ -58,18 +60,14 @@ class SearchFilterDialog extends StatelessWidget { RadioListTile( toggleable: true, title: const Text('Proper nouns'), + subtitle: + properNounsEnabled ? null : const Text('Enable in settings'), groupValue: SearchFilter.properNouns, - value: request.data, - onChanged: (_) { - if (locator() - .getProperNounsEnabled()) { - completer(DialogResponse(data: SearchFilter.properNouns)); - } else { - locator().showSnackbar( - message: 'Enable proper noun dictionary in settings', - ); - } - }, + value: searchFilter, + onChanged: properNounsEnabled + ? (_) => + completer(DialogResponse(data: SearchFilter.properNouns)) + : null, ), ], ), diff --git a/lib/ui/views/flashcard_set_settings/flashcard_set_settings_viewmodel.dart b/lib/ui/views/flashcard_set_settings/flashcard_set_settings_viewmodel.dart index a797a71..69eccea 100644 --- a/lib/ui/views/flashcard_set_settings/flashcard_set_settings_viewmodel.dart +++ b/lib/ui/views/flashcard_set_settings/flashcard_set_settings_viewmodel.dart @@ -222,9 +222,11 @@ class FlashcardSetSettingsViewModel extends FutureViewModel { void openFlashcardSet() { if (flashcardSet.myDictionaryLists.isEmpty && flashcardSet.predefinedDictionaryLists.isEmpty) { - _snackbarService.showSnackbar( - message: 'Add lists to your flashcard set to open flashcards', - ); + if (!_snackbarService.isSnackbarOpen) { + _snackbarService.showSnackbar( + message: 'Add lists to your flashcard set to open flashcards', + ); + } return; } diff --git a/lib/ui/views/kanji/kanji_viewmodel.dart b/lib/ui/views/kanji/kanji_viewmodel.dart index d0ab277..cbe3027 100644 --- a/lib/ui/views/kanji/kanji_viewmodel.dart +++ b/lib/ui/views/kanji/kanji_viewmodel.dart @@ -150,10 +150,12 @@ class KanjiViewModel extends FutureViewModel { void copyKanji() { Clipboard.setData(ClipboardData(text: kanji.kanji)); - _snackbarService.showSnackbar( - message: '${kanji.kanji} copied to clipboard', - duration: const Duration(seconds: 1), - ); + if (!_snackbarService.isSnackbarOpen) { + _snackbarService.showSnackbar( + message: '${kanji.kanji} copied to clipboard', + duration: const Duration(seconds: 1), + ); + } } void setStrokeDiagramStartExpanded(bool value) { diff --git a/lib/ui/views/learning/learning_viewmodel.dart b/lib/ui/views/learning/learning_viewmodel.dart index 3a4b879..0078e12 100644 --- a/lib/ui/views/learning/learning_viewmodel.dart +++ b/lib/ui/views/learning/learning_viewmodel.dart @@ -44,9 +44,11 @@ class LearningViewModel extends FutureViewModel { void openFlashcardSet(FlashcardSet flashcardSet) { if (flashcardSet.myDictionaryLists.isEmpty && flashcardSet.predefinedDictionaryLists.isEmpty) { - _snackbarService.showSnackbar( - message: 'Add lists to your flashcard set to open flashcards', - ); + if (!_snackbarService.isSnackbarOpen) { + _snackbarService.showSnackbar( + message: 'Add lists to your flashcard set to open flashcards', + ); + } return; } @@ -65,9 +67,11 @@ class LearningViewModel extends FutureViewModel { if (flashcardSet.myDictionaryLists.isEmpty && flashcardSet.predefinedDictionaryLists.isEmpty) { - _snackbarService.showSnackbar( - message: 'Add lists to your flashcard set to open flashcards', - ); + if (!_snackbarService.isSnackbarOpen) { + _snackbarService.showSnackbar( + message: 'Add lists to your flashcard set to open flashcards', + ); + } return; } diff --git a/lib/ui/views/radical/radical_viewmodel.dart b/lib/ui/views/radical/radical_viewmodel.dart index 18f93d4..956c586 100644 --- a/lib/ui/views/radical/radical_viewmodel.dart +++ b/lib/ui/views/radical/radical_viewmodel.dart @@ -76,10 +76,12 @@ class RadicalViewModel extends FutureViewModel { void copyToClipboard(String text) { Clipboard.setData(ClipboardData(text: text)); - _snackbarService.showSnackbar( - message: '$text copied to clipboard', - duration: const Duration(seconds: 1), - ); + if (!_snackbarService.isSnackbarOpen) { + _snackbarService.showSnackbar( + message: '$text copied to clipboard', + duration: const Duration(seconds: 1), + ); + } } void setStrokeDiagramStartExpanded(bool value) { diff --git a/lib/ui/views/search/search_viewmodel.dart b/lib/ui/views/search/search_viewmodel.dart index 71bb41d..f679c7c 100644 --- a/lib/ui/views/search/search_viewmodel.dart +++ b/lib/ui/views/search/search_viewmodel.dart @@ -5,6 +5,7 @@ import 'package:sagase/app/app.dialogs.dart'; import 'package:sagase/app/app.locator.dart'; import 'package:sagase/app/app.router.dart'; import 'package:sagase/services/mecab_service.dart'; +import 'package:sagase/services/shared_preferences_service.dart'; import 'package:sagase_dictionary/sagase_dictionary.dart'; import 'package:sagase/services/digital_ink_service.dart'; import 'package:sagase/services/dictionary_service.dart'; @@ -19,6 +20,7 @@ class SearchViewModel extends FutureViewModel { final _snackbarService = locator(); final _dialogService = locator(); final _mecabService = locator(); + final _sharedPreferencesService = locator(); final _kanaKit = const KanaKit(); @@ -122,10 +124,12 @@ class SearchViewModel extends FutureViewModel { void toggleHandWriting() { if (!_digitalInkService.ready) { - _snackbarService.showSnackbar( - message: - 'Hand writing detection is setting up. Please try again later.', - ); + if (!_snackbarService.isSnackbarOpen) { + _snackbarService.showSnackbar( + message: + 'Hand writing detection is setting up. Please try again later.', + ); + } return; } _showHandWriting = !showHandWriting; @@ -165,7 +169,7 @@ class SearchViewModel extends FutureViewModel { Future setSearchFilter() async { final response = await _dialogService.showCustomDialog( variant: DialogType.searchFilter, - data: _searchFilter, + data: (_searchFilter, _sharedPreferencesService.getProperNounsEnabled()), barrierDismissible: true, ); diff --git a/lib/ui/views/text_analysis/text_analysis_viewmodel.dart b/lib/ui/views/text_analysis/text_analysis_viewmodel.dart index 66cfc47..bf4b47a 100644 --- a/lib/ui/views/text_analysis/text_analysis_viewmodel.dart +++ b/lib/ui/views/text_analysis/text_analysis_viewmodel.dart @@ -146,10 +146,12 @@ class TextAnalysisViewModel extends FutureViewModel { // Copy to clipboard Clipboard.setData(ClipboardData(text: buffer.toString())); - _snackbarService.showSnackbar( - message: '$buffer copied to clipboard', - duration: const Duration(seconds: 1), - ); + if (!_snackbarService.isSnackbarOpen) { + _snackbarService.showSnackbar( + message: '$buffer copied to clipboard', + duration: const Duration(seconds: 1), + ); + } } void textAnalysisHistoryItemSelected(TextAnalysisHistoryItem item) { diff --git a/lib/ui/views/vocab/vocab_viewmodel.dart b/lib/ui/views/vocab/vocab_viewmodel.dart index 17064c7..c58ae0d 100644 --- a/lib/ui/views/vocab/vocab_viewmodel.dart +++ b/lib/ui/views/vocab/vocab_viewmodel.dart @@ -188,9 +188,12 @@ class VocabViewModel extends FutureViewModel { } } else { Clipboard.setData(ClipboardData(text: reference.text)); - _snackbarService.showSnackbar( - message: 'Reference not found. ${reference.text} copied to clipboard.', - ); + if (!_snackbarService.isSnackbarOpen) { + _snackbarService.showSnackbar( + message: + 'Reference not found. ${reference.text} copied to clipboard.', + ); + } } }