Merge pull request #232 from pangeachat/word-data-fix

fix for empty data returned from wordnet
pull/1183/head
ggurdin 2 years ago committed by GitHub
commit 4b88b263c0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -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);
}

@ -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>[
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>[
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>[
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>[
TextSpan(
text: "${L10n.of(context)!.exampleSentence}: ",
style: const TextStyle(
fontWeight: FontWeight.bold,
),
),
TextSpan(text: exampleSentence),
],
),
),
),
],
),
),

Loading…
Cancel
Save