From 35434b09d1b389f8f4bcf7cd2d458f832aa96769 Mon Sep 17 00:00:00 2001 From: bluearevalo <90929912+bluearevalo@users.noreply.github.com> Date: Fri, 12 Jul 2024 11:14:00 -0400 Subject: [PATCH] Add mounted check to prevent updates on unmounted widgets --- lib/pangea/widgets/chat/message_toolbar.dart | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/pangea/widgets/chat/message_toolbar.dart b/lib/pangea/widgets/chat/message_toolbar.dart index 8d2d66b7d..e10d637e0 100644 --- a/lib/pangea/widgets/chat/message_toolbar.dart +++ b/lib/pangea/widgets/chat/message_toolbar.dart @@ -194,6 +194,8 @@ class MessageToolbarState extends State { late StreamSubscription toolbarModeStream; void updateMode(MessageMode newMode) { + //Early exit from the function if the widget has been unmounted to prevent updates on an inactive widget. + if (!mounted) return; if (updatingMode) return; debugPrint("updating toolbar mode"); final bool subscribed = @@ -347,6 +349,7 @@ class MessageToolbarState extends State { Timer? timer; selectionStream = widget.textSelection.selectionStream.stream.listen((value) { + //talk about this timer?.cancel(); timer = Timer(const Duration(milliseconds: 500), () { if (value != null && value.isNotEmpty) {