add romaji under sentences
This commit is contained in:
parent
04793b58ca
commit
935d2a17df
|
@ -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),
|
||||
|
|
|
@ -36,6 +36,7 @@ class Sentences extends StatelessWidget {
|
|||
.map(
|
||||
(word) => KanjiKanaBox(
|
||||
word: word,
|
||||
showRomajiBelow: true,
|
||||
margin: EdgeInsets.zero,
|
||||
padding: EdgeInsets.zero,
|
||||
centerFurigana: false,
|
||||
|
|
Loading…
Reference in New Issue