Jisho-Study-Tool/lib/components/kanji/kanji_result_body.dart

108 lines
3.3 KiB
Dart
Raw Permalink Normal View History

2020-07-11 13:33:31 +02:00
import 'package:flutter/material.dart';
import 'package:unofficial_jisho_api/api.dart' as jisho;
import './kanji_result_body/examples.dart';
import './kanji_result_body/grade.dart';
import './kanji_result_body/header.dart';
import './kanji_result_body/jlpt_level.dart';
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';
2022-05-08 15:33:03 +02:00
import '../../services/kanji_grade_conversion.dart';
2020-07-11 13:33:31 +02:00
class KanjiResultBody extends StatelessWidget {
2021-07-26 21:39:17 +02:00
late final String query;
late final jisho.KanjiResultData resultData;
2020-07-11 13:33:31 +02:00
2021-12-01 23:09:53 +01:00
KanjiResultBody({required jisho.KanjiResult result, Key? key})
: super(key: key) {
2021-08-08 23:16:54 +02:00
query = result.query;
// TODO: Handle this kind of exception before widget is initialized
2021-12-01 23:09:53 +01:00
if (result.data == null) throw Exception();
2021-08-08 23:16:54 +02:00
resultData = result.data!;
}
2022-05-08 15:33:03 +02:00
// TODO: add compart link
2022-01-19 02:10:05 +01:00
Widget get headerRow => Container(
margin: const EdgeInsets.fromLTRB(20.0, 20.0, 20.0, 30.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
const Flexible(
fit: FlexFit.tight,
child: SizedBox(),
2022-01-19 02:10:05 +01:00
),
Flexible(
fit: FlexFit.tight,
child: Center(child: Header(kanji: query)),
),
Flexible(
fit: FlexFit.tight,
child: Center(
child: (resultData.radical != null)
? Radical(radical: resultData.radical!)
: const SizedBox(),
),
),
],
),
);
Widget get rankingColumn => Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const Text('JLPT: ', style: TextStyle(fontSize: 20.0)),
JlptLevel(jlptLevel: resultData.jlptLevel ?? ''),
],
),
Row(
children: [
const Text('Grade: ', style: TextStyle(fontSize: 20.0)),
2022-05-08 15:33:03 +02:00
Grade(grade: resultData.grade),
2022-01-19 02:10:05 +01:00
],
),
Row(
children: [
const Text('Rank: ', style: TextStyle(fontSize: 20.0)),
Rank(rank: resultData.newspaperFrequencyRank),
],
),
],
);
2020-07-11 13:33:31 +02:00
@override
Widget build(BuildContext context) {
2020-07-16 22:11:23 +02:00
return ListView(
2020-07-11 13:33:31 +02:00
children: [
2022-01-19 02:10:05 +01:00
headerRow,
2021-12-01 23:09:53 +01:00
YomiChips(yomi: resultData.meaning.split(', '), type: YomiType.meaning),
(resultData.onyomi.isNotEmpty)
? YomiChips(yomi: resultData.onyomi, type: YomiType.onyomi)
: const SizedBox.shrink(),
(resultData.kunyomi.isNotEmpty)
? YomiChips(yomi: resultData.kunyomi, type: YomiType.kunyomi)
: const SizedBox.shrink(),
2020-07-11 13:33:31 +02:00
IntrinsicHeight(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
2021-12-01 23:09:53 +01:00
StrokeOrderGif(uri: resultData.strokeOrderGifUri),
2022-01-19 02:10:05 +01:00
rankingColumn,
2020-07-11 13:33:31 +02:00
],
),
),
2021-12-01 23:09:53 +01:00
Examples(
onyomi: resultData.onyomiExamples,
kunyomi: resultData.kunyomiExamples,
),
2020-07-11 13:33:31 +02:00
],
);
}
2021-12-01 23:09:53 +01:00
}