made logic for determining if warning should show in translated card more readable and moved out of build function
This commit is contained in:
parent
0556128afc
commit
acef3778f7
1 changed files with 16 additions and 14 deletions
|
|
@ -10,7 +10,6 @@ import 'package:fluffychat/pangea/widgets/chat/toolbar_content_loading_indicator
|
|||
import 'package:fluffychat/pangea/widgets/igc/card_error_widget.dart';
|
||||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:matrix/matrix.dart';
|
||||
|
||||
class MessageTranslationCard extends StatefulWidget {
|
||||
final PangeaMessageEvent messageEvent;
|
||||
|
|
@ -133,6 +132,22 @@ class MessageTranslationCardState extends State<MessageTranslationCard> {
|
|||
setState(() {});
|
||||
}
|
||||
|
||||
/// Show warning if message's language code is user's L1
|
||||
/// or if translated text is same as original text.
|
||||
/// Warning does not show if was previously closed
|
||||
bool get showWarning {
|
||||
if (MatrixState.pangeaController.instructions.wereInstructionsTurnedOff(
|
||||
InlineInstructions.l1Translation.toString(),
|
||||
)) return false;
|
||||
|
||||
final bool isWrittenInL1 =
|
||||
l1Code != null && widget.messageEvent.originalSent?.langCode == l1Code;
|
||||
final bool isTextIdentical = selectionTranslation != null &&
|
||||
widget.messageEvent.originalSent?.text == selectionTranslation;
|
||||
|
||||
return isWrittenInL1 || isTextIdentical;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (!_fetchingRepresentation &&
|
||||
|
|
@ -141,19 +156,6 @@ class MessageTranslationCardState extends State<MessageTranslationCard> {
|
|||
return const CardErrorWidget();
|
||||
}
|
||||
|
||||
// Show warning if message's language code is user's L1
|
||||
// or if translated text is same as original text
|
||||
// Warning does not show if was previously closed
|
||||
final bool showWarning = widget.messageEvent.originalSent != null &&
|
||||
((!widget.immersionMode &&
|
||||
widget.messageEvent.originalSent!.langCode.equals(l1Code)) ||
|
||||
(selectionTranslation == null ||
|
||||
widget.messageEvent.originalSent!.text
|
||||
.equals(selectionTranslation))) &&
|
||||
!MatrixState.pangeaController.instructions.wereInstructionsTurnedOff(
|
||||
InlineInstructions.l1Translation.toString(),
|
||||
);
|
||||
|
||||
return Container(
|
||||
child: _fetchingRepresentation
|
||||
? const ToolbarContentLoadingIndicator()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue