Flutter-小部件的元素树不再稳定

时间:2019-09-16 09:23:40

标签: flutter dart

我在构建应用程序时遇到问题。

我正在处理颤振,并且在下面出现此错误。

════════ 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 inheritFromWidgetOfExactType() 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:3389:9)
#1      Element._debugCheckStateIsActiveForAncestorLookup (package:flutter/src/widgets/framework.dart:3403:6)
#2      Element.ancestorStateOfType (package:flutter/src/widgets/framework.dart:3451:12)
#3      Overlay.of (package:flutter/src/widgets/overlay.dart:238:41)
#4      createTutorialOverlay (package:tuxin_tutorial_overlay/TutorialOverlayUtil.dart:244:24)
...
Handler: "onTap"
Recognizer: TapGestureRecognizer#0ba95
  debugOwner: GestureDetector
  state: possible
  won arena
  finalPosition: Offset(203.5, 431.5)
  sent tap down
════════════════════════════════════════════════════════════════════════════════════════════════════

我已经在互联网上搜索了,却没有找到任何东西。

我正在使用 tuxin_tutorial_overlay 插件来解决问题。有人可以告诉我如何解决这个问题吗?

以下是一些代码:

void guidedTour(BuildContext context) {
    step1(context);
  }

  void step1(BuildContext context){
    createTutorialOverlay(
        context: context,
        tagName: 'step 1',
        bgColor: Colors.green.withOpacity(
            1.0), // Optional. uses black color with 0.4 opacity by default
        onTap: () => step2(context),
        widgetsData: <WidgetData>[
          WidgetData(key: infoServiceGuideKey, isEnabled: false, shape: WidgetShape.Rect)
        ],
        description: Text(
          'step 1',
          textAlign: TextAlign.center,
          style: TextStyle(decoration: TextDecoration.none),
        ));
    showOverlayEntry(tagName: 'step 1');
  }

  void step2(BuildContext context){
    createTutorialOverlay(
        context: context,
        tagName: 'step 2',
        bgColor: Colors.green.withOpacity(
            1.0), // Optional. uses black color with 0.4 opacity by default
        onTap: () => step3(context),
        widgetsData: <WidgetData>[
          WidgetData(key: chatAreaGuideKey, isEnabled: false, shape: WidgetShape.Rect)
        ],
        description: Text(
          'step 2',
          textAlign: TextAlign.center,
          style: TextStyle(decoration: TextDecoration.none),
        ));

    showOverlayEntry(tagName: 'step 2');
  }

然后我从第一步转到第二步

0 个答案:

没有答案