Jisho-Study-Tool/lib/components/search/search_results_body/parts/header.dart

41 lines
1.3 KiB
Dart
Raw Permalink Normal View History

2020-08-23 00:38:42 +02:00
import 'package:flutter/material.dart';
import 'package:unofficial_jisho_api/api.dart';
import '../../../../services/romaji_transliteration.dart';
import '../../../../settings.dart';
2020-08-23 00:38:42 +02:00
class JapaneseHeader extends StatelessWidget {
2021-03-03 00:24:25 +01:00
final JishoJapaneseWord word;
2021-12-01 23:09:53 +01:00
const JapaneseHeader({
required this.word,
Key? key,
}) : super(key: key);
bool get hasFurigana => word.word != null && word.reading != null;
2020-08-23 00:38:42 +02:00
@override
Widget build(BuildContext context) {
final String? wordReading = word.reading == null
? null
: (romajiEnabled
? transliterateKanaToLatin(word.reading!)
: word.reading!);
2020-08-23 00:38:42 +02:00
return Container(
2020-08-24 23:45:47 +02:00
alignment: Alignment.centerLeft,
2021-12-01 23:09:53 +01:00
padding: const EdgeInsets.only(left: 10.0),
2020-08-23 00:38:42 +02:00
child: Column(
children: [
// Both wordReading and word.word being present implies that the word has furigana.
// If that's not the case, then the word is usually present in wordReading.
// However, there are some exceptions where the reading is placed in word.
// I have no clue why this might be the case.
hasFurigana ? Text(wordReading!) : const Text(''),
hasFurigana ? Text(word.word!) : Text(wordReading ?? word.word!),
2020-08-23 00:38:42 +02:00
],
),
);
}
}