Lir*_*bul 11 overlay setstate dart flutter
我尝试在 {AbsorbPointer} (特别是 {GestureDetector} onPanEnd)调用的 'fling' 函数的 SetState() 内使用 'showGeneralDialog' 编写动画对话框脚本。我附加了简单的代码,我尝试用未来的异步等待等来完成它,但可能我不明白。
\n“child: EasyDialog”在我的代码中定义为 void 函数。\n这是我的调试控制台和附加的代码
\n如果有人能指导我如何在 setState 期间完成动画(pageBuilder),我会很高兴。
\n[38;5;248m\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90 Exception caught by widgets library \xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90[39;49m\n[38;5;244mThe following assertion was thrown building Builder(dirty, dependencies: [_LocalizationsScope-[GlobalKey#3e9b6]]):[39;49m\nsetState() or markNeedsBuild() called during build.\n\n[38;5;244mThis Overlay widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase.[39;49m\n[38;5;244mThe widget on which setState() or markNeedsBuild() was called was: Overlay-[LabeledGlobalKey<OverlayState>#2acd6][39;49m\n [38;5;244mstate: OverlayState#6a2d6(entries: [OverlayEntry#9eb98(opaque: true; maintainState: false), OverlayEntry#7538d(opaque: false; maintainState: true), OverlayEntry#dfb68(opaque: true; maintainState: false), OverlayEntry#12c39(opaque: false; maintainState: true), OverlayEntry#3ef90(opaque: true; maintainState: false), OverlayEntry#53522(opaque: false; maintainState: true), OverlayEntry#07377(opaque: false; maintainState: false), OverlayEntry#e5cbf(opaque: false; maintainState: true), OverlayEntry#f3375(opaque: false; maintainState: false), OverlayEntry#b6bdc(opaque: false; maintainState: true), OverlayEntry#34ca0(opaque: false; maintainState: false)])[39;49m\n[38;5;244mThe widget which was currently being built when the offending call was made was: Builder[39;49m\n [38;5;244mdirty[39;49m\n [38;5;244mdependencies: [_LocalizationsScope-[GlobalKey#3e9b6]][39;49m\n[38;5;244mThe relevant error-causing widget was[39;49m\n[38;5;248mSlideTransition[39;49m\n lib\\main.dart\n[38;5;244mWhen the exception was thrown, this was the stack[39;49m\n[38;5;244m#0 Element.markNeedsBuild.<anonymous closure>[39;49m\n package:flutter/\xe2\x80\xa6/widgets/framework.dart\n[38;5;244m#1 Element.markNeedsBuild[39;49m\n package:flutter/\xe2\x80\xa6/widgets/framework.dart\n[38;5;244m#2 State.setState[39;49m\n package:flutter/\xe2\x80\xa6/widgets/framework.dart\n[38;5;244m#3 OverlayState.rearrange[39;49m\n package:flutter/\xe2\x80\xa6/widgets/overlay.dart\n[38;5;244m#4 NavigatorState._flushHistoryUpdates[39;49m\n package:flutter/\xe2\x80\xa6/widgets/navigator.dart\n[38;5;244m...[39;49m\n[38;5;248m\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90\xe2\x95\x90[39;49m\nE/flutter (30352): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 2976 pos 18: '!navigator._debugLocked': is not true.\n[38;5;244mE/flutter (30352): #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39)[39;49m\n[38;5;244mE/flutter (30352): #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)[39;49m\n[38;5;244mE/flutter (30352): #2 _RouteEntry.handlePush.<anonymous closure>[39;49m\n package:flutter/\xe2\x80\xa6/widgets/navigator.dart\n[38;5;244mE/flutter (30352): #3 TickerFuture.whenCompleteOrCancel.thunk[39;49m\n package:flutter/\xe2\x80\xa6/scheduler/ticker.dart\n[38;5;244mE/flutter (30352): #4 _rootRunUnary (dart:async/zone.dart:1194:47)[39;49m\n[38;5;244mE/flutter (30352): #5 _CustomZone.runUnary (dart:async/zone.dart:1097:19)[39;49m\n[38;5;244mE/flutter (30352): #6 _FutureListener.handleValue (dart:async/future_impl.dart:150:18)[39;49m\n[38;5;244mE/flutter (30352): #7 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:703:45)[39;49m\n[38;5;244mE/flutter (30352): #8 Future._propagateToListeners (dart:async/future_impl.dart:732:32)[39;49m\n[38;5;244mE/flutter (30352): #9 Future._completeWithValue (dart:async/future_impl.dart:536:5)[39;49m\n[38;5;244mE/flutter (30352): #10 Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:574:7)[39;49m\n[38;5;244mE/flutter (30352): #11 _rootRun (dart:async/zone.dart:1186:13)[39;49m\n[38;5;244mE/flutter (30352): #12 _CustomZone.run (dart:async/zone.dart:1090:19)[39;49m\n[38;5;244mE/flutter (30352): #13 _CustomZone.runGuarded (dart:async/zone.dart:994:7)[39;49m\n[38;5;244mE/flutter (30352): #14 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1034:23)[39;49m\n[38;5;244mE/flutter (30352): #15 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)[39;49m\n[38;5;244mE/flutter (30352): #16 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)[39;49m\nE/flutter (30352):\nE/flutter (30352): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: 'package:flutter/src/widgets/navigator.dart': Failed assertion: line 2976 pos 18: '!navigator._debugLocked': is not true.\n[38;5;244mE/flutter (30352): #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:46:39)[39;49m\n[38;5;244mE/flutter (30352): #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)[39;49m\n[38;5;244mE/flutter (30352): #2 _RouteEntry.handlePush.<anonymous closure>[39;49m\n package:flutter/\xe2\x80\xa6/widgets/navigator.dart\n[38;5;244mE/flutter (30352): #3 TickerFuture.whenCompleteOrCancel.thunk[39;49m\n package:flutter/\xe2\x80\xa6/scheduler/ticker.dart\n[38;5;244mE/flutter (30352): #4 _rootRunUnary (dart:async/zone.dart:1194:47)[39;49m\n[38;5;244mE/flutter (30352): #5 _CustomZone.runUnary (dart:async/zone.dart:1097:19)[39;49m\n[38;5;244mE/flutter (30352): #6 _FutureListener.handleValue (dart:async/future_impl.dart:150:18)[39;49m\n[38;5;244mE/flutter (30352): #7 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:703:45)[39;49m\n[38;5;244mE/flutter (30352): #8 Future._propagateToListeners (dart:async/future_impl.dart:732:32)[39;49m\n[38;5;244mE/flutter (30352): #9 Future._completeWithValue (dart:async/future_impl.dart:536:5)[39;49m\n[38;5;244mE/flutter (30352): #10 Future._asyncCompleteWithValue.<anonymous closure> (dart:async/future_impl.dart:574:7)[39;49m\n[38;5;244mE/flutter (30352): #11 _rootRun (dart:async/zone.dart:1186:13)[39;49m\n[38;5;244mE/flutter (30352): #12 _CustomZone.run (dart:async/zone.dart:1090:19)[39;49m\n[38;5;244mE/flutter (30352): #13 _CustomZone.runGuarded (dart:async/zone.dart:994:7)[39;49m\n[38;5;244mE/flutter (30352): #14 _CustomZone.bindCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1034:23)[39;49m\n[38;5;244mE/flutter (30352): #15 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)[39;49m\n[38;5;244mE/flutter (30352): #16 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)[39;49m\nE/flutter (30352):\nI/ViewRootImpl@738e9ee[MainActivity](30352): ViewPostIme pointer 0\nRun Code Online (Sandbox Code Playgroud)\n fling(details) {\n final simulation = FrictionSimulation(/**/\n\n );\n _spinController.animateWith(simulation).then((_) => setState(() {\n absorbing = false;\n Timer(Duration(milliseconds: 500), () {\n showGeneralDialog(\n barrierLabel: "Label",\n barrierDismissible: true,\n barrierColor: Colors.black.withOpacity(0.5),\n transitionDuration: Duration(milliseconds: 700),\n context: context,\n pageBuilder: (context, anim1, anim2) {\n return Align(\n alignment:\n _fromTop ? Alignment.topCenter : Alignment.bottomCenter,\n child: Container(\n height: 300,\n child: SizedBox.expand(\n child: EasyDialog(\n closeButton: true,\n cardColor: Colors.white.withOpacity(0.3),\n contentPadding: const EdgeInsets.only(bottom: 100),\n title: Text(\n "Task Dialog",\n textScaleFactor: 1.2,\n ),\n description: Text(\n text[Random().nextInt(text.length)],\n ),\n topImage: AssetImage('assets/images/cbg82.jpg'),\n height: 400,\n width: 350,\n ).show(context)),\n margin: EdgeInsets.only(\n top: 50, left: 12, right: 12, bottom: 50),\n decoration: BoxDecoration(\n color: Colors.white,\n borderRadius: BorderRadius.circular(40),\n ),\n ),\n );\n },\n transitionBuilder: (context, anim1, anim2, child) {\n return SlideTransition(\n position: Tween(\n begin: Offset(0, _fromTop ? -1 : 1),\n end: Offset(0, 0))\n .animate(anim1),\n child: child,\n );\n },\n );\n });\n }));\n setState(() => absorbing = true);\n }\n///\n\n @override\n Widget build(BuildContext context) {\n return Scaffold(\n /*appbars*/\n body: Container(\n child: Column(\n children: <Widget>[\n Card(\n child: AbsorbPointer(\n absorbing: absorbing,\n child: GestureDetector(\n behavior: HitTestBehavior.translucent,\n onPanUpdate: (d) =>\n _spinController.value += d.delta.dx / 100,\n onPanEnd: fling,\n child: SizedBox(\n child: RotationTransition(\n turns: _spinController,\n child: FittedBox(\n alignment: Alignment.center,\n fit: BoxFit.fill,\n child: Image.asset(\n _imageToShow,\n height: _aHeight,\n width: _aWidth,\n ))),\n ),\n ),\n )),\n ],\n )),\n );\n }\nRun Code Online (Sandbox Code Playgroud)\n谢谢 :)
\nLOL*_*dad 25
您收到此错误是因为您在页面构建完成之前正在执行某些操作。所以你必须等待。
使用怎么样addPostFrameCallback?
请参阅flutter 官方文档中的信息。
安排此帧结束时的回调。
不请求新框架。
此回调在帧期间运行,就在持久帧回调之后(即主渲染管道已刷新时)。如果帧正在进行中并且帧后回调尚未执行,则注册的回调仍会在该帧期间执行。否则,注册的回调将在下一帧期间执行。
回调按照添加的顺序执行。
帧后回调无法取消注册。它们只被调用一次。
所以你可以这样做:
SchedulerBinding.instance.addPostFrameCallback((_) {
//yourcode
});
Run Code Online (Sandbox Code Playgroud)
另一个原因可能是(如果不看到整个代码就很难判断)您在构建阶段立即执行onPressed或回调。确保您的代码中onTap没有类似的内容。onTap: onTap()相反,你需要做onTap: onTap.