Redirect kanji function
This commit is contained in:
parent
709b43d95d
commit
e0df989359
|
@ -23,30 +23,6 @@ class _Header extends StatelessWidget {
|
||||||
_Header(this._kanji);
|
_Header(this._kanji);
|
||||||
}
|
}
|
||||||
|
|
||||||
class _JlptLevel extends StatelessWidget {
|
|
||||||
final String _jlptLevel;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Container(
|
|
||||||
padding: EdgeInsets.all(10.0),
|
|
||||||
child: Text(
|
|
||||||
_jlptLevel,
|
|
||||||
style: TextStyle(
|
|
||||||
color: Colors.white,
|
|
||||||
fontSize: 20.0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
color: Colors.blue,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
_JlptLevel(this._jlptLevel);
|
|
||||||
}
|
|
||||||
|
|
||||||
class _Rank extends StatelessWidget {
|
class _Rank extends StatelessWidget {
|
||||||
final int _rank;
|
final int _rank;
|
||||||
|
|
||||||
|
@ -71,6 +47,30 @@ class _Rank extends StatelessWidget {
|
||||||
_Rank(this._rank);
|
_Rank(this._rank);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _JlptLevel extends StatelessWidget {
|
||||||
|
final String _jlptLevel;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Container(
|
||||||
|
padding: EdgeInsets.all(10.0),
|
||||||
|
child: Text(
|
||||||
|
_jlptLevel,
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 20.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
color: Colors.blue,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_JlptLevel(this._jlptLevel);
|
||||||
|
}
|
||||||
|
|
||||||
class _Grade extends StatelessWidget {
|
class _Grade extends StatelessWidget {
|
||||||
final String _grade;
|
final String _grade;
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ class _Grade extends StatelessWidget {
|
||||||
),
|
),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
borderRadius: BorderRadius.circular(10.0),
|
shape: BoxShape.circle,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ class _Radical extends StatelessWidget {
|
||||||
_radical.symbol,
|
_radical.symbol,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
fontSize: 20.0,
|
fontSize: 40.0,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
|
@ -186,19 +186,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(_result.jlptLevel ?? "⨉"),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Text("Grade: ", style: TextStyle(fontSize: 20.0)),
|
Text("Grade: ", style: TextStyle(fontSize: 20.0)),
|
||||||
_Grade(_result.taughtIn),
|
_Grade(_result.taughtIn ?? "⨉"),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Text("Rank: ", style: TextStyle(fontSize: 20.0)),
|
Text("Rank: ", style: TextStyle(fontSize: 20.0)),
|
||||||
_Rank(_result.newspaperFrequencyRank),
|
_Rank(_result.newspaperFrequencyRank ?? -1),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
@ -4,6 +4,6 @@ import 'package:jisho_study_tool/services/jisho_search.dart';
|
||||||
class KanjiView extends StatelessWidget {
|
class KanjiView extends StatelessWidget {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return searchForKanji('拒');
|
return searchForKanji('黽');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import './kanji_search.dart';
|
||||||
import 'package:unofficial_jisho_api/api.dart' as jisho;
|
import 'package:unofficial_jisho_api/api.dart' as jisho;
|
||||||
|
|
||||||
import 'package:jisho_study_tool/components/kanji/kanji_search_page.dart';
|
import 'package:jisho_study_tool/components/kanji/kanji_search_page.dart';
|
||||||
|
|
||||||
Widget searchForKanji(String kanji) {
|
Widget searchForKanji(String kanji) {
|
||||||
return FutureBuilder(
|
return FutureBuilder(
|
||||||
future: jisho.searchForKanji(kanji),
|
future: fetchKanji(kanji),
|
||||||
builder:
|
builder: (BuildContext context, AsyncSnapshot<jisho.KanjiResult> snapshot) {
|
||||||
(BuildContext context, AsyncSnapshot<jisho.KanjiResult> snapshot) {
|
|
||||||
if (snapshot.hasData) {
|
if (snapshot.hasData) {
|
||||||
return KanjiResultCard(snapshot.data);
|
return KanjiResultCard(snapshot.data);
|
||||||
} else if (snapshot.hasError) {
|
} else if (snapshot.hasError) {
|
||||||
|
@ -17,5 +17,6 @@ Widget searchForKanji(String kanji) {
|
||||||
child: CircularProgressIndicator(),
|
child: CircularProgressIndicator(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
import 'package:unofficial_jisho_api/api.dart' as jisho;
|
||||||
|
|
||||||
|
String _convertGrade(String grade) {
|
||||||
|
const _conversionTable = {
|
||||||
|
"grade 1": "小1",
|
||||||
|
"grade 2": "小2",
|
||||||
|
"grade 3": "小3",
|
||||||
|
"grade 4": "小4",
|
||||||
|
"grade 5": "小5",
|
||||||
|
"grade 6": "小6",
|
||||||
|
"junior high": "中"
|
||||||
|
};
|
||||||
|
|
||||||
|
print('conversion run: $grade -> ${_conversionTable[grade]}');
|
||||||
|
|
||||||
|
return _conversionTable[grade];
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<jisho.KanjiResult> fetchKanji(String kanji) async {
|
||||||
|
final result = await jisho.searchForKanji(kanji);
|
||||||
|
result.taughtIn = _convertGrade(result.taughtIn);
|
||||||
|
return result;
|
||||||
|
}
|
Loading…
Reference in New Issue