1
0
mirror of https://github.com/h7x4/Jisho-Study-Tool.git synced 2024-12-21 13:37:29 +01:00

Update to null safety

This commit is contained in:
Oystein Kristoffer Tveit 2021-07-26 21:39:17 +02:00
parent b86e0ae2f2
commit d82fcbe427
28 changed files with 195 additions and 410 deletions

2
.gitignore vendored
View File

@ -30,6 +30,8 @@
.pub/ .pub/
/build/ /build/
objectbox.g.dart
# Web related # Web related
lib/generated_plugin_registrant.dart lib/generated_plugin_registrant.dart

View File

@ -31,7 +31,7 @@ class KanjiSearchFinished extends KanjiState {
final bool starred; final bool starred;
const KanjiSearchFinished({ const KanjiSearchFinished({
this.kanji, required this.kanji,
this.starred = false, this.starred = false,
}); });
} }

View File

@ -42,7 +42,7 @@ class SearchBloc extends Bloc<SearchEvent, SearchState> {
try { try {
addSearchToDB(event.searchString); addSearchToDB(event.searchString);
final searchResults = await fetchJishoResults(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 { } on Exception {
yield SearchError('Something went wrong'); yield SearchError('Something went wrong');
} }

View File

@ -5,9 +5,9 @@ import 'package:path_provider/path_provider.dart';
import 'package:path/path.dart'; import 'package:path/path.dart';
import 'package:jisho_study_tool/objectbox.g.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/database/database_bloc.dart';
import 'package:jisho_study_tool/bloc/kanji/kanji_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/kanji/view.dart';
import 'package:jisho_study_tool/view/screens/history.dart'; import 'package:jisho_study_tool/view/screens/history.dart';
@ -46,7 +46,7 @@ class Home extends StatefulWidget {
class _HomeState extends State<Home> { class _HomeState extends State<Home> {
int selectedPage = 0; int selectedPage = 0;
Store _store; late final Store _store;
@override @override
void initState() { void initState() {
@ -136,8 +136,8 @@ class _Page {
Widget titleBar; Widget titleBar;
_Page({ _Page({
this.content, required this.content,
this.titleBar, required this.titleBar,
}); });
} }

View File

@ -11,8 +11,8 @@ class KanjiResult {
String kanji; String kanji;
KanjiResult({ KanjiResult({
this.timestamp, required this.timestamp,
this.kanji, required this.kanji,
}); });
@override @override

View File

@ -15,8 +15,8 @@ class SearchString {
final chosenResults = ToMany<WordResult>(); final chosenResults = ToMany<WordResult>();
SearchString({ SearchString({
this.timestamp, required this.timestamp,
this.query, required this.query,
}); });
@override @override

View File

@ -14,8 +14,8 @@ class WordResult {
final searchString = ToOne<SearchString>(); final searchString = ToOne<SearchString>();
WordResult({ WordResult({
this.timestamp, required this.timestamp,
this.word, required this.word,
}); });
@override @override

View File

@ -1,72 +1,72 @@
import 'package:objectbox/objectbox.dart'; // import 'package:objectbox/objectbox.dart';
import 'package:unofficial_jisho_api/api.dart' as jisho; // import 'package:unofficial_jisho_api/api.dart' as jisho;
@Entity() // @Entity()
class SearchResult { // class SearchResult {
int id = 0; // int id = 0;
final meta = ToOne<JishoResultMeta>(); // final meta = ToOne<JishoResultMeta>();
final data = ToMany<JishoResult>(); // final data = ToMany<JishoResult>();
// SearchResult(JishoAPIResult result) { // // SearchResult(JishoAPIResult result) {
// this.data = result.data; // // this.data = result.data;
// this.meta = result.meta; // // this.meta = result.meta;
// } // // }
// JishoAPIResult toJishoAPIResult() { // // JishoAPIResult toJishoAPIResult() {
// return JishoAPIResult(meta: this.meta, data: this.data); // // return JishoAPIResult(meta: this.meta, data: this.data);
// } // // }
} // }
@Entity() // @Entity()
class JishoResultMeta { // class JishoResultMeta {
int id = 0; // int id = 0;
int status; // int status;
} // }
@Entity() // @Entity()
class JishoResult { // class JishoResult {
int id = 0; // int id = 0;
final attribution = ToOne<JishoAttribution>(); // final attribution = ToOne<JishoAttribution>();
bool is_common; // bool is_common;
final japanese = ToMany<JishoJapaneseWord>(); // final japanese = ToMany<JishoJapaneseWord>();
List<String> jlpt; // List<String> jlpt;
final senses = ToMany<JishoWordSense>(); // final senses = ToMany<JishoWordSense>();
String slug; // String slug;
List<String> tags; // List<String> tags;
} // }
@Entity() // @Entity()
class JishoAttribution { // class JishoAttribution {
int id = 0; // int id = 0;
String dbpedia; // String dbpedia;
String jmdict; // String jmdict;
bool jmnedict; // bool jmnedict;
} // }
@Entity() // @Entity()
class JishoJapaneseWord { // class JishoJapaneseWord {
int id = 0; // int id = 0;
String reading; // String reading;
String word; // String word;
} // }
@Entity() // @Entity()
class JishoWordSense { // class JishoWordSense {
int id = 0; // int id = 0;
List<String> antonyms; // List<String> antonyms;
List<String> english_definitions; // List<String> english_definitions;
List<String> info; // List<String> info;
final links = ToMany<JishoSenseLink>(); // final links = ToMany<JishoSenseLink>();
List<String> parts_of_speech; // List<String> parts_of_speech;
List<String> restrictions; // List<String> restrictions;
List<String> see_also; // List<String> see_also;
List<dynamic> source; // List<dynamic> source;
List<String> tags; // List<String> tags;
} // }
@Entity() // @Entity()
class JishoSenseLink { // class JishoSenseLink {
int id = 0; // int id = 0;
String text; // String text;
String url; // String url;
} // }

View File

@ -4,255 +4,23 @@
"_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.", "_note3": "If you have VCS merge conflicts, you must resolve them according to ObjectBox docs.",
"entities": [ "entities": [
{ {
"id": "3:7851566044119418641", "id": "1:8135239166970424087",
"lastPropertyId": "4:2352718426928758061", "lastPropertyId": "3:1930470268740402049",
"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",
"name": "KanjiResult", "name": "KanjiResult",
"properties": [ "properties": [
{ {
"id": "1:4875831913401260727", "id": "1:2681934095975267680",
"name": "id", "name": "id",
"type": 6, "type": 6,
"flags": 1 "flags": 1
}, },
{ {
"id": "2:2639524138758004976", "id": "2:4514526257378540330",
"name": "timestamp", "name": "timestamp",
"type": 10 "type": 10
}, },
{ {
"id": "3:7310514284446208088", "id": "3:1930470268740402049",
"name": "kanji", "name": "kanji",
"type": 9 "type": 9
} }
@ -260,23 +28,23 @@
"relations": [] "relations": []
}, },
{ {
"id": "11:8718716930258187923", "id": "2:461492167249325765",
"lastPropertyId": "3:6047999002753663080", "lastPropertyId": "3:7573103520245228403",
"name": "SearchString", "name": "SearchString",
"properties": [ "properties": [
{ {
"id": "1:8056495551508046109", "id": "1:4297905889790758495",
"name": "id", "name": "id",
"type": 6, "type": 6,
"flags": 1 "flags": 1
}, },
{ {
"id": "2:5805071287032353000", "id": "2:4157902147911002923",
"name": "timestamp", "name": "timestamp",
"type": 10 "type": 10
}, },
{ {
"id": "3:6047999002753663080", "id": "3:7573103520245228403",
"name": "query", "name": "query",
"type": 9 "type": 9
} }
@ -284,56 +52,47 @@
"relations": [] "relations": []
}, },
{ {
"id": "12:8709403319711854658", "id": "3:8314315977756262774",
"lastPropertyId": "4:4071472200738865726", "lastPropertyId": "4:7972948456299367594",
"name": "WordResult", "name": "WordResult",
"properties": [ "properties": [
{ {
"id": "1:2725285997242709614", "id": "1:8286440150679521496",
"name": "id", "name": "id",
"type": 6, "type": 6,
"flags": 1 "flags": 1
}, },
{ {
"id": "2:6271798504226631398", "id": "2:2698026687178480112",
"name": "timestamp", "name": "timestamp",
"type": 10 "type": 10
}, },
{ {
"id": "3:5467536225310784192", "id": "3:8750782874894963158",
"name": "word", "name": "word",
"type": 9 "type": 9
}, },
{ {
"id": "4:4071472200738865726", "id": "4:7972948456299367594",
"name": "searchStringId", "name": "searchStringId",
"type": 11, "type": 11,
"flags": 520, "flags": 520,
"indexId": "3:5534321127094586184", "indexId": "1:6146948198859733323",
"relationTarget": "SearchString" "relationTarget": "SearchString"
} }
], ],
"relations": [] "relations": []
} }
], ],
"lastEntityId": "12:8709403319711854658", "lastEntityId": "3:8314315977756262774",
"lastIndexId": "3:5534321127094586184", "lastIndexId": "1:6146948198859733323",
"lastRelationId": "4:554428283260148269", "lastRelationId": "0:0",
"lastSequenceId": "0:0", "lastSequenceId": "0:0",
"modelVersion": 5, "modelVersion": 5,
"modelVersionParserMinimum": 5, "modelVersionParserMinimum": 5,
"retiredEntityUids": [ "retiredEntityUids": [],
2061102273968386021,
7471000004971513655
],
"retiredIndexUids": [], "retiredIndexUids": [],
"retiredPropertyUids": [ "retiredPropertyUids": [],
1377817599424560887,
182004738902401315,
647032929519296287,
8448353731705407210,
1530573958565295186
],
"retiredRelationUids": [], "retiredRelationUids": [],
"version": 1 "version": 1
} }

View File

@ -1,6 +1,6 @@
import 'package:unofficial_jisho_api/api.dart' as jisho; import 'package:unofficial_jisho_api/api.dart' as jisho;
String _convertGrade(String grade) { String? _convertGrade(String grade) {
const conversionTable = { const conversionTable = {
"grade 1": "小1", "grade 1": "小1",
"grade 2": "小2", "grade 2": "小2",
@ -16,8 +16,11 @@ String _convertGrade(String grade) {
return conversionTable[grade]; return conversionTable[grade];
} }
// TODO: fix this logic
Future<jisho.KanjiResult> fetchKanji(String kanji) async { Future<jisho.KanjiResult> fetchKanji(String kanji) async {
final result = await jisho.searchForKanji(kanji); 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; return result;
} }

View File

@ -1,5 +1,10 @@
final kanjiPattern = RegExp(r'[\u3400-\u4DB5\u4E00-\u9FCB\uF900-\uFA6A]'); final kanjiPattern = RegExp(r'[\u3400-\u4DB5\u4E00-\u9FCB\uF900-\uFA6A]');
List<String> kanjiSuggestions(String string) { List<String> kanjiSuggestions(String string) {
return kanjiPattern.allMatches(string).map((match) => match.group(0)).toList(); return kanjiPattern
} .allMatches(string)
.map((match) => match.group(0))
.where((element) => element != null)
.map((element) => element!)
.toList();
}

View File

@ -5,7 +5,7 @@ import 'package:jisho_study_tool/models/history/kanji_result.dart';
class _KanjiSearchItemHeader extends StatelessWidget { class _KanjiSearchItemHeader extends StatelessWidget {
final KanjiResult result; final KanjiResult result;
const _KanjiSearchItemHeader(this.result, {Key key}) : super(key: key); const _KanjiSearchItemHeader(this.result, {Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -16,7 +16,7 @@ class _KanjiSearchItemHeader extends StatelessWidget {
class KanjiSearchItem extends StatelessWidget { class KanjiSearchItem extends StatelessWidget {
final KanjiResult result; final KanjiResult result;
const KanjiSearchItem(this.result,{Key key}) : super(key: key); const KanjiSearchItem(this.result,{Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -5,7 +5,7 @@ import 'package:jisho_study_tool/models/history/search_string.dart';
class SearchItemHeader extends StatelessWidget { class SearchItemHeader extends StatelessWidget {
final SearchString _search; final SearchString _search;
const SearchItemHeader(this._search, {Key key}) : super(key: key); const SearchItemHeader(this._search, {Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -18,7 +18,7 @@ class SearchItemHeader extends StatelessWidget {
class SearchItem extends StatelessWidget { class SearchItem extends StatelessWidget {
final SearchString _search; final SearchString _search;
const SearchItem(this._search, {Key key}) : super(key: key); const SearchItem(this._search, {Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -35,9 +35,11 @@ class _KanjiSearchBarState extends State<KanjiSearchBar> {
} }
void _pasteText() async { void _pasteText() async {
ClipboardData clipboardData = await Clipboard.getData('text/plain'); ClipboardData? clipboardData = await Clipboard.getData('text/plain');
textController.text = clipboardData.text; if (clipboardData != null && clipboardData.text != null) {
updateSuggestions(); textController.text = clipboardData.text!;
updateSuggestions();
}
} }
@override @override

View File

@ -5,7 +5,7 @@ import 'package:jisho_study_tool/bloc/kanji/kanji_bloc.dart';
//TODO: Make buttons have an effect //TODO: Make buttons have an effect
class KanjiSearchOptionsBar extends StatelessWidget { class KanjiSearchOptionsBar extends StatelessWidget {
const KanjiSearchOptionsBar({Key key}) : super(key: key); const KanjiSearchOptionsBar({Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -42,8 +42,12 @@ class KanjiSearchOptionsBar extends StatelessWidget {
class _IconButton extends StatelessWidget { class _IconButton extends StatelessWidget {
final Widget icon; final Widget icon;
final Function onPressed; final void Function()? onPressed;
const _IconButton({this.icon, this.onPressed, Key key}) : super(key: key); const _IconButton({
required this.icon,
required this.onPressed,
Key? key,
}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
class Kunyomi extends StatelessWidget { class Kunyomi extends StatelessWidget {
final List<String> kunyomi; final List<String> kunyomi;
List<_KunyomiCard> kunyomiCards; late final List<_KunyomiCard> kunyomiCards;
bool expandable; late final bool expandable;
Kunyomi(this.kunyomi) { Kunyomi(this.kunyomi) {
kunyomiCards = kunyomi.map((kunyomi) => _KunyomiCard(kunyomi)).toList(); kunyomiCards = kunyomi.map((kunyomi) => _KunyomiCard(kunyomi)).toList();
@ -18,11 +18,11 @@ class Kunyomi extends StatelessWidget {
vertical: 5.0, vertical: 5.0,
), ),
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: _KunyomiWrapper(context), child: _kunyomiWrapper(context),
); );
} }
Widget _KunyomiWrapper(BuildContext context) { Widget _kunyomiWrapper(BuildContext context) {
if (expandable) { if (expandable) {
return ExpansionTile( return ExpansionTile(
initiallyExpanded: false, initiallyExpanded: false,

View File

@ -1,9 +1,9 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
class Meaning extends StatelessWidget { class Meaning extends StatelessWidget {
List<String> meanings; late final List<String> meanings;
List<_MeaningCard> meaningCards; late final List<_MeaningCard> meaningCards;
bool expandable; late final bool expandable;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -13,11 +13,11 @@ class Meaning extends StatelessWidget {
vertical: 5.0, vertical: 5.0,
), ),
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: _MeaningWrapper(context), child: _meaningWrapper(context),
); );
} }
Widget _MeaningWrapper(BuildContext context) { Widget _meaningWrapper(BuildContext context) {
if (expandable) { if (expandable) {
return ExpansionTile( return ExpansionTile(
initiallyExpanded: false, initiallyExpanded: false,

View File

@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
class Onyomi extends StatelessWidget { class Onyomi extends StatelessWidget {
final List<String> onyomi; final List<String> onyomi;
List<_OnyomiCard> onyomiCards; late final List<_OnyomiCard> onyomiCards;
bool expandable; late final bool expandable;
Onyomi(this.onyomi) { Onyomi(this.onyomi) {
onyomiCards = onyomi.map((onyomi) => _OnyomiCard(onyomi)).toList(); onyomiCards = onyomi.map((onyomi) => _OnyomiCard(onyomi)).toList();
@ -18,11 +18,11 @@ class Onyomi extends StatelessWidget {
vertical: 5.0, vertical: 5.0,
), ),
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: _OnyomiWrapper(context), child: _onyomiWrapper(context),
); );
} }
Widget _OnyomiWrapper(BuildContext context) { Widget _onyomiWrapper(BuildContext context) {
if (expandable) { if (expandable) {
return ExpansionTile( return ExpansionTile(
initiallyExpanded: false, initiallyExpanded: false,

View File

@ -7,8 +7,8 @@ class LanguageSelector extends StatefulWidget {
} }
class _LanguageSelectorState extends State<LanguageSelector> { class _LanguageSelectorState extends State<LanguageSelector> {
SharedPreferences prefs; late final SharedPreferences prefs;
List<bool> isSelected; late List<bool> isSelected;
@override @override
void initState() { void initState() {
@ -31,11 +31,11 @@ class _LanguageSelectorState extends State<LanguageSelector> {
.toList()); .toList());
} }
List<bool> _getSelectedStatus() { List<bool>? _getSelectedStatus() {
return prefs return prefs
.getStringList('languageSelectorStatus') .getStringList('languageSelectorStatus')
?.map((s) => s == '1') ?.map((s) => s == '1')
?.toList(); .toList();
} }
@override @override

View File

@ -4,9 +4,7 @@ import 'package:jisho_study_tool/view/components/search/search_result_page/parts
class CommonBadge extends StatelessWidget { class CommonBadge extends StatelessWidget {
bool isCommon; bool isCommon;
CommonBadge(this.isCommon) { CommonBadge(this.isCommon);
this.isCommon ??= false;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@ -14,8 +14,9 @@ class JapaneseHeader extends StatelessWidget {
padding: EdgeInsets.only(left: 10.0), padding: EdgeInsets.only(left: 10.0),
child: Column( child: Column(
children: [ children: [
(hasFurigana) ? Text(word.reading) : Text(''), // TODO: take a look at this logic
(hasFurigana) ? Text(word.word) : Text(word.reading ?? word.word), (hasFurigana) ? Text(word.reading!) : Text(''),
(hasFurigana) ? Text(word.word!) : Text(word.reading ?? word.word!),
], ],
), ),
); );

View File

@ -37,8 +37,9 @@ class _KanaBox extends StatelessWidget {
return Container( return Container(
child: Column( child: Column(
children: [ children: [
(hasFurigana) ? Text(word.reading) : Text(''), // TODO: take a look at this logic
(hasFurigana) ? Text(word.word) : Text(word.reading), (hasFurigana) ? Text(word.reading ?? '') : Text(''),
(hasFurigana) ? Text(word.word!) : Text(word.reading ?? ''),
], ],
), ),
margin: EdgeInsets.symmetric( margin: EdgeInsets.symmetric(

View File

@ -35,7 +35,7 @@ class _Sense extends StatelessWidget {
style: TextStyle(color: Colors.grey), style: TextStyle(color: Colors.grey),
), ),
Text( Text(
sense.parts_of_speech.join(', '), sense.partsOfSpeech.join(', '),
style: TextStyle(fontWeight: FontWeight.bold), style: TextStyle(fontWeight: FontWeight.bold),
textAlign: TextAlign.left, textAlign: TextAlign.left,
), ),
@ -46,7 +46,7 @@ class _Sense extends StatelessWidget {
children:[ children:[
Column( Column(
children: children:
sense.english_definitions.map((def) => Text(def)).toList(), sense.englishDefinitions.map((def) => Text(def)).toList(),
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
), ),
] ]

View File

@ -11,8 +11,8 @@ import './parts/other_forms.dart';
class SearchResultCard extends StatelessWidget { class SearchResultCard extends StatelessWidget {
final JishoResult result; final JishoResult result;
JishoJapaneseWord mainWord; late final JishoJapaneseWord mainWord;
List<JishoJapaneseWord> otherForms; late final List<JishoJapaneseWord> otherForms;
SearchResultCard(this.result) { SearchResultCard(this.result) {
this.mainWord = result.japanese[0]; this.mainWord = result.japanese[0];
@ -31,7 +31,7 @@ class SearchResultCard extends StatelessWidget {
children: [ children: [
WKBadge(result.tags.firstWhere((tag) => tag.contains("wanikani"), orElse: () => '')), WKBadge(result.tags.firstWhere((tag) => tag.contains("wanikani"), orElse: () => '')),
JLPTBadge(result.jlpt.isNotEmpty ? result.jlpt[0] : ''), JLPTBadge(result.jlpt.isNotEmpty ? result.jlpt[0] : ''),
CommonBadge(result.is_common) CommonBadge(result.isCommon!)
], ],
) )
], ],

View File

@ -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'; import 'package:jisho_study_tool/view/components/kanji/result/examples.dart';
class KanjiResultCard extends StatelessWidget { class KanjiResultCard extends StatelessWidget {
final jisho.KanjiResult result; late final String query;
late final jisho.KanjiResultData resultData;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -34,26 +35,26 @@ class KanjiResultCard extends StatelessWidget {
Flexible( Flexible(
flex: 1, flex: 1,
fit: FlexFit.tight, fit: FlexFit.tight,
child: Center(child: Header(result.query)), child: Center(child: Header(query)),
), ),
Flexible( Flexible(
flex: 1, flex: 1,
fit: FlexFit.tight, fit: FlexFit.tight,
child: Center( child: Center(
child: Radical(result.radical), child: (resultData.radical != null) ? Radical(resultData.radical!) : SizedBox(),
), ),
), ),
], ],
), ),
), ),
Meaning(result.meaning), Meaning(resultData.meaning),
result.onyomi.length != 0 ? Onyomi(result.onyomi) : SizedBox.shrink(), resultData.onyomi.length != 0 ? Onyomi(resultData.onyomi) : SizedBox.shrink(),
result.kunyomi.length != 0 ? Kunyomi(result.kunyomi) : SizedBox.shrink(), resultData.kunyomi.length != 0 ? Kunyomi(resultData.kunyomi) : SizedBox.shrink(),
IntrinsicHeight( IntrinsicHeight(
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [
StrokeOrderGif(result.strokeOrderGifUri), StrokeOrderGif(resultData.strokeOrderGifUri),
Container( Container(
child: Column( child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
@ -62,19 +63,19 @@ class KanjiResultCard extends StatelessWidget {
Row( Row(
children: [ children: [
Text("JLPT: ", style: TextStyle(fontSize: 20.0)), Text("JLPT: ", style: TextStyle(fontSize: 20.0)),
JlptLevel(result.jlptLevel ?? ""), JlptLevel(resultData.jlptLevel ?? ""),
], ],
), ),
Row( Row(
children: [ children: [
Text("Grade: ", style: TextStyle(fontSize: 20.0)), Text("Grade: ", style: TextStyle(fontSize: 20.0)),
Grade(result.taughtIn ?? ""), Grade(resultData.taughtIn ?? ""),
], ],
), ),
Row( Row(
children: [ children: [
Text("Rank: ", style: TextStyle(fontSize: 20.0)), 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!;
}
} }

View File

@ -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'; import 'package:jisho_study_tool/view/components/kanji/kanji_search_options_bar.dart';
class SearchScreen extends StatefulWidget { class SearchScreen extends StatefulWidget {
SearchScreen({Key key}) : super(key: key); SearchScreen({Key? key}) : super(key: key);
@override @override
_SearchScreenState createState() => _SearchScreenState(); _SearchScreenState createState() => _SearchScreenState();
@ -16,8 +16,8 @@ class SearchScreen extends StatefulWidget {
class _SearchScreenState extends State<SearchScreen> class _SearchScreenState extends State<SearchScreen>
with SingleTickerProviderStateMixin { with SingleTickerProviderStateMixin {
AnimationController _controller; late final AnimationController _controller;
Animation _searchbarMovementAnimation; late final Animation _searchbarMovementAnimation;
@override @override
void initState() { void initState() {

View File

@ -28,7 +28,7 @@ class KanjiView extends StatelessWidget {
else if (state is KanjiSearchLoading) return LoadingScreen(); else if (state is KanjiSearchLoading) return LoadingScreen();
else if (state is KanjiSearchFinished) else if (state is KanjiSearchFinished)
return WillPopScope( return WillPopScope(
child: KanjiResultCard(state.kanji), child: KanjiResultCard(result: state.kanji),
onWillPop: () async { onWillPop: () async {
BlocProvider.of<KanjiBloc>(context) BlocProvider.of<KanjiBloc>(context)
.add(ReturnToInitialState()); .add(ReturnToInitialState());

View File

@ -1,31 +1,31 @@
name: jisho_study_tool name: jisho_study_tool
description: A new Flutter project. description: A dictionary app for studying japanese
version: 1.0.0+1 version: 1.0.0+1
environment: environment:
sdk: ">=2.1.0 <3.0.0" sdk: ">=2.12.0 <3.0.0"
dependencies: dependencies:
animated_size_and_fade: ^2.0.0
division: ^0.9.0
flutter: flutter:
sdk: flutter sdk: flutter
flutter_bloc: ^7.0.1
shared_preferences: "^2.0.3" flutter_slidable: ^0.6.0
mdi: ^5.0.0-nullsafety.0
objectbox: ^1.1.1 objectbox: ^1.1.1
objectbox_flutter_libs: any objectbox_flutter_libs: ^1.1.1
path_provider: ^2.0.2 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: dev_dependencies:
build_runner: ^2.0.6
flutter_test: flutter_test:
sdk: flutter sdk: flutter
build_runner: ^1.0.0 objectbox_generator: ^1.1.1
objectbox_generator: any
flutter: flutter:
uses-material-design: true uses-material-design: true