diff --git a/lib/pangea/models/word_data_model.dart b/lib/pangea/models/word_data_model.dart index 838240725..c4c059241 100644 --- a/lib/pangea/models/word_data_model.dart +++ b/lib/pangea/models/word_data_model.dart @@ -1,9 +1,8 @@ import 'dart:developer'; -import 'package:flutter/foundation.dart'; - import 'package:fluffychat/pangea/constants/model_keys.dart'; import 'package:fluffychat/pangea/widgets/igc/word_data_card.dart'; +import 'package:flutter/foundation.dart'; class WordData { final String word; @@ -102,10 +101,11 @@ class WordData { }) => word == w && userL1 == l1 && userL2 == l2 && fullText == f; - String formattedPartOfSpeech(LanguageType languageType) { + String? formattedPartOfSpeech(LanguageType languageType) { final String pos = languageType == LanguageType.base ? basePartOfSpeech : targetPartOfSpeech; + if (pos.isEmpty) return null; return pos[0].toUpperCase() + pos.substring(1); } diff --git a/lib/pangea/widgets/igc/word_data_card.dart b/lib/pangea/widgets/igc/word_data_card.dart index a6ef7b511..4b8445417 100644 --- a/lib/pangea/widgets/igc/word_data_card.dart +++ b/lib/pangea/widgets/igc/word_data_card.dart @@ -314,6 +314,23 @@ class PartOfSpeechBlock extends StatelessWidget { required this.languageType, }); + String get exampleSentence => languageType == LanguageType.target + ? wordData.targetExampleSentence + : wordData.baseExampleSentence; + + String get definition => languageType == LanguageType.target + ? wordData.targetDefinition + : wordData.baseDefinition; + + String formattedTitle(BuildContext context) { + final String word = languageType == LanguageType.target + ? wordData.targetWord + : wordData.baseWord; + String? pos = wordData.formattedPartOfSpeech(languageType); + if (pos == null || pos.isEmpty) pos = L10n.of(context)!.unkDisplayName; + return "$word (${wordData.formattedPartOfSpeech(languageType)})"; + } + @override Widget build(BuildContext context) { return Padding( @@ -324,9 +341,7 @@ class PartOfSpeechBlock extends StatelessWidget { Align( alignment: Alignment.centerLeft, child: Text( - languageType == LanguageType.target - ? "${wordData.targetWord} (${wordData.formattedPartOfSpeech(languageType)})" - : "${wordData.baseWord} (${wordData.formattedPartOfSpeech(languageType)})", + formattedTitle(context), style: BotStyle.text(context, italics: true, bold: false), ), ), @@ -337,47 +352,43 @@ class PartOfSpeechBlock extends StatelessWidget { alignment: Alignment.centerLeft, child: Column( children: [ - RichText( - text: TextSpan( - style: BotStyle.text( - context, - italics: false, - bold: false, - ), - children: [ - TextSpan( - text: "${L10n.of(context)!.definition}: ", - style: const TextStyle(fontWeight: FontWeight.bold), - ), - TextSpan( - text: languageType == LanguageType.target - ? wordData.targetDefinition - : wordData.baseDefinition, + if (definition.isNotEmpty) + RichText( + text: TextSpan( + style: BotStyle.text( + context, + italics: false, + bold: false, ), - ], + children: [ + TextSpan( + text: "${L10n.of(context)!.definition}: ", + style: const TextStyle(fontWeight: FontWeight.bold), + ), + TextSpan(text: definition), + ], + ), ), - ), const SizedBox(height: 10), - RichText( - text: TextSpan( - style: BotStyle.text( - context, - italics: false, - bold: false, - ), - children: [ - TextSpan( - text: "${L10n.of(context)!.exampleSentence}: ", - style: const TextStyle(fontWeight: FontWeight.bold), + if (exampleSentence.isNotEmpty) + RichText( + text: TextSpan( + style: BotStyle.text( + context, + italics: false, + bold: false, ), - TextSpan( - text: languageType == LanguageType.target - ? wordData.targetExampleSentence - : wordData.baseExampleSentence, - ), - ], + children: [ + TextSpan( + text: "${L10n.of(context)!.exampleSentence}: ", + style: const TextStyle( + fontWeight: FontWeight.bold, + ), + ), + TextSpan(text: exampleSentence), + ], + ), ), - ), ], ), ),