getTermReadingOverrideWidget method
- {required BuildContext context,
- required AppModel appModel,
- required DictionaryHeading heading,
- required dynamic onSearch( )}
override
Some languages may want to display custom widgets rather than the built in term and reading text that is there by default. For example, Japanese may want to display a furigana widget instead.
Implementation
@override
Widget getTermReadingOverrideWidget({
required BuildContext context,
required AppModel appModel,
required DictionaryHeading heading,
required Function(String) onSearch,
}) {
/// Responsible for the underline on the heading term.
TextStyle indexStyle(int index, String character) {
if (kanaKit.isKanji(character)) {
return const TextStyle(
decoration: TextDecoration.underline,
decorationStyle: TextDecorationStyle.dotted,
);
} else {
return const TextStyle();
}
}
/// Responsible for the action performed on tapping a certain character
/// on the heading term.
void indexAction(int index, String character) {
if (kanaKit.isKanji(character)) {
onSearch(character);
}
}
if (heading.reading.isEmpty) {
return RubyText(
[RubyTextData(heading.term)],
style: Theme.of(context)
.textTheme
.titleLarge!
.copyWith(fontWeight: FontWeight.bold),
rubyStyle: Theme.of(context).textTheme.labelSmall,
indexAction: indexAction,
indexStyle: indexStyle,
);
}
List<RubyTextData>? segments = fetchFurigana(heading: heading);
return RubyText(
segments ??
[
RubyTextData(heading.term, ruby: heading.reading),
],
style: Theme.of(context)
.textTheme
.titleLarge!
.copyWith(fontWeight: FontWeight.bold),
rubyStyle: Theme.of(context).textTheme.labelSmall,
indexAction: indexAction,
indexStyle: indexStyle,
);
}