'package:flutter/src/gestures/tap.dart':断言失败:第 201 行 pos 14:'_down == null && _up == null':不正确

时间:2021-05-13 13:39:46

标签: flutter

我正在使用手势点击关闭文章详细信息页面,当我重新打开文章详细信息页面时,应用程序会显示此错误(第一次打开详细信息工作正常,第二次打开详细信息会显示此错误和细节无法上下滚动):

======== Exception caught by gesture library =======================================================
The following assertion was thrown while dispatching a pointer event:
'package:flutter/src/gestures/tap.dart': Failed assertion: line 201 pos 14: '_down == null && _up == null': 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      BaseTapGestureRecognizer.addAllowedPointer (package:flutter/src/gestures/tap.dart:201:14)
#3      GestureRecognizer.addPointer (package:flutter/src/gestures/recognizer.dart:102:7)
#4      RawGestureDetectorState._handlePointerDown (package:flutter/src/widgets/gesture_detector.dart:1204:18)
#5      RenderPointerListener.handleEvent (package:flutter/src/rendering/proxy_box.dart:2821:29)
#6      GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:361:22)
...
Event: PointerDownEvent#6e7c4(position: Offset(191.4, 563.1))
  position: Offset(191.4, 563.1)
Target: RenderPointerListener#946e9 relayoutBoundary=up46
  parentData: <none> (can use size)
  constraints: BoxConstraints(0.0<=w<=363.4, 0.0<=h<=Infinity)
  size: Size(363.4, 458.2)
  behavior: deferToChild
  listeners: down
====================================================================================================

这是我的详细信息页面抖动代码:

    return GestureDetector(
          onHorizontalDragStart: _onHorizontalDragStart,
          onHorizontalDragUpdate: _onHorizontalDragUpdate,
          onHorizontalDragEnd: _onHorizontalDragEnd,
          child: Container(
            constraints: BoxConstraints(
              minHeight: MediaQuery.of(context).size.height * 0.9,
            ),
            color: Theme.of(context).scaffoldBackgroundColor,
            child: Padding(
              padding: const EdgeInsets.all(16.0),
              child: buildListView(item, context),
            ),
          ));


 void _onHorizontalDragStart(DragStartDetails details) {
    _initialSwipeOffset = details.globalPosition;
  }

  void _onHorizontalDragUpdate(DragUpdateDetails details) {
    _finalSwipeOffset = details.globalPosition;
  }

  void _onHorizontalDragEnd(DragEndDetails details) {
    if (_initialSwipeOffset != null) {
      final offsetDifference = _initialSwipeOffset!.dx - _finalSwipeOffset!.dx;
      if (offsetDifference < 0) {
        Navigator.pop(context);
      }
    }
  }

我正在网上搜索,但没有人遇到这个问题。我应该怎么做才能解决这个问题?

1 个答案:

答案 0 :(得分:1)

看起来您使用的是 Flutter SDK 的预发布版本。我建议您使用 Flutter Stable 频道并重新构建您的项目。

根据Flutter build release channels 建议为所有正式版应用发布稳定版本。

现在知道您当前使用的是哪个分支。打开终端并输入以下命令。

flutter channel

您所在的频道将以“*”开头。例如,

*大师
开发
测试版
稳定

要切换到稳定频道,请在终端上运行此命令。

flutter channel CHANNEL_NAME

例如,将频道更改为稳定,

flutter channel stable

要确保您使用的是此频道的最新版本,请运行

flutter upgrade

这就是你需要做的。