silly way of initializing

pull/1490/head
William Jordan-Cooley 1 year ago
parent 1a4dc0ba95
commit 585a9a2be4

@ -62,6 +62,9 @@ class MessageOverlayController extends State<MessageSelectionOverlay>
MessageMode toolbarMode = MessageMode.translation; MessageMode toolbarMode = MessageMode.translation;
PangeaTokenText? _selectedSpan; PangeaTokenText? _selectedSpan;
List<PangeaToken>? tokens;
bool initialized = false;
/// The number of activities that need to be completed before the toolbar is unlocked /// The number of activities that need to be completed before the toolbar is unlocked
/// If we don't have any good activities for them, we'll decrease this number /// If we don't have any good activities for them, we'll decrease this number
static const int neededActivities = 3; static const int neededActivities = 3;
@ -101,8 +104,6 @@ class MessageOverlayController extends State<MessageSelectionOverlay>
: null; : null;
} }
List<PangeaToken>? tokens;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
@ -113,17 +114,12 @@ class MessageOverlayController extends State<MessageSelectionOverlay>
); );
debugPrint( debugPrint(
"selected token: ${widget._initialSelectedToken?.toJson()} total_xp:${widget._initialSelectedToken?.xp} vocab_construct_xp: ${widget._initialSelectedToken?.vocabConstruct.points} daysSincelastUseInWordMeaning ${widget._initialSelectedToken?.daysSinceLastUseByType(ActivityTypeEnum.wordMeaning)}", "selected token: ${widget._initialSelectedToken?.text.content} total_xp:${widget._initialSelectedToken?.xp} vocab_construct_xp: ${widget._initialSelectedToken?.vocabConstruct.points} daysSincelastUseInWordMeaning ${widget._initialSelectedToken?.daysSinceLastUseByType(ActivityTypeEnum.wordMeaning)}",
); );
debugPrint( debugPrint(
"${widget._initialSelectedToken?.vocabConstruct.uses.map((u) => "${u.useType} ${u.timeStamp}").join(", ")}", "${widget._initialSelectedToken?.vocabConstruct.uses.map((u) => "${u.useType} ${u.timeStamp}").join(", ")}",
); );
_getTokens();
activitiesLeftToComplete = activitiesLeftToComplete -
widget._pangeaMessageEvent.numberOfActivitiesCompleted;
_reactionSubscription = _reactionSubscription =
widget.chatController.room.client.onSync.stream.where( widget.chatController.room.client.onSync.stream.where(
(update) { (update) {
@ -146,36 +142,41 @@ class MessageOverlayController extends State<MessageSelectionOverlay>
tts.setupTTS(); tts.setupTTS();
_setInitialToolbarModeAndSelectedSpan(); activitiesLeftToComplete = activitiesLeftToComplete -
} widget._pangeaMessageEvent.numberOfActivitiesCompleted;
MessageAnalyticsEntry? get messageAnalyticsEntry => tokens != null
? MatrixState.pangeaController.getAnalytics.perMessage.get(
tokens!,
// this logic should be in the controller
!pangeaMessageEvent.ownMessage &&
pangeaMessageEvent.messageDisplayRepresentation?.tokens != null,
)
: null;
Future<void> _getTokens() async {
tokens = pangeaMessageEvent.originalSent?.tokens;
if (pangeaMessageEvent.originalSent != null && tokens == null) { if (pangeaMessageEvent.originalSent != null) {
debugPrint("fetching tokens");
pangeaMessageEvent.originalSent! pangeaMessageEvent.originalSent!
.tokensGlobal( .tokensGlobal(
pangeaMessageEvent.senderId, pangeaMessageEvent.senderId,
pangeaMessageEvent.originServerTs, pangeaMessageEvent.originServerTs,
) )
.then((tokens) { .then(
// this isn't currently working because originalSent's _event is null (tokens) {
this.tokens = tokens; this.tokens = tokens;
_setInitialToolbarModeAndSelectedSpan();
initialized = true;
},
).onError((e, stackTrace) {
ErrorHandler.logError(e: "Error getting tokens: $e", s: stackTrace);
_setInitialToolbarModeAndSelectedSpan(); _setInitialToolbarModeAndSelectedSpan();
initialized = true;
}); });
} else {
_setInitialToolbarModeAndSelectedSpan();
initialized = true;
} }
} }
MessageAnalyticsEntry? get messageAnalyticsEntry => tokens != null
? MatrixState.pangeaController.getAnalytics.perMessage.get(
tokens!,
// this logic should be in the controller
!pangeaMessageEvent.ownMessage &&
pangeaMessageEvent.messageDisplayRepresentation?.tokens != null,
)
: null;
/// We need to check if the setState call is safe to call immediately /// We need to check if the setState call is safe to call immediately
/// Kept getting the error: setState() or markNeedsBuild() called during build. /// Kept getting the error: setState() or markNeedsBuild() called during build.
/// This is a workaround to prevent that error /// This is a workaround to prevent that error

@ -145,6 +145,8 @@ class MessageToolbar extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
if (!overLayController.initialized) return const SizedBox();
return Container( return Container(
decoration: BoxDecoration( decoration: BoxDecoration(
color: Theme.of(context).cardColor, color: Theme.of(context).cardColor,

Loading…
Cancel
Save