Update API
This commit is contained in:
parent
5d377aa668
commit
d652fc0685
|
@ -9,6 +9,7 @@ import './kanji_result_body/radical.dart';
|
|||
import './kanji_result_body/rank.dart';
|
||||
import './kanji_result_body/stroke_order_gif.dart';
|
||||
import './kanji_result_body/yomi_chips.dart';
|
||||
import '../../services/kanji_grade_conversion.dart';
|
||||
|
||||
class KanjiResultBody extends StatelessWidget {
|
||||
late final String query;
|
||||
|
@ -24,6 +25,7 @@ class KanjiResultBody extends StatelessWidget {
|
|||
resultData = result.data!;
|
||||
}
|
||||
|
||||
// TODO: add compart link
|
||||
Widget get headerRow => Container(
|
||||
margin: const EdgeInsets.fromLTRB(20.0, 20.0, 20.0, 30.0),
|
||||
child: Row(
|
||||
|
@ -62,7 +64,7 @@ class KanjiResultBody extends StatelessWidget {
|
|||
Row(
|
||||
children: [
|
||||
const Text('Grade: ', style: TextStyle(fontSize: 20.0)),
|
||||
Grade(grade: resultData.taughtIn),
|
||||
Grade(grade: resultData.grade),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
|
|
|
@ -1,25 +1,5 @@
|
|||
import 'package:unofficial_jisho_api/api.dart' as jisho;
|
||||
export 'package:unofficial_jisho_api/api.dart' show KanjiResult;
|
||||
|
||||
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': '中'
|
||||
};
|
||||
|
||||
return conversionTable[grade];
|
||||
}
|
||||
|
||||
// TODO: fix this logic
|
||||
|
||||
Future<jisho.KanjiResult> fetchKanji(String kanji) async {
|
||||
final result = await jisho.searchForKanji(kanji);
|
||||
if (result.data != null && result.data?.taughtIn != null)
|
||||
result.data!.taughtIn = _convertGrade(result.data!.taughtIn!);
|
||||
return result;
|
||||
}
|
||||
Future<jisho.KanjiResult> fetchKanji(String kanji) =>
|
||||
jisho.searchForKanji(kanji);
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
import 'package:unofficial_jisho_api/api.dart';
|
||||
|
||||
extension GradeConversion on KanjiResultData {
|
||||
String? get grade => {
|
||||
'grade 1': '小1',
|
||||
'grade 2': '小2',
|
||||
'grade 3': '小3',
|
||||
'grade 4': '小4',
|
||||
'grade 5': '小5',
|
||||
'grade 6': '小6',
|
||||
'junior high': '中'
|
||||
}[taughtIn];
|
||||
|
||||
int? get gradeNum => {
|
||||
'grade 1': 1,
|
||||
'grade 2': 2,
|
||||
'grade 3': 3,
|
||||
'grade 4': 4,
|
||||
'grade 5': 5,
|
||||
'grade 6': 6,
|
||||
'junior high': 7,
|
||||
}[taughtIn];
|
||||
}
|
|
@ -28,7 +28,7 @@ dependencies:
|
|||
test: ^1.19.5
|
||||
shared_preferences: ^2.0.6
|
||||
signature: ^5.0.0
|
||||
unofficial_jisho_api: ^2.0.4
|
||||
unofficial_jisho_api: ^3.0.0
|
||||
url_launcher: ^6.0.9
|
||||
|
||||
dev_dependencies:
|
||||
|
|
Loading…
Reference in New Issue