我的应用程序的页面流程是:main -> work -> result -> main
在主页面,它有细长的应用栏、标签、标签页(网格视图)和底部导航视图。
在网格视图中,当用户单击项目时,项目路由到工作页面。
当用户确认他们的工作时,应用程序路由到主页。
像这样:
//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;
}
我在结果页面执行 Navigator.pop(context, "complete");
。
并且网格视图中的项目在用户完成工作时回调以刷新项目。
var res = routeToWorkPage(context);
res.then((value) {
if(value == 'C' || value == 'complete') {
widget.onChangeState(true);
//refresh it self
}
});
但是当应用返回主页时,如果我移动到下一个选项卡并滚动,它会抛出错误。
======== 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):
我不知道这个错误的来源。
我该如何解决这个问题?
答案 0 :(得分:1)
我发现了问题所在。我的问题代码没有错误。
我在转到页面之前展示了一个插页式广告,这是一个问题。