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

124 lines
3.2 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:unofficial_jisho_api/api.dart';
2021-12-01 23:09:53 +01:00
import '../../../../bloc/theme/theme_bloc.dart';
class Examples extends StatelessWidget {
2021-12-01 23:09:53 +01:00
final List<YomiExample> onyomi;
final List<YomiExample> kunyomi;
2021-12-01 23:09:53 +01:00
const Examples({
required this.onyomi,
required this.kunyomi,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
2021-08-08 23:16:54 +02:00
return Column(
children: [
[
Container(
2021-12-01 23:09:53 +01:00
margin: const EdgeInsets.symmetric(horizontal: 10),
2021-08-08 23:16:54 +02:00
alignment: Alignment.centerLeft,
2021-12-01 23:09:53 +01:00
child: const Text(
2021-08-08 23:16:54 +02:00
'Examples:',
style: TextStyle(fontSize: 20),
),
2021-08-08 23:16:54 +02:00
)
],
2021-12-01 23:09:53 +01:00
onyomi
2021-08-08 23:16:54 +02:00
.map((onyomiExample) => _Example(onyomiExample, _KanaType.onyomi))
.toList(),
2021-12-01 23:09:53 +01:00
kunyomi
2021-08-08 23:16:54 +02:00
.map(
2021-12-01 23:09:53 +01:00
(kunyomiExample) => _Example(kunyomiExample, _KanaType.kunyomi),
)
2021-08-08 23:16:54 +02:00
.toList(),
].expand((list) => list).toList(),
);
}
}
enum _KanaType { kunyomi, onyomi }
class _Example extends StatelessWidget {
2021-03-03 00:24:25 +01:00
final _KanaType kanaType;
final YomiExample yomiExample;
2021-03-03 00:24:25 +01:00
const _Example(this.yomiExample, this.kanaType);
@override
Widget build(BuildContext context) {
2021-08-08 23:16:54 +02:00
final _themeData = BlocProvider.of<ThemeBloc>(context).state.theme;
2021-12-01 23:09:53 +01:00
final _kanaColors = kanaType == _KanaType.kunyomi
? _themeData.kunyomiColor
: _themeData.onyomiColor;
2021-08-08 23:16:54 +02:00
final _menuColors = _themeData.menuGreyNormal;
2021-12-01 23:09:53 +01:00
return Container(
margin: const EdgeInsets.symmetric(
2021-08-08 23:16:54 +02:00
vertical: 5.0,
horizontal: 10.0,
),
decoration: BoxDecoration(
2021-12-01 23:09:53 +01:00
color: _menuColors.background,
borderRadius: BorderRadius.circular(10.0),
),
2021-08-08 23:16:54 +02:00
child: Row(
children: [
Container(
2021-12-01 23:09:53 +01:00
padding: const EdgeInsets.symmetric(
2021-08-08 23:16:54 +02:00
vertical: 10.0,
horizontal: 10.0,
),
decoration: BoxDecoration(
color: _kanaColors.background,
2021-12-01 23:09:53 +01:00
borderRadius: const BorderRadius.only(
2021-08-08 23:16:54 +02:00
topLeft: Radius.circular(10.0),
bottomLeft: Radius.circular(10.0),
),
2021-08-08 23:16:54 +02:00
),
child: Column(
children: [
2021-12-01 23:09:53 +01:00
Text(
yomiExample.reading,
style: TextStyle(
color: _kanaColors.foreground,
fontSize: 15.0,
),
2021-08-08 23:16:54 +02:00
),
2021-12-01 23:09:53 +01:00
const SizedBox(
2021-08-08 23:16:54 +02:00
height: 5.0,
),
2021-12-01 23:09:53 +01:00
Text(
yomiExample.example,
style: TextStyle(
color: _kanaColors.foreground,
fontSize: 20.0,
),
2021-08-08 23:16:54 +02:00
),
],
),
2021-08-08 23:16:54 +02:00
),
2021-12-01 23:09:53 +01:00
const SizedBox(
2021-08-08 23:16:54 +02:00
width: 15.0,
),
Expanded(
child: Wrap(
children: [
2021-12-01 23:09:53 +01:00
Text(
yomiExample.meaning,
style: TextStyle(
color: _menuColors.foreground,
2021-08-08 23:16:54 +02:00
),
)
],
),
2021-08-08 23:16:54 +02:00
),
],
),
);
}
}