1
0
mirror of https://github.com/h7x4/Jisho-Study-Tool.git synced 2024-12-22 13:57:29 +01:00
Jisho-Study-Tool/lib/services/jisho_api/kanji_search.dart

26 lines
676 B
Dart
Raw Normal View History

2020-07-10 15:53:51 +02:00
import 'package:unofficial_jisho_api/api.dart' as jisho;
export 'package:unofficial_jisho_api/api.dart' show KanjiResult;
2020-07-10 15:53:51 +02:00
2021-07-26 21:39:17 +02:00
String? _convertGrade(String grade) {
2021-03-03 00:24:25 +01:00
const conversionTable = {
2021-12-01 23:09:53 +01:00
'grade 1': '小1',
'grade 2': '小2',
'grade 3': '小3',
'grade 4': '小4',
'grade 5': '小5',
'grade 6': '小6',
'junior high': ''
2020-07-10 15:53:51 +02:00
};
2021-03-03 00:24:25 +01:00
return conversionTable[grade];
2020-07-10 15:53:51 +02:00
}
2021-07-26 21:39:17 +02:00
// TODO: fix this logic
2020-07-10 15:53:51 +02:00
Future<jisho.KanjiResult> fetchKanji(String kanji) async {
final result = await jisho.searchForKanji(kanji);
2021-07-26 21:39:17 +02:00
if (result.data != null && result.data?.taughtIn != null)
result.data!.taughtIn = _convertGrade(result.data!.taughtIn!);
2020-07-10 15:53:51 +02:00
return result;
2021-12-01 23:09:53 +01:00
}