Flutter Failed assertion: line 1340 pos 12: '_debugLifecycleState == _StateLifecycle.ready': is not true

Viewed 622

My app's page flow is: main -> work -> result -> main
In main page, it has sliver app bar, tabs, tab page(grid view), and bottom navigation view.
In grid view, item route to work page when user click item.
When user confirm their work, app routes to main page.
Like this:

//in work page
var result = await routeToResultPage(context);

if (result.toString() == "complete") {
  Navigator.pop(context, "complete");
}

Future<String> routeToResultPage(BuildContext context) {
  Future<String> result = Navigator.of(context).push(MaterialPageRoute(
      builder: (BuildContext context) => CompletePage()));

  return result;
}

I do Navigator.pop(context, "complete"); in result page.
And also the item in grid view has call back to refresh the item when user finish work.

var res = routeToWorkPage(context);
    res.then((value) {
      if(value == 'C' || value == 'complete') {
        widget.onChangeState(true);
        //refresh it self
      }
    });

But when the app comes back to the main page and if I move to next tab and scroll, It throws Error.

======== Exception caught by widgets library =======================================================
The following assertion was thrown while finalizing the widget tree:
'package:flutter/src/widgets/framework.dart': Failed assertion: line 1340 pos 12: '_debugLifecycleState == _StateLifecycle.ready': is not true.


Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause.
In either case, please report this assertion by filing a bug on GitHub:
  https://github.com/flutter/flutter/issues/new?template=2_bug.md

When the exception was thrown, this was the stack: 
#2      State.dispose (package:flutter/src/widgets/framework.dart:1340:12)
#3      StatefulElement.unmount (package:flutter/src/widgets/framework.dart:4721:11)
#4      _InactiveElements._unmount (package:flutter/src/widgets/framework.dart:2022:13)
#5      _InactiveElements._unmount.<anonymous closure> (package:flutter/src/widgets/framework.dart:2020:7)
#6      SingleChildRenderObjectElement.visitChildren (package:flutter/src/widgets/framework.dart:5961:14)
...
====================================================================================================
======== Exception caught by gesture ===============================================================
The following assertion was thrown while handling a gesture:
Looking up a deactivated widget's ancestor is unsafe.

At this point the state of the widget's element tree is no longer stable.

To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.

When the exception was thrown, this was the stack: 
#0      Element._debugCheckStateIsActiveForAncestorLookup.<anonymous closure> (package:flutter/src/widgets/framework.dart:3864:9)
#1      Element._debugCheckStateIsActiveForAncestorLookup (package:flutter/src/widgets/framework.dart:3878:6)
#2      Element.visitAncestorElements (package:flutter/src/widgets/framework.dart:3964:12)
#3      Notification.dispatch (package:flutter/src/widgets/notification_listener.dart:138:13)
#4      DragScrollActivity.dispatchScrollStartNotification (package:flutter/src/widgets/scroll_activity.dart:444:111)
...
Handler: "onStart"
Recognizer: VerticalDragGestureRecognizer#da46d
  start behavior: start
====================================================================================================
E/flutter (31657): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Looking up a deactivated widget's ancestor is unsafe.
E/flutter (31657): At this point the state of the widget's element tree is no longer stable.
E/flutter (31657): To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor by calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.
E/flutter (31657): #0      Element._debugCheckStateIsActiveForAncestorLookup.<anonymous closure> (package:flutter/src/widgets/framework.dart:3864:9)
E/flutter (31657): #1      Element._debugCheckStateIsActiveForAncestorLookup (package:flutter/src/widgets/framework.dart:3878:6)
E/flutter (31657): #2      Element.visitAncestorElements (package:flutter/src/widgets/framework.dart:3964:12)
E/flutter (31657): #3      Notification.dispatch (package:flutter/src/widgets/notification_listener.dart:138:13)
E/flutter (31657): #4      ScrollActivity.dispatchScrollEndNotification (package:flutter/src/widgets/scroll_activity.dart:104:63)
E/flutter (31657): #5      ScrollPosition.didEndScroll (package:flutter/src/widgets/scroll_position.dart:877:15)
E/flutter (31657): #6      ScrollPosition.beginActivity (package:flutter/src/widgets/scroll_position.dart:846:9)
E/flutter (31657): #7      _NestedScrollPosition.goBallistic (package:flutter/src/widgets/nested_scroll_view.dart:1498:5)
E/flutter (31657): #8      BallisticScrollActivity._end (package:flutter/src/widgets/scroll_activity.dart:556:14)
E/flutter (31657): #9      _rootRun (dart:async/zone.dart:1346:47)
E/flutter (31657): #10     _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (31657): #11     _FutureListener.handleWhenComplete (dart:async/future_impl.dart:176:18)
E/flutter (31657): #12     Future._propagateToListeners.handleWhenCompleteCallback (dart:async/future_impl.dart:674:39)
E/flutter (31657): #13     Future._propagateToListeners (dart:async/future_impl.dart:730:37)
E/flutter (31657): #14     Future._completeWithValue (dart:async/future_impl.dart:539:5)
E/flutter (31657): #15     Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:577:7)
E/flutter (31657): #16     _rootRun (dart:async/zone.dart:1354:13)
E/flutter (31657): #17     _CustomZone.run (dart:async/zone.dart:1258:19)
E/flutter (31657): #18     _CustomZone.runGuarded (dart:async/zone.dart:1162:7)
E/flutter (31657): #19     _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1202:23)
E/flutter (31657): #20     _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
E/flutter (31657): #21     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)
E/flutter (31657): 

I couldn't get where this error comes from.
How can I solve this problem?

1 Answers

I found what was problem. There's no error in my question's code.
I was showing an interstitial ad before route to page and that was a problem.

Related