From d82fcbe42786baf1c749a6d92ae71cc791791459 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 26 Jul 2021 21:39:17 +0200 Subject: [PATCH] Update to null safety --- .gitignore | 2 + lib/bloc/kanji/kanji_state.dart | 2 +- lib/bloc/search/search_bloc.dart | 2 +- lib/main.dart | 8 +- lib/models/history/kanji_result.dart | 4 +- lib/models/history/search_string.dart | 4 +- lib/models/history/word_result.dart | 4 +- lib/models/storage/search_result.dart | 126 ++++---- lib/objectbox-model.json | 285 ++---------------- lib/services/jisho_api/kanji_search.dart | 7 +- lib/services/kanji_suggestions.dart | 9 +- .../components/history/kanji_search_item.dart | 4 +- lib/view/components/history/search_item.dart | 4 +- .../components/kanji/kanji_search_bar.dart | 8 +- .../kanji/kanji_search_options_bar.dart | 10 +- lib/view/components/kanji/result/kunyomi.dart | 8 +- lib/view/components/kanji/result/meaning.dart | 10 +- lib/view/components/kanji/result/onyomi.dart | 8 +- .../components/search/LanguageSelector.dart | 8 +- .../parts/common_badge.dart | 4 +- .../search_result_page/parts/header.dart | 5 +- .../search_result_page/parts/other_forms.dart | 5 +- .../search_result_page/parts/senses.dart | 4 +- .../search_result_page/search_card.dart | 6 +- lib/view/screens/kanji/result.dart | 34 ++- lib/view/screens/kanji/search.dart | 6 +- lib/view/screens/kanji/view.dart | 2 +- pubspec.yaml | 26 +- 28 files changed, 195 insertions(+), 410 deletions(-) diff --git a/.gitignore b/.gitignore index d16b8eb..0bd996a 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,8 @@ .pub/ /build/ +objectbox.g.dart + # Web related lib/generated_plugin_registrant.dart diff --git a/lib/bloc/kanji/kanji_state.dart b/lib/bloc/kanji/kanji_state.dart index e280c64..ecc3653 100644 --- a/lib/bloc/kanji/kanji_state.dart +++ b/lib/bloc/kanji/kanji_state.dart @@ -31,7 +31,7 @@ class KanjiSearchFinished extends KanjiState { final bool starred; const KanjiSearchFinished({ - this.kanji, + required this.kanji, this.starred = false, }); } diff --git a/lib/bloc/search/search_bloc.dart b/lib/bloc/search/search_bloc.dart index 6ce75cc..02be4bc 100644 --- a/lib/bloc/search/search_bloc.dart +++ b/lib/bloc/search/search_bloc.dart @@ -42,7 +42,7 @@ class SearchBloc extends Bloc { try { addSearchToDB(event.searchString); final searchResults = await fetchJishoResults(event.searchString); - if (searchResults.meta.status == 200) yield SearchFinished(searchResults.data); + if (searchResults.meta.status == 200) yield SearchFinished(searchResults.data!); } on Exception { yield SearchError('Something went wrong'); } diff --git a/lib/main.dart b/lib/main.dart index 822251d..3da26d6 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,9 +5,9 @@ import 'package:path_provider/path_provider.dart'; import 'package:path/path.dart'; import 'package:jisho_study_tool/objectbox.g.dart'; -import 'package:jisho_study_tool/bloc/search/search_bloc.dart'; import 'package:jisho_study_tool/bloc/database/database_bloc.dart'; import 'package:jisho_study_tool/bloc/kanji/kanji_bloc.dart'; +import 'package:jisho_study_tool/bloc/search/search_bloc.dart'; import 'package:jisho_study_tool/view/screens/kanji/view.dart'; import 'package:jisho_study_tool/view/screens/history.dart'; @@ -46,7 +46,7 @@ class Home extends StatefulWidget { class _HomeState extends State { int selectedPage = 0; - Store _store; + late final Store _store; @override void initState() { @@ -136,8 +136,8 @@ class _Page { Widget titleBar; _Page({ - this.content, - this.titleBar, + required this.content, + required this.titleBar, }); } diff --git a/lib/models/history/kanji_result.dart b/lib/models/history/kanji_result.dart index 2d7864c..e2beb9d 100644 --- a/lib/models/history/kanji_result.dart +++ b/lib/models/history/kanji_result.dart @@ -11,8 +11,8 @@ class KanjiResult { String kanji; KanjiResult({ - this.timestamp, - this.kanji, + required this.timestamp, + required this.kanji, }); @override diff --git a/lib/models/history/search_string.dart b/lib/models/history/search_string.dart index b85aa07..1e9cf7c 100644 --- a/lib/models/history/search_string.dart +++ b/lib/models/history/search_string.dart @@ -15,8 +15,8 @@ class SearchString { final chosenResults = ToMany(); SearchString({ - this.timestamp, - this.query, + required this.timestamp, + required this.query, }); @override diff --git a/lib/models/history/word_result.dart b/lib/models/history/word_result.dart index 5e3cf7c..56f8ec9 100644 --- a/lib/models/history/word_result.dart +++ b/lib/models/history/word_result.dart @@ -14,8 +14,8 @@ class WordResult { final searchString = ToOne(); WordResult({ - this.timestamp, - this.word, + required this.timestamp, + required this.word, }); @override diff --git a/lib/models/storage/search_result.dart b/lib/models/storage/search_result.dart index 19783af..7d1e5d3 100644 --- a/lib/models/storage/search_result.dart +++ b/lib/models/storage/search_result.dart @@ -1,72 +1,72 @@ -import 'package:objectbox/objectbox.dart'; -import 'package:unofficial_jisho_api/api.dart' as jisho; +// import 'package:objectbox/objectbox.dart'; +// import 'package:unofficial_jisho_api/api.dart' as jisho; -@Entity() -class SearchResult { - int id = 0; - final meta = ToOne(); - final data = ToMany(); +// @Entity() +// class SearchResult { +// int id = 0; +// final meta = ToOne(); +// final data = ToMany(); - // SearchResult(JishoAPIResult result) { - // this.data = result.data; - // this.meta = result.meta; - // } +// // SearchResult(JishoAPIResult result) { +// // this.data = result.data; +// // this.meta = result.meta; +// // } - // JishoAPIResult toJishoAPIResult() { - // return JishoAPIResult(meta: this.meta, data: this.data); - // } -} +// // JishoAPIResult toJishoAPIResult() { +// // return JishoAPIResult(meta: this.meta, data: this.data); +// // } +// } -@Entity() -class JishoResultMeta { - int id = 0; - int status; -} +// @Entity() +// class JishoResultMeta { +// int id = 0; +// int status; +// } -@Entity() -class JishoResult { - int id = 0; - final attribution = ToOne(); - bool is_common; - final japanese = ToMany(); - List jlpt; - final senses = ToMany(); - String slug; - List tags; -} +// @Entity() +// class JishoResult { +// int id = 0; +// final attribution = ToOne(); +// bool is_common; +// final japanese = ToMany(); +// List jlpt; +// final senses = ToMany(); +// String slug; +// List tags; +// } -@Entity() -class JishoAttribution { - int id = 0; - String dbpedia; - String jmdict; - bool jmnedict; -} +// @Entity() +// class JishoAttribution { +// int id = 0; +// String dbpedia; +// String jmdict; +// bool jmnedict; +// } -@Entity() -class JishoJapaneseWord { - int id = 0; - String reading; - String word; -} +// @Entity() +// class JishoJapaneseWord { +// int id = 0; +// String reading; +// String word; +// } -@Entity() -class JishoWordSense { - int id = 0; - List antonyms; - List english_definitions; - List info; - final links = ToMany(); - List parts_of_speech; - List restrictions; - List see_also; - List source; - List tags; -} +// @Entity() +// class JishoWordSense { +// int id = 0; +// List antonyms; +// List english_definitions; +// List info; +// final links = ToMany(); +// List parts_of_speech; +// List restrictions; +// List see_also; +// List source; +// List tags; +// } -@Entity() -class JishoSenseLink { - int id = 0; - String text; - String url; -} +// @Entity() +// class JishoSenseLink { +// int id = 0; +// String text; +// String url; +// } diff --git a/lib/objectbox-model.json b/lib/objectbox-model.json index 483b1a3..44a2088 100644 --- a/lib/objectbox-model.json +++ b/lib/objectbox-model.json @@ -4,255 +4,23 @@ "_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.", "entities": [ { - "id": "3:7851566044119418641", - "lastPropertyId": "4:2352718426928758061", - "name": "JishoAttribution", - "properties": [ - { - "id": "1:9162407962473480509", - "name": "id", - "type": 6, - "flags": 1 - }, - { - "id": "2:708495477684386", - "name": "dbpedia", - "type": 9 - }, - { - "id": "3:6579248575703756688", - "name": "jmdict", - "type": 9 - }, - { - "id": "4:2352718426928758061", - "name": "jmnedict", - "type": 1 - } - ], - "relations": [] - }, - { - "id": "4:5830034738494786681", - "lastPropertyId": "3:1420686825377652298", - "name": "JishoJapaneseWord", - "properties": [ - { - "id": "1:5568051277997102473", - "name": "id", - "type": 6, - "flags": 1 - }, - { - "id": "2:8794655557751948952", - "name": "reading", - "type": 9 - }, - { - "id": "3:1420686825377652298", - "name": "word", - "type": 9 - } - ], - "relations": [] - }, - { - "id": "5:814015574151442186", - "lastPropertyId": "6:5908719510010444548", - "name": "JishoResult", - "properties": [ - { - "id": "1:4779715838063307925", - "name": "id", - "type": 6, - "flags": 1 - }, - { - "id": "2:398633124413531447", - "name": "attributionId", - "type": 11, - "flags": 520, - "indexId": "1:3741479335507224998", - "relationTarget": "JishoAttribution" - }, - { - "id": "3:3743357097628620453", - "name": "is_common", - "type": 1 - }, - { - "id": "4:2403901886209575067", - "name": "jlpt", - "type": 30 - }, - { - "id": "5:9147057123672087105", - "name": "slug", - "type": 9 - }, - { - "id": "6:5908719510010444548", - "name": "tags", - "type": 30 - } - ], - "relations": [ - { - "id": "1:1762405519516054052", - "name": "japanese", - "targetId": "4:5830034738494786681" - }, - { - "id": "2:5662556255405307520", - "name": "senses", - "targetId": "8:7499450265299287403" - } - ] - }, - { - "id": "6:6175990861942758315", - "lastPropertyId": "2:6228403848602783530", - "name": "JishoResultMeta", - "properties": [ - { - "id": "1:2609861734144336951", - "name": "id", - "type": 6, - "flags": 1 - }, - { - "id": "2:6228403848602783530", - "name": "status", - "type": 6 - } - ], - "relations": [] - }, - { - "id": "7:8388739279951258717", - "lastPropertyId": "3:6475272726803052671", - "name": "JishoSenseLink", - "properties": [ - { - "id": "1:9038298290884158108", - "name": "id", - "type": 6, - "flags": 1 - }, - { - "id": "2:3536322409202325005", - "name": "text", - "type": 9 - }, - { - "id": "3:6475272726803052671", - "name": "url", - "type": 9 - } - ], - "relations": [] - }, - { - "id": "8:7499450265299287403", - "lastPropertyId": "8:8987388154341761734", - "name": "JishoWordSense", - "properties": [ - { - "id": "1:3215440847258041904", - "name": "id", - "type": 6, - "flags": 1 - }, - { - "id": "2:2015550844387658352", - "name": "antonyms", - "type": 30 - }, - { - "id": "3:5828592811743363528", - "name": "english_definitions", - "type": 30 - }, - { - "id": "4:5593994833762859570", - "name": "info", - "type": 30 - }, - { - "id": "5:2972516533060921751", - "name": "parts_of_speech", - "type": 30 - }, - { - "id": "6:116167531949398184", - "name": "restrictions", - "type": 30 - }, - { - "id": "7:5268205144755091970", - "name": "see_also", - "type": 30 - }, - { - "id": "8:8987388154341761734", - "name": "tags", - "type": 30 - } - ], - "relations": [ - { - "id": "4:554428283260148269", - "name": "links", - "targetId": "7:8388739279951258717" - } - ] - }, - { - "id": "9:6483665137820532859", - "lastPropertyId": "2:8047458152016460696", - "name": "SearchResult", - "properties": [ - { - "id": "1:1744658189464710184", - "name": "id", - "type": 6, - "flags": 1 - }, - { - "id": "2:8047458152016460696", - "name": "metaId", - "type": 11, - "flags": 520, - "indexId": "2:2854883655423126351", - "relationTarget": "JishoResultMeta" - } - ], - "relations": [ - { - "id": "3:9171394818028481706", - "name": "data", - "targetId": "5:814015574151442186" - } - ] - }, - { - "id": "10:2511293769307589652", - "lastPropertyId": "3:7310514284446208088", + "id": "1:8135239166970424087", + "lastPropertyId": "3:1930470268740402049", "name": "KanjiResult", "properties": [ { - "id": "1:4875831913401260727", + "id": "1:2681934095975267680", "name": "id", "type": 6, "flags": 1 }, { - "id": "2:2639524138758004976", + "id": "2:4514526257378540330", "name": "timestamp", "type": 10 }, { - "id": "3:7310514284446208088", + "id": "3:1930470268740402049", "name": "kanji", "type": 9 } @@ -260,23 +28,23 @@ "relations": [] }, { - "id": "11:8718716930258187923", - "lastPropertyId": "3:6047999002753663080", + "id": "2:461492167249325765", + "lastPropertyId": "3:7573103520245228403", "name": "SearchString", "properties": [ { - "id": "1:8056495551508046109", + "id": "1:4297905889790758495", "name": "id", "type": 6, "flags": 1 }, { - "id": "2:5805071287032353000", + "id": "2:4157902147911002923", "name": "timestamp", "type": 10 }, { - "id": "3:6047999002753663080", + "id": "3:7573103520245228403", "name": "query", "type": 9 } @@ -284,56 +52,47 @@ "relations": [] }, { - "id": "12:8709403319711854658", - "lastPropertyId": "4:4071472200738865726", + "id": "3:8314315977756262774", + "lastPropertyId": "4:7972948456299367594", "name": "WordResult", "properties": [ { - "id": "1:2725285997242709614", + "id": "1:8286440150679521496", "name": "id", "type": 6, "flags": 1 }, { - "id": "2:6271798504226631398", + "id": "2:2698026687178480112", "name": "timestamp", "type": 10 }, { - "id": "3:5467536225310784192", + "id": "3:8750782874894963158", "name": "word", "type": 9 }, { - "id": "4:4071472200738865726", + "id": "4:7972948456299367594", "name": "searchStringId", "type": 11, "flags": 520, - "indexId": "3:5534321127094586184", + "indexId": "1:6146948198859733323", "relationTarget": "SearchString" } ], "relations": [] } ], - "lastEntityId": "12:8709403319711854658", - "lastIndexId": "3:5534321127094586184", - "lastRelationId": "4:554428283260148269", + "lastEntityId": "3:8314315977756262774", + "lastIndexId": "1:6146948198859733323", + "lastRelationId": "0:0", "lastSequenceId": "0:0", "modelVersion": 5, "modelVersionParserMinimum": 5, - "retiredEntityUids": [ - 2061102273968386021, - 7471000004971513655 - ], + "retiredEntityUids": [], "retiredIndexUids": [], - "retiredPropertyUids": [ - 1377817599424560887, - 182004738902401315, - 647032929519296287, - 8448353731705407210, - 1530573958565295186 - ], + "retiredPropertyUids": [], "retiredRelationUids": [], "version": 1 } \ No newline at end of file diff --git a/lib/services/jisho_api/kanji_search.dart b/lib/services/jisho_api/kanji_search.dart index 92e01e2..2c55d61 100644 --- a/lib/services/jisho_api/kanji_search.dart +++ b/lib/services/jisho_api/kanji_search.dart @@ -1,6 +1,6 @@ import 'package:unofficial_jisho_api/api.dart' as jisho; -String _convertGrade(String grade) { +String? _convertGrade(String grade) { const conversionTable = { "grade 1": "小1", "grade 2": "小2", @@ -16,8 +16,11 @@ String _convertGrade(String grade) { return conversionTable[grade]; } +// TODO: fix this logic + Future fetchKanji(String kanji) async { final result = await jisho.searchForKanji(kanji); - result.taughtIn = _convertGrade(result.taughtIn); + if (result.data != null && result.data?.taughtIn != null) + result.data!.taughtIn = _convertGrade(result.data!.taughtIn!); return result; } \ No newline at end of file diff --git a/lib/services/kanji_suggestions.dart b/lib/services/kanji_suggestions.dart index a2adfc2..d1e0eda 100644 --- a/lib/services/kanji_suggestions.dart +++ b/lib/services/kanji_suggestions.dart @@ -1,5 +1,10 @@ final kanjiPattern = RegExp(r'[\u3400-\u4DB5\u4E00-\u9FCB\uF900-\uFA6A]'); List kanjiSuggestions(String string) { - return kanjiPattern.allMatches(string).map((match) => match.group(0)).toList(); -} \ No newline at end of file + return kanjiPattern + .allMatches(string) + .map((match) => match.group(0)) + .where((element) => element != null) + .map((element) => element!) + .toList(); +} diff --git a/lib/view/components/history/kanji_search_item.dart b/lib/view/components/history/kanji_search_item.dart index 3a229a2..fc60ead 100644 --- a/lib/view/components/history/kanji_search_item.dart +++ b/lib/view/components/history/kanji_search_item.dart @@ -5,7 +5,7 @@ import 'package:jisho_study_tool/models/history/kanji_result.dart'; class _KanjiSearchItemHeader extends StatelessWidget { final KanjiResult result; - const _KanjiSearchItemHeader(this.result, {Key key}) : super(key: key); + const _KanjiSearchItemHeader(this.result, {Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -16,7 +16,7 @@ class _KanjiSearchItemHeader extends StatelessWidget { class KanjiSearchItem extends StatelessWidget { final KanjiResult result; - const KanjiSearchItem(this.result,{Key key}) : super(key: key); + const KanjiSearchItem(this.result,{Key? key}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/lib/view/components/history/search_item.dart b/lib/view/components/history/search_item.dart index e058ea1..1ec423b 100644 --- a/lib/view/components/history/search_item.dart +++ b/lib/view/components/history/search_item.dart @@ -5,7 +5,7 @@ import 'package:jisho_study_tool/models/history/search_string.dart'; class SearchItemHeader extends StatelessWidget { final SearchString _search; - const SearchItemHeader(this._search, {Key key}) : super(key: key); + const SearchItemHeader(this._search, {Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -18,7 +18,7 @@ class SearchItemHeader extends StatelessWidget { class SearchItem extends StatelessWidget { final SearchString _search; - const SearchItem(this._search, {Key key}) : super(key: key); + const SearchItem(this._search, {Key? key}) : super(key: key); @override Widget build(BuildContext context) { diff --git a/lib/view/components/kanji/kanji_search_bar.dart b/lib/view/components/kanji/kanji_search_bar.dart index 2248eb4..62c95f6 100644 --- a/lib/view/components/kanji/kanji_search_bar.dart +++ b/lib/view/components/kanji/kanji_search_bar.dart @@ -35,9 +35,11 @@ class _KanjiSearchBarState extends State { } void _pasteText() async { - ClipboardData clipboardData = await Clipboard.getData('text/plain'); - textController.text = clipboardData.text; - updateSuggestions(); + ClipboardData? clipboardData = await Clipboard.getData('text/plain'); + if (clipboardData != null && clipboardData.text != null) { + textController.text = clipboardData.text!; + updateSuggestions(); + } } @override diff --git a/lib/view/components/kanji/kanji_search_options_bar.dart b/lib/view/components/kanji/kanji_search_options_bar.dart index 080f15c..97c0dee 100644 --- a/lib/view/components/kanji/kanji_search_options_bar.dart +++ b/lib/view/components/kanji/kanji_search_options_bar.dart @@ -5,7 +5,7 @@ import 'package:jisho_study_tool/bloc/kanji/kanji_bloc.dart'; //TODO: Make buttons have an effect class KanjiSearchOptionsBar extends StatelessWidget { - const KanjiSearchOptionsBar({Key key}) : super(key: key); + const KanjiSearchOptionsBar({Key? key}) : super(key: key); @override Widget build(BuildContext context) { @@ -42,8 +42,12 @@ class KanjiSearchOptionsBar extends StatelessWidget { class _IconButton extends StatelessWidget { final Widget icon; - final Function onPressed; - const _IconButton({this.icon, this.onPressed, Key key}) : super(key: key); + final void Function()? onPressed; + const _IconButton({ + required this.icon, + required this.onPressed, + Key? key, + }) : super(key: key); @override Widget build(BuildContext context) { diff --git a/lib/view/components/kanji/result/kunyomi.dart b/lib/view/components/kanji/result/kunyomi.dart index f9545fc..beaec3f 100644 --- a/lib/view/components/kanji/result/kunyomi.dart +++ b/lib/view/components/kanji/result/kunyomi.dart @@ -2,8 +2,8 @@ import 'package:flutter/material.dart'; class Kunyomi extends StatelessWidget { final List kunyomi; - List<_KunyomiCard> kunyomiCards; - bool expandable; + late final List<_KunyomiCard> kunyomiCards; + late final bool expandable; Kunyomi(this.kunyomi) { kunyomiCards = kunyomi.map((kunyomi) => _KunyomiCard(kunyomi)).toList(); @@ -18,11 +18,11 @@ class Kunyomi extends StatelessWidget { vertical: 5.0, ), alignment: Alignment.centerLeft, - child: _KunyomiWrapper(context), + child: _kunyomiWrapper(context), ); } - Widget _KunyomiWrapper(BuildContext context) { + Widget _kunyomiWrapper(BuildContext context) { if (expandable) { return ExpansionTile( initiallyExpanded: false, diff --git a/lib/view/components/kanji/result/meaning.dart b/lib/view/components/kanji/result/meaning.dart index 0cf0adf..b035dec 100644 --- a/lib/view/components/kanji/result/meaning.dart +++ b/lib/view/components/kanji/result/meaning.dart @@ -1,9 +1,9 @@ import 'package:flutter/material.dart'; class Meaning extends StatelessWidget { - List meanings; - List<_MeaningCard> meaningCards; - bool expandable; + late final List meanings; + late final List<_MeaningCard> meaningCards; + late final bool expandable; @override Widget build(BuildContext context) { @@ -13,11 +13,11 @@ class Meaning extends StatelessWidget { vertical: 5.0, ), alignment: Alignment.centerLeft, - child: _MeaningWrapper(context), + child: _meaningWrapper(context), ); } - Widget _MeaningWrapper(BuildContext context) { + Widget _meaningWrapper(BuildContext context) { if (expandable) { return ExpansionTile( initiallyExpanded: false, diff --git a/lib/view/components/kanji/result/onyomi.dart b/lib/view/components/kanji/result/onyomi.dart index 9839092..bebfc1a 100644 --- a/lib/view/components/kanji/result/onyomi.dart +++ b/lib/view/components/kanji/result/onyomi.dart @@ -2,8 +2,8 @@ import 'package:flutter/material.dart'; class Onyomi extends StatelessWidget { final List onyomi; - List<_OnyomiCard> onyomiCards; - bool expandable; + late final List<_OnyomiCard> onyomiCards; + late final bool expandable; Onyomi(this.onyomi) { onyomiCards = onyomi.map((onyomi) => _OnyomiCard(onyomi)).toList(); @@ -18,11 +18,11 @@ class Onyomi extends StatelessWidget { vertical: 5.0, ), alignment: Alignment.centerLeft, - child: _OnyomiWrapper(context), + child: _onyomiWrapper(context), ); } - Widget _OnyomiWrapper(BuildContext context) { + Widget _onyomiWrapper(BuildContext context) { if (expandable) { return ExpansionTile( initiallyExpanded: false, diff --git a/lib/view/components/search/LanguageSelector.dart b/lib/view/components/search/LanguageSelector.dart index 3f176cc..1da238b 100644 --- a/lib/view/components/search/LanguageSelector.dart +++ b/lib/view/components/search/LanguageSelector.dart @@ -7,8 +7,8 @@ class LanguageSelector extends StatefulWidget { } class _LanguageSelectorState extends State { - SharedPreferences prefs; - List isSelected; + late final SharedPreferences prefs; + late List isSelected; @override void initState() { @@ -31,11 +31,11 @@ class _LanguageSelectorState extends State { .toList()); } - List _getSelectedStatus() { + List? _getSelectedStatus() { return prefs .getStringList('languageSelectorStatus') ?.map((s) => s == '1') - ?.toList(); + .toList(); } @override diff --git a/lib/view/components/search/search_result_page/parts/common_badge.dart b/lib/view/components/search/search_result_page/parts/common_badge.dart index 77998f8..7255d9f 100644 --- a/lib/view/components/search/search_result_page/parts/common_badge.dart +++ b/lib/view/components/search/search_result_page/parts/common_badge.dart @@ -4,9 +4,7 @@ import 'package:jisho_study_tool/view/components/search/search_result_page/parts class CommonBadge extends StatelessWidget { bool isCommon; - CommonBadge(this.isCommon) { - this.isCommon ??= false; - } + CommonBadge(this.isCommon); @override Widget build(BuildContext context) { diff --git a/lib/view/components/search/search_result_page/parts/header.dart b/lib/view/components/search/search_result_page/parts/header.dart index 554000f..c08eaa4 100644 --- a/lib/view/components/search/search_result_page/parts/header.dart +++ b/lib/view/components/search/search_result_page/parts/header.dart @@ -14,8 +14,9 @@ class JapaneseHeader extends StatelessWidget { padding: EdgeInsets.only(left: 10.0), child: Column( children: [ - (hasFurigana) ? Text(word.reading) : Text(''), - (hasFurigana) ? Text(word.word) : Text(word.reading ?? word.word), + // TODO: take a look at this logic + (hasFurigana) ? Text(word.reading!) : Text(''), + (hasFurigana) ? Text(word.word!) : Text(word.reading ?? word.word!), ], ), ); diff --git a/lib/view/components/search/search_result_page/parts/other_forms.dart b/lib/view/components/search/search_result_page/parts/other_forms.dart index 837fd5b..fa397d1 100644 --- a/lib/view/components/search/search_result_page/parts/other_forms.dart +++ b/lib/view/components/search/search_result_page/parts/other_forms.dart @@ -37,8 +37,9 @@ class _KanaBox extends StatelessWidget { return Container( child: Column( children: [ - (hasFurigana) ? Text(word.reading) : Text(''), - (hasFurigana) ? Text(word.word) : Text(word.reading), + // TODO: take a look at this logic + (hasFurigana) ? Text(word.reading ?? '') : Text(''), + (hasFurigana) ? Text(word.word!) : Text(word.reading ?? ''), ], ), margin: EdgeInsets.symmetric( diff --git a/lib/view/components/search/search_result_page/parts/senses.dart b/lib/view/components/search/search_result_page/parts/senses.dart index d6666d1..728b3a6 100644 --- a/lib/view/components/search/search_result_page/parts/senses.dart +++ b/lib/view/components/search/search_result_page/parts/senses.dart @@ -35,7 +35,7 @@ class _Sense extends StatelessWidget { style: TextStyle(color: Colors.grey), ), Text( - sense.parts_of_speech.join(', '), + sense.partsOfSpeech.join(', '), style: TextStyle(fontWeight: FontWeight.bold), textAlign: TextAlign.left, ), @@ -46,7 +46,7 @@ class _Sense extends StatelessWidget { children:[ Column( children: - sense.english_definitions.map((def) => Text(def)).toList(), + sense.englishDefinitions.map((def) => Text(def)).toList(), crossAxisAlignment: CrossAxisAlignment.start, ), ] diff --git a/lib/view/components/search/search_result_page/search_card.dart b/lib/view/components/search/search_result_page/search_card.dart index c6d96b7..235047c 100644 --- a/lib/view/components/search/search_result_page/search_card.dart +++ b/lib/view/components/search/search_result_page/search_card.dart @@ -11,8 +11,8 @@ import './parts/other_forms.dart'; class SearchResultCard extends StatelessWidget { final JishoResult result; - JishoJapaneseWord mainWord; - List otherForms; + late final JishoJapaneseWord mainWord; + late final List otherForms; SearchResultCard(this.result) { this.mainWord = result.japanese[0]; @@ -31,7 +31,7 @@ class SearchResultCard extends StatelessWidget { children: [ WKBadge(result.tags.firstWhere((tag) => tag.contains("wanikani"), orElse: () => '')), JLPTBadge(result.jlpt.isNotEmpty ? result.jlpt[0] : ''), - CommonBadge(result.is_common) + CommonBadge(result.isCommon!) ], ) ], diff --git a/lib/view/screens/kanji/result.dart b/lib/view/screens/kanji/result.dart index b73bd0a..1d8e247 100644 --- a/lib/view/screens/kanji/result.dart +++ b/lib/view/screens/kanji/result.dart @@ -15,7 +15,8 @@ import 'package:jisho_study_tool/view/components/kanji/result/kunyomi.dart'; import 'package:jisho_study_tool/view/components/kanji/result/examples.dart'; class KanjiResultCard extends StatelessWidget { - final jisho.KanjiResult result; + late final String query; + late final jisho.KanjiResultData resultData; @override Widget build(BuildContext context) { @@ -34,26 +35,26 @@ class KanjiResultCard extends StatelessWidget { Flexible( flex: 1, fit: FlexFit.tight, - child: Center(child: Header(result.query)), + child: Center(child: Header(query)), ), Flexible( flex: 1, fit: FlexFit.tight, child: Center( - child: Radical(result.radical), + child: (resultData.radical != null) ? Radical(resultData.radical!) : SizedBox(), ), ), ], ), ), - Meaning(result.meaning), - result.onyomi.length != 0 ? Onyomi(result.onyomi) : SizedBox.shrink(), - result.kunyomi.length != 0 ? Kunyomi(result.kunyomi) : SizedBox.shrink(), + Meaning(resultData.meaning), + resultData.onyomi.length != 0 ? Onyomi(resultData.onyomi) : SizedBox.shrink(), + resultData.kunyomi.length != 0 ? Kunyomi(resultData.kunyomi) : SizedBox.shrink(), IntrinsicHeight( child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ - StrokeOrderGif(result.strokeOrderGifUri), + StrokeOrderGif(resultData.strokeOrderGifUri), Container( child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, @@ -62,19 +63,19 @@ class KanjiResultCard extends StatelessWidget { Row( children: [ Text("JLPT: ", style: TextStyle(fontSize: 20.0)), - JlptLevel(result.jlptLevel ?? "⨉"), + JlptLevel(resultData.jlptLevel ?? "⨉"), ], ), Row( children: [ Text("Grade: ", style: TextStyle(fontSize: 20.0)), - Grade(result.taughtIn ?? "⨉"), + Grade(resultData.taughtIn ?? "⨉"), ], ), Row( children: [ Text("Rank: ", style: TextStyle(fontSize: 20.0)), - Rank(result.newspaperFrequencyRank ?? -1), + Rank(resultData.newspaperFrequencyRank ?? -1), ], ), ], @@ -83,10 +84,19 @@ class KanjiResultCard extends StatelessWidget { ], ), ), - Examples(result.onyomiExamples, result.kunyomiExamples), + Examples(resultData.onyomiExamples, resultData.kunyomiExamples), ], ); } - KanjiResultCard(this.result); + KanjiResultCard({required jisho.KanjiResult result}) { + + query = result.query; + + // TODO: Handle this kind of exception before widget is initialized + if (result.data == null) + throw Exception(); + + resultData = result.data!; + } } \ No newline at end of file diff --git a/lib/view/screens/kanji/search.dart b/lib/view/screens/kanji/search.dart index 5949094..ad2d5c4 100644 --- a/lib/view/screens/kanji/search.dart +++ b/lib/view/screens/kanji/search.dart @@ -8,7 +8,7 @@ import 'package:jisho_study_tool/view/components/kanji/kanji_search_bar.dart'; import 'package:jisho_study_tool/view/components/kanji/kanji_search_options_bar.dart'; class SearchScreen extends StatefulWidget { - SearchScreen({Key key}) : super(key: key); + SearchScreen({Key? key}) : super(key: key); @override _SearchScreenState createState() => _SearchScreenState(); @@ -16,8 +16,8 @@ class SearchScreen extends StatefulWidget { class _SearchScreenState extends State with SingleTickerProviderStateMixin { - AnimationController _controller; - Animation _searchbarMovementAnimation; + late final AnimationController _controller; + late final Animation _searchbarMovementAnimation; @override void initState() { diff --git a/lib/view/screens/kanji/view.dart b/lib/view/screens/kanji/view.dart index 25c4c12..f223ccc 100644 --- a/lib/view/screens/kanji/view.dart +++ b/lib/view/screens/kanji/view.dart @@ -28,7 +28,7 @@ class KanjiView extends StatelessWidget { else if (state is KanjiSearchLoading) return LoadingScreen(); else if (state is KanjiSearchFinished) return WillPopScope( - child: KanjiResultCard(state.kanji), + child: KanjiResultCard(result: state.kanji), onWillPop: () async { BlocProvider.of(context) .add(ReturnToInitialState()); diff --git a/pubspec.yaml b/pubspec.yaml index 1f98988..19e834e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,31 +1,31 @@ name: jisho_study_tool -description: A new Flutter project. +description: A dictionary app for studying japanese version: 1.0.0+1 environment: - sdk: ">=2.1.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" dependencies: + animated_size_and_fade: ^2.0.0 + division: ^0.9.0 flutter: sdk: flutter - - shared_preferences: "^2.0.3" + flutter_bloc: ^7.0.1 + flutter_slidable: ^0.6.0 + mdi: ^5.0.0-nullsafety.0 objectbox: ^1.1.1 - objectbox_flutter_libs: any + objectbox_flutter_libs: ^1.1.1 path_provider: ^2.0.2 + shared_preferences: ^2.0.6 + unofficial_jisho_api: ^2.0.2 + url_launcher: ^6.0.9 - # cupertino_icons: ^0.1.2 - mdi: ^4.0.0 - unofficial_jisho_api: ^1.1.0 - flutter_bloc: ^7.0.0 - url_launcher: ^6.0.3 - division: ^0.8.8 dev_dependencies: + build_runner: ^2.0.6 flutter_test: sdk: flutter - build_runner: ^1.0.0 - objectbox_generator: any + objectbox_generator: ^1.1.1 flutter: uses-material-design: true