diff --git a/lib/services/dictionary_service.dart b/lib/services/dictionary_service.dart index 9297598..84e66a2 100644 --- a/lib/services/dictionary_service.dart +++ b/lib/services/dictionary_service.dart @@ -241,7 +241,7 @@ class DictionaryService { (a.common ? 1 : 0); } - Future getKanji(String kanji) async { + Future getKanji(String kanji) async { return _database.kanjisDao.getKanji(kanji); } diff --git a/lib/ui/views/flashcards/flashcards_viewmodel.dart b/lib/ui/views/flashcards/flashcards_viewmodel.dart index bcfc8dc..07ffcf8 100644 --- a/lib/ui/views/flashcards/flashcards_viewmodel.dart +++ b/lib/ui/views/flashcards/flashcards_viewmodel.dart @@ -660,8 +660,8 @@ class FlashcardsViewModel extends FutureViewModel { if (kanjiStrings.contains(foundKanji[0]!)) continue; kanjiStrings.add(foundKanji[0]!); // Load from database - vocab.includedKanji! - .add(await _dictionaryService.getKanji(foundKanji[0]!)); + final kanji = await _dictionaryService.getKanji(foundKanji[0]!); + if (kanji != null) vocab.includedKanji!.add(kanji); } } diff --git a/lib/ui/views/proper_noun/proper_noun_view.dart b/lib/ui/views/proper_noun/proper_noun_view.dart index d098a98..4c31fc7 100644 --- a/lib/ui/views/proper_noun/proper_noun_view.dart +++ b/lib/ui/views/proper_noun/proper_noun_view.dart @@ -32,7 +32,7 @@ class ProperNounView extends StackedView { children: [ const _WritingReading(), const _RomajiAndType(), - if (viewModel.kanjiStringList.isNotEmpty) const _KanjiList(), + if (viewModel.kanjiList.isNotEmpty) const _KanjiList(), SizedBox(height: MediaQuery.of(context).padding.bottom), ], ), @@ -135,7 +135,7 @@ class _KanjiList extends ViewModelWidget { child: Column( children: viewModel.isBusy ? List.generate( - viewModel.kanjiStringList.length, + viewModel.kanjiList.length, (index) { return Padding( padding: const EdgeInsets.symmetric( @@ -151,7 +151,7 @@ class _KanjiList extends ViewModelWidget { right: 12, ), child: Text( - viewModel.kanjiStringList[index], + viewModel.kanjiList[index], style: const TextStyle(fontSize: 24), ), ), diff --git a/lib/ui/views/proper_noun/proper_noun_viewmodel.dart b/lib/ui/views/proper_noun/proper_noun_viewmodel.dart index 838cb54..ebf842c 100644 --- a/lib/ui/views/proper_noun/proper_noun_viewmodel.dart +++ b/lib/ui/views/proper_noun/proper_noun_viewmodel.dart @@ -14,8 +14,9 @@ class ProperNounViewModel extends FutureViewModel { final ProperNoun properNoun; - late final List kanjiStringList; - late final List kanjiList; + List get kanjiList => isBusy ? _kanjiStringList : _kanjiList; + late final List _kanjiStringList; + late final List _kanjiList; ProperNounViewModel(this.properNoun) { // Get list of kanji to be loaded during initialize function @@ -26,14 +27,14 @@ class ProperNounViewModel extends FutureViewModel { kanjiStringSet.add(foundKanji[0]!); } } - kanjiStringList = kanjiStringSet.toList(); + _kanjiStringList = kanjiStringSet.toList(); } @override Future futureToRun() async { // Load kanji from database that were found during class constructor - kanjiList = await _dictionaryService - .getKanjiList(kanjiStringList.map((e) => e.kanjiCodePoint()).toList()); + _kanjiList = await _dictionaryService + .getKanjiList(_kanjiStringList.map((e) => e.kanjiCodePoint()).toList()); } Future navigateToKanji(Kanji kanji) async { diff --git a/lib/ui/views/vocab/vocab_view.dart b/lib/ui/views/vocab/vocab_view.dart index 7971730..c05b42d 100644 --- a/lib/ui/views/vocab/vocab_view.dart +++ b/lib/ui/views/vocab/vocab_view.dart @@ -83,7 +83,7 @@ class VocabView extends StackedView { children: [ _KanjiReadingPairs(viewModel.writingReadingPairs), const _Definitions(), - if (viewModel.kanjiStringList.isNotEmpty) const _KanjiList(), + if (viewModel.kanjiList.isNotEmpty) const _KanjiList(), const _Examples(), if (viewModel.conjugations != null) const _Conjugations(), SizedBox(height: MediaQuery.of(context).padding.bottom), @@ -655,7 +655,7 @@ class _KanjiList extends ViewModelWidget { child: Column( children: viewModel.isBusy ? List.generate( - viewModel.kanjiStringList.length, + viewModel.kanjiList.length, (index) { return Padding( padding: const EdgeInsets.symmetric( @@ -671,7 +671,7 @@ class _KanjiList extends ViewModelWidget { right: 12, ), child: Text( - viewModel.kanjiStringList[index], + viewModel.kanjiList[index], style: const TextStyle(fontSize: 24), ), ), diff --git a/lib/ui/views/vocab/vocab_viewmodel.dart b/lib/ui/views/vocab/vocab_viewmodel.dart index ba606e1..c0a8408 100644 --- a/lib/ui/views/vocab/vocab_viewmodel.dart +++ b/lib/ui/views/vocab/vocab_viewmodel.dart @@ -28,8 +28,9 @@ class VocabViewModel extends FutureViewModel { final Vocab vocab; late final List writingReadingPairs; - late final List kanjiStringList; - late final List kanjiList; + List get kanjiList => isBusy ? _kanjiStringList : _kanjiList; + late final List _kanjiStringList; + late final List _kanjiList; List _myDictionaryListsContainingVocab = []; bool get inMyDictionaryList => _myDictionaryListsContainingVocab.isNotEmpty; @@ -53,7 +54,7 @@ class VocabViewModel extends FutureViewModel { } } } - kanjiStringList = kanjiStringSet.toList(); + _kanjiStringList = kanjiStringSet.toList(); // Get conjugations conjugations = _conjugationUtils.getConjugations(vocab); @@ -75,8 +76,8 @@ class VocabViewModel extends FutureViewModel { rebuildUi(); // Load kanji from database that were found during class constructor - kanjiList = await _dictionaryService - .getKanjiList(kanjiStringList.map((e) => e.kanjiCodePoint()).toList()); + _kanjiList = await _dictionaryService + .getKanjiList(_kanjiStringList.map((e) => e.kanjiCodePoint()).toList()); } void _startWatcher() { diff --git a/pubspec.lock b/pubspec.lock index 7afec60..7da4a90 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -958,8 +958,8 @@ packages: dependency: "direct main" description: path: "." - ref: "003d79c" - resolved-ref: "003d79c6228e5e3299e8c22e93ec3820f5dee4d4" + ref: "428d744" + resolved-ref: "428d74484705dd96e2bd43b39e7c9963aebc6182" url: "https://github.com/Moseco/sagase_dictionary" source: git version: "1.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 939b621..03a6813 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -72,7 +72,7 @@ dependencies: sagase_dictionary: git: url: https://github.com/Moseco/sagase_dictionary - ref: '003d79c' + ref: '428d744' url_launcher: ^6.1.12 dio: ^5.3.3 in_app_review: ^2.0.8 diff --git a/test/services/dictionary_service_test.dart b/test/services/dictionary_service_test.dart index b897945..0b3413b 100644 --- a/test/services/dictionary_service_test.dart +++ b/test/services/dictionary_service_test.dart @@ -220,7 +220,7 @@ void main() { ); await service.addToMyDictionaryList( dictionaryList, - await service.getKanji('二'), + (await service.getKanji('二'))!, ); // Create flashcard set @@ -258,7 +258,7 @@ void main() { ); await service.addToMyDictionaryList( dictionaryList, - await service.getKanji('三'), + (await service.getKanji('三'))!, ); await service.renameMyDictionaryList(dictionaryList, 'new name'); @@ -275,13 +275,13 @@ void main() { ); await service.setSpacedRepetitionData( SpacedRepetitionData.initial( - dictionaryItem: await service.getKanji('二'), + dictionaryItem: (await service.getKanji('二'))!, frontType: FrontType.japanese, ).copyWith(interval: 4), ); await service.setSpacedRepetitionData( SpacedRepetitionData.initial( - dictionaryItem: await service.getKanji('三'), + dictionaryItem: (await service.getKanji('三'))!, frontType: FrontType.english, ).copyWith(interval: 4), ); @@ -431,11 +431,11 @@ void main() { ); await service.addToMyDictionaryList( dictionaryList, - await service.getKanji('二'), + (await service.getKanji('二'))!, ); await service.addToMyDictionaryList( dictionaryList, - await service.getKanji('三'), + (await service.getKanji('三'))!, ); // Create flashcard set @@ -468,13 +468,13 @@ void main() { ); await service.setSpacedRepetitionData( SpacedRepetitionData.initial( - dictionaryItem: await service.getKanji('三'), + dictionaryItem: (await service.getKanji('三'))!, frontType: FrontType.japanese, ).copyWith(interval: 3), ); await service.setSpacedRepetitionData( SpacedRepetitionData.initial( - dictionaryItem: await service.getKanji('三'), + dictionaryItem: (await service.getKanji('三'))!, frontType: FrontType.english, ).copyWith(interval: 4), ); diff --git a/test/ui/views/flashcards/flashcards_viewmodel_test.dart b/test/ui/views/flashcards/flashcards_viewmodel_test.dart index 4314322..e4bff2b 100644 --- a/test/ui/views/flashcards/flashcards_viewmodel_test.dart +++ b/test/ui/views/flashcards/flashcards_viewmodel_test.dart @@ -585,25 +585,25 @@ void main() { ); } await dictionaryService.addToMyDictionaryList( - dictionaryList, await dictionaryService.getKanji('一')); + dictionaryList, (await dictionaryService.getKanji('一'))!); await dictionaryService.addToMyDictionaryList( - dictionaryList, await dictionaryService.getKanji('二')); + dictionaryList, (await dictionaryService.getKanji('二'))!); await dictionaryService.addToMyDictionaryList( - dictionaryList, await dictionaryService.getKanji('三')); + dictionaryList, (await dictionaryService.getKanji('三'))!); await dictionaryService.addToMyDictionaryList( - dictionaryList, await dictionaryService.getKanji('四')); + dictionaryList, (await dictionaryService.getKanji('四'))!); await dictionaryService.addToMyDictionaryList( - dictionaryList, await dictionaryService.getKanji('五')); + dictionaryList, (await dictionaryService.getKanji('五'))!); await dictionaryService.addToMyDictionaryList( - dictionaryList, await dictionaryService.getKanji('六')); + dictionaryList, (await dictionaryService.getKanji('六'))!); await dictionaryService.addToMyDictionaryList( - dictionaryList, await dictionaryService.getKanji('七')); + dictionaryList, (await dictionaryService.getKanji('七'))!); await dictionaryService.addToMyDictionaryList( - dictionaryList, await dictionaryService.getKanji('八')); + dictionaryList, (await dictionaryService.getKanji('八'))!); await dictionaryService.addToMyDictionaryList( - dictionaryList, await dictionaryService.getKanji('九')); + dictionaryList, (await dictionaryService.getKanji('九'))!); await dictionaryService.addToMyDictionaryList( - dictionaryList, await dictionaryService.getKanji('十')); + dictionaryList, (await dictionaryService.getKanji('十'))!); // Create flashcard set and assign lists final flashcardSet = await dictionaryService.createFlashcardSet('name');