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

add romaji under sentences

This commit is contained in:
Oystein Kristoffer Tveit 2022-01-23 16:58:34 +01:00
parent 04793b58ca
commit 935d2a17df
2 changed files with 30 additions and 21 deletions

View File

@ -7,6 +7,7 @@ import '../../../../settings.dart';
class KanjiKanaBox extends StatelessWidget {
final JishoJapaneseWord word;
final bool showRomajiBelow;
final ColorSet colors;
final bool autoTransliterateRomaji;
final bool centerFurigana;
@ -18,6 +19,7 @@ class KanjiKanaBox extends StatelessWidget {
const KanjiKanaBox({
Key? key,
required this.word,
this.showRomajiBelow = false,
this.colors = LightTheme.defaultMenuGreyNormal,
this.autoTransliterateRomaji = true,
this.centerFurigana = true,
@ -30,7 +32,10 @@ class KanjiKanaBox extends StatelessWidget {
this.padding = const EdgeInsets.all(5.0),
}) : super(key: key);
bool get hasFurigana => word.word != null;
bool get hasFurigana => word.reading != null;
String get kana => '${word.reading ?? ""}${word.word ?? ""}'
.replaceAll(RegExp(r'\p{Script=Hani}', unicode: true), '');
@override
Widget build(BuildContext context) {
@ -40,43 +45,46 @@ class KanjiKanaBox extends StatelessWidget {
? transliterateKanaToLatin(word.reading!)
: word.reading!);
final fFontsize = furiganaFontsize ??
((kanjiFontsize != null) ? 0.8 * kanjiFontsize! : null);
return Container(
margin: margin,
padding: padding,
decoration: BoxDecoration(
color: colors.background,
// boxShadow: [
// BoxShadow(
// color: Colors.black.withOpacity(0.5),
// spreadRadius: 1,
// blurRadius: 0.5,
// offset: const Offset(1, 1),
// ),
// ],
),
color: colors.background,
child: DefaultTextStyle.merge(
child: Column(
crossAxisAlignment: centerFurigana ? CrossAxisAlignment.center : CrossAxisAlignment.start,
crossAxisAlignment: centerFurigana
? CrossAxisAlignment.center
: CrossAxisAlignment.start,
children: [
// See header.dart for more details about this logic
hasFurigana
? Text(
wordReading ?? '',
wordReading!,
style: TextStyle(
fontSize: furiganaFontsize ??
((kanjiFontsize != null)
? 0.8 * kanjiFontsize!
: null),
color: wordReading != null ? colors.foreground : Colors.transparent,
fontSize: fFontsize,
color: colors.foreground,
),
)
: const Text(''),
: Text(
'',
style: TextStyle(
color: Colors.transparent,
fontSize: fFontsize,
),
),
DefaultTextStyle.merge(
child: hasFurigana
? Text(word.word!)
: Text(wordReading ?? word.word!),
style: TextStyle(fontSize: kanjiFontsize),
)
),
if (romajiEnabled && showRomajiBelow)
Text(
transliterateKanaToLatin(kana),
)
],
),
style: TextStyle(color: colors.foreground),

View File

@ -36,6 +36,7 @@ class Sentences extends StatelessWidget {
.map(
(word) => KanjiKanaBox(
word: word,
showRomajiBelow: true,
margin: EdgeInsets.zero,
padding: EdgeInsets.zero,
centerFurigana: false,