2021-08-08 23:16:54 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2021-12-01 23:09:53 +01:00
|
|
|
|
2022-01-19 02:10:05 +01:00
|
|
|
import '../../../bloc/theme/theme_bloc.dart';
|
2022-01-23 21:29:54 +01:00
|
|
|
import '../../../routing/routes.dart';
|
2022-01-19 13:47:54 +01:00
|
|
|
import '../../../services/romaji_transliteration.dart';
|
|
|
|
import '../../../settings.dart';
|
2021-08-08 23:16:54 +02:00
|
|
|
|
|
|
|
enum YomiType {
|
|
|
|
onyomi,
|
|
|
|
kunyomi,
|
|
|
|
meaning,
|
|
|
|
}
|
|
|
|
|
|
|
|
extension on YomiType {
|
|
|
|
String get title {
|
|
|
|
switch (this) {
|
|
|
|
case YomiType.onyomi:
|
|
|
|
return 'Onyomi';
|
|
|
|
case YomiType.kunyomi:
|
|
|
|
return 'Kunyomi';
|
|
|
|
case YomiType.meaning:
|
|
|
|
return 'Meanings';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ColorSet getColors(BuildContext context) {
|
2022-01-23 04:52:28 +01:00
|
|
|
// TODO: convert this into a blocbuilder or bloclistener
|
2021-08-08 23:16:54 +02:00
|
|
|
final theme = BlocProvider.of<ThemeBloc>(context).state.theme;
|
|
|
|
|
|
|
|
switch (this) {
|
|
|
|
case YomiType.onyomi:
|
|
|
|
return theme.onyomiColor;
|
|
|
|
case YomiType.kunyomi:
|
|
|
|
return theme.kunyomiColor;
|
|
|
|
case YomiType.meaning:
|
|
|
|
return theme.menuGreyNormal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class YomiChips extends StatelessWidget {
|
|
|
|
final List<String> yomi;
|
|
|
|
final YomiType type;
|
|
|
|
|
2021-12-01 23:09:53 +01:00
|
|
|
const YomiChips({
|
|
|
|
required this.yomi,
|
|
|
|
required this.type,
|
|
|
|
Key? key,
|
|
|
|
}) : super(key: key);
|
2021-08-08 23:16:54 +02:00
|
|
|
|
2021-12-01 23:09:53 +01:00
|
|
|
bool get isExpandable => yomi.length > 6;
|
2021-08-08 23:16:54 +02:00
|
|
|
|
2021-12-01 23:09:53 +01:00
|
|
|
Widget yomiCard({
|
2022-01-23 21:29:54 +01:00
|
|
|
required BuildContext context,
|
2021-12-01 23:09:53 +01:00
|
|
|
required String yomi,
|
|
|
|
required ColorSet colors,
|
2022-01-23 23:56:26 +01:00
|
|
|
TextStyle? extraTextStyle,
|
2021-12-01 23:09:53 +01:00
|
|
|
}) =>
|
2022-01-23 21:29:54 +01:00
|
|
|
InkWell(
|
|
|
|
onTap: () =>
|
|
|
|
Navigator.pushNamed(context, Routes.search, arguments: yomi),
|
|
|
|
child: Container(
|
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 5),
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
vertical: 10.0,
|
|
|
|
horizontal: 10.0,
|
|
|
|
),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: colors.background,
|
|
|
|
borderRadius: BorderRadius.circular(10.0),
|
|
|
|
),
|
|
|
|
child: Text(
|
|
|
|
yomi,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 20.0,
|
|
|
|
color: colors.foreground,
|
2022-01-23 23:56:26 +01:00
|
|
|
).merge(extraTextStyle),
|
2021-12-01 23:09:53 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
2022-01-23 03:18:05 +01:00
|
|
|
|
2021-12-01 23:09:53 +01:00
|
|
|
Widget yomiWrapper(BuildContext context) {
|
|
|
|
final yomiCards = yomi
|
2022-01-19 13:47:54 +01:00
|
|
|
.map((y) => romajiEnabled ? transliterateKanaToLatin(y) : y)
|
2022-01-23 21:29:54 +01:00
|
|
|
.map(
|
|
|
|
(y) => yomiCard(
|
|
|
|
context: context,
|
|
|
|
yomi: y,
|
|
|
|
colors: type.getColors(context),
|
2022-01-23 23:56:26 +01:00
|
|
|
extraTextStyle: type != YomiType.meaning && !romajiEnabled
|
|
|
|
? japaneseFont.textStyle
|
|
|
|
: null,
|
2022-01-23 21:29:54 +01:00
|
|
|
),
|
|
|
|
)
|
2021-08-08 23:16:54 +02:00
|
|
|
.toList();
|
|
|
|
|
2022-01-19 02:10:05 +01:00
|
|
|
final yomiCardsWithTitle = <Widget>[
|
2022-01-23 03:18:05 +01:00
|
|
|
if (type != YomiType.meaning)
|
|
|
|
yomiCard(
|
2022-01-23 21:29:54 +01:00
|
|
|
context: context,
|
2022-01-23 03:18:05 +01:00
|
|
|
yomi: type == YomiType.kunyomi ? 'Kun:' : 'On:',
|
|
|
|
colors: ColorSet(
|
|
|
|
foreground: type.getColors(context).background,
|
|
|
|
background: Colors.transparent,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
...yomiCards
|
|
|
|
];
|
2022-01-19 02:10:05 +01:00
|
|
|
|
|
|
|
final wrap = Wrap(
|
|
|
|
runSpacing: 10.0,
|
|
|
|
crossAxisAlignment: WrapCrossAlignment.center,
|
|
|
|
children: yomiCardsWithTitle,
|
|
|
|
);
|
|
|
|
|
2021-12-01 23:09:53 +01:00
|
|
|
if (!isExpandable)
|
2022-01-19 02:10:05 +01:00
|
|
|
return wrap;
|
2021-12-01 23:09:53 +01:00
|
|
|
else
|
|
|
|
return ExpansionTile(
|
|
|
|
title: Center(
|
2022-01-23 21:29:54 +01:00
|
|
|
child: yomiCard(
|
|
|
|
context: context,
|
|
|
|
yomi: type.title,
|
|
|
|
colors: type.getColors(context),
|
|
|
|
),
|
2021-08-08 23:16:54 +02:00
|
|
|
),
|
2021-12-01 23:09:53 +01:00
|
|
|
children: [
|
2022-01-19 02:10:05 +01:00
|
|
|
const SizedBox(height: 20.0),
|
|
|
|
wrap,
|
|
|
|
const SizedBox(height: 25.0),
|
2021-12-01 23:09:53 +01:00
|
|
|
],
|
|
|
|
);
|
2021-08-08 23:16:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
2021-12-01 23:09:53 +01:00
|
|
|
margin: const EdgeInsets.symmetric(
|
2021-08-08 23:16:54 +02:00
|
|
|
horizontal: 10.0,
|
2021-12-01 23:09:53 +01:00
|
|
|
vertical: 5.0,
|
2021-08-08 23:16:54 +02:00
|
|
|
),
|
2021-12-01 23:09:53 +01:00
|
|
|
alignment: Alignment.centerLeft,
|
|
|
|
child: yomiWrapper(context),
|
2021-08-08 23:16:54 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|