Skip to content

A MixViewObserverState was used after being disposed #120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rjahn opened this issue Mar 10, 2025 · 2 comments
Closed

A MixViewObserverState was used after being disposed #120

rjahn opened this issue Mar 10, 2025 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@rjahn
Copy link

rjahn commented Mar 10, 2025

If you do a manual animateTo(context, index) and change the page/show different widgets before the animation is done, following error will be logged:

The following assertion was thrown during a scheduler callback:
A MixViewObserverState was used after being disposed.

Once you have called dispose() on a MixViewObserverState, it can no longer be used.
When the exception was thrown, this was the stack: 
#0      MixViewObserverState._debugAssertNotDisposed.<anonymous closure> (package:scrollview_observer/src/sliver/sliver_observer_view.dart:160:9)
#1      MixViewObserverState._debugAssertNotDisposed (package:scrollview_observer/src/sliver/sliver_observer_view.dart:166:6)
#2      MixViewObserverState._notifySliverListeners (package:scrollview_observer/src/sliver/sliver_observer_view.dart:418:12)
#3      MixViewObserverState.handleContexts (package:scrollview_observer/src/sliver/sliver_observer_view.dart:195:5)
#4      ObserverWidgetState._setupSliverController.<anonymous closure> (package:scrollview_observer/src/common/observer_widget.dart:368:7)
#5      ObserverControllerForScroll._handleScrollEnd.<anonymous closure> (package:scrollview_observer/src/common/observer_controller.dart:1169:38)
#6      SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1442:15)
#7      SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1369:11)
#8      SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:1208:5)
#9      _invoke (dart:ui/hooks.dart:316:13)
#10     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:428:5)
#11     _drawFrame (dart:ui/hooks.dart:288:31)

I have no simple demo application for you, but I hope it's clear what's happening?

@Vlsrnd
Copy link

Vlsrnd commented Mar 14, 2025

The same issue. Let me clarify that it appears when you navigate back while the scroll animation is not finished. It doesn't matter whether via a animateTo or manually scroll.
You can reproduce it using the example NestedScrollViewDemoPage from the repository. Launch, scroll, and while scrolling, change the page so that the dispose method is called.

@rjahn
Copy link
Author

rjahn commented Mar 14, 2025

I fixed the problem temporary, but it's not the best solution 🤗

class FixMixViewObserverState extends MixViewObserverState {

    @override
    SliverObserverHandleContextsResultModel<ObserveModel>? handleContexts({
      bool isForceObserve = false,
      bool isFromObserveNotification = false,
      bool isDependObserveCallback = true,
      bool isIgnoreInnerCanHandleObserve = true,
    }) {
      //means: disposed
      if (innerSliverListeners == null) {
        return null;
      }

      return super.handleContexts(
        isForceObserve: isForceObserve,
        isFromObserveNotification: isFromObserveNotification,
        isDependObserveCallback: isDependObserveCallback,
        isIgnoreInnerCanHandleObserve: isIgnoreInnerCanHandleObserve);
    }

  }

@LinXunFeng LinXunFeng added the bug Something isn't working label Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants