Add mounted check to prevent updates on unmounted widgets

This commit is contained in:
bluearevalo 2024-07-12 11:14:00 -04:00
parent 5494019be5
commit 35434b09d1

View file

@ -194,6 +194,8 @@ class MessageToolbarState extends State<MessageToolbar> {
late StreamSubscription<MessageMode> 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<MessageToolbar> {
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) {