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 'dart:developer';
import 'package:flutter/foundation.dart';
import 'package:fluffychat/pangea/constants/model_keys.dart'; import 'package:fluffychat/pangea/constants/model_keys.dart';
import 'package:fluffychat/pangea/widgets/igc/word_data_card.dart'; import 'package:fluffychat/pangea/widgets/igc/word_data_card.dart';
import 'package:flutter/foundation.dart';
class WordData { class WordData {
final String word; final String word;
@ -102,10 +101,11 @@ class WordData {
}) => }) =>
word == w && userL1 == l1 && userL2 == l2 && fullText == f; word == w && userL1 == l1 && userL2 == l2 && fullText == f;
String formattedPartOfSpeech(LanguageType languageType) { String? formattedPartOfSpeech(LanguageType languageType) {
final String pos = languageType == LanguageType.base final String pos = languageType == LanguageType.base
? basePartOfSpeech ? basePartOfSpeech
: targetPartOfSpeech; : targetPartOfSpeech;
if (pos.isEmpty) return null;
return pos[0].toUpperCase() + pos.substring(1); return pos[0].toUpperCase() + pos.substring(1);
} }

@ -314,6 +314,23 @@ class PartOfSpeechBlock extends StatelessWidget {
required this.languageType, 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Padding( return Padding(
@ -324,9 +341,7 @@ class PartOfSpeechBlock extends StatelessWidget {
Align( Align(
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: Text( child: Text(
languageType == LanguageType.target formattedTitle(context),
? "${wordData.targetWord} (${wordData.formattedPartOfSpeech(languageType)})"
: "${wordData.baseWord} (${wordData.formattedPartOfSpeech(languageType)})",
style: BotStyle.text(context, italics: true, bold: false), style: BotStyle.text(context, italics: true, bold: false),
), ),
), ),
@ -337,47 +352,43 @@ class PartOfSpeechBlock extends StatelessWidget {
alignment: Alignment.centerLeft, alignment: Alignment.centerLeft,
child: Column( child: Column(
children: [ children: [
RichText( if (definition.isNotEmpty)
text: TextSpan( RichText(
style: BotStyle.text( text: TextSpan(
context, style: BotStyle.text(
italics: false, context,
bold: false, 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,
), ),
], children: <TextSpan>[
TextSpan(
text: "${L10n.of(context)!.definition}: ",
style: const TextStyle(fontWeight: FontWeight.bold),
),
TextSpan(text: definition),
],
),
), ),
),
const SizedBox(height: 10), const SizedBox(height: 10),
RichText( if (exampleSentence.isNotEmpty)
text: TextSpan( RichText(
style: BotStyle.text( text: TextSpan(
context, style: BotStyle.text(
italics: false, context,
bold: false, italics: false,
), bold: false,
children: <TextSpan>[
TextSpan(
text: "${L10n.of(context)!.exampleSentence}: ",
style: const TextStyle(fontWeight: FontWeight.bold),
), ),
TextSpan( children: <TextSpan>[
text: languageType == LanguageType.target TextSpan(
? wordData.targetExampleSentence text: "${L10n.of(context)!.exampleSentence}: ",
: wordData.baseExampleSentence, style: const TextStyle(
), fontWeight: FontWeight.bold,
], ),
),
TextSpan(text: exampleSentence),
],
),
), ),
),
], ],
), ),
), ),

Loading…
Cancel
Save