Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter onHorizontalDragEnd DragEndDetails.primaryVelocity存在问题_Flutter_Dart_Swipe_Gesturedetector - Fatal编程技术网

Flutter onHorizontalDragEnd DragEndDetails.primaryVelocity存在问题

Flutter onHorizontalDragEnd DragEndDetails.primaryVelocity存在问题,flutter,dart,swipe,gesturedetector,Flutter,Dart,Swipe,Gesturedetector,总的来说,我对安卓系统的开发还很陌生,所以如果其中一些是显而易见的答案,请原谅我 我正在尝试实现向左/向右滑动功能,以便在我的应用程序中的页面之间进行交换。但是,我在检测速度并使用它来确定是否进行了左/右交换时遇到了问题 以下是我的代码,为了清晰起见,保留了调试器说明: onHorizontalDragStart: (DragStartDetails details) { print("Horizontal Drag Start - preflop."); }, onHorizontalDr

总的来说,我对安卓系统的开发还很陌生,所以如果其中一些是显而易见的答案,请原谅我

我正在尝试实现向左/向右滑动功能,以便在我的应用程序中的页面之间进行交换。但是,我在检测速度并使用它来确定是否进行了左/右交换时遇到了问题

以下是我的代码,为了清晰起见,保留了调试器说明:

onHorizontalDragStart: (DragStartDetails details) {
  print("Horizontal Drag Start - preflop.");
},
onHorizontalDragDown: (DragDownDetails details) {
  print("Horizontal Drag Down - preflop.");
},
onHorizontalDragUpdate: (DragUpdateDetails details) {
  print("Horizontal Drag Update - preflop. Velocity Delta: " + details.primaryDelta.toString());
},
onHorizontalDragEnd: (DragEndDetails details) {
  // TODO: Check velocity for non-zero but still too slow to swap?
  if (details.primaryVelocity >= 0) {
    print("Horizontal Drag End - preflop movement cancelled. Velocity: " + details.primaryVelocity.toString());

    return;
  }
  else {
    print("Horizontal Drag End - preflop. Velocity: " + details.primaryVelocity.toString());

    Navigator.push(
      context,
      MaterialPageRoute(builder: (context) => Flop()),
    );
  }
}

    onHorizontalDragStart: (DragStartDetails details) {
      print("Horizontal Drag Start - flop.");
    },
    onHorizontalDragDown: (DragDownDetails details) {
      print("Horizontal Drag Down - flop.");
    },
    onHorizontalDragUpdate: (DragUpdateDetails details) {
      print("Horizontal Drag Update - flop. Velocity Delta: " + details.primaryDelta.toString());
    },
    onHorizontalDragEnd: (DragEndDetails details) {
      // TODO: Check velocity for non-zero but still too slow to swap?
      if (details.primaryVelocity <= 0) {
    print("Horizontal Drag End - flop movement cancelled. Velocity: " + details.primaryVelocity.toString());

    return;
      }
      else {
    print("Horizontal Drag End - flop. Velocity: " +
        details.primaryVelocity.toString());

    Navigator.pop(context);
      }
    }
我面临两个主要问题。首先,有时,即使我正确地刷卡,
primaryVelocity
返回零。这可以通过跟踪
onHorizontalDragUpdate
然后查看结果
onHorizontalDragEnd
来证明。现在,我明白了,如果我拖动然后停止,然后释放光标,结束速度在逻辑上将为零——但在这种情况下,我没有感觉到暂停——只是拖动和释放

I/flutter (17305): Horizontal Drag Down - flop.
I/flutter (17305): Horizontal Drag Start - flop.
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -6.85546875
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -8.763950892857167
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -7.998046875
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -9.906529017857167
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -9.140625
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -8.763950892857167
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -7.998046875
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -5.336216517857139
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -6.85546875
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -4.5703125
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -4.193638392857139
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -2.28515625
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -2.28515625
I/flutter (17305): Horizontal Drag End - flop movement cancelled. Velocity: 0.0
另一个问题是,
primaryVelocity
的符号有时似乎不正确。例如,尽管
onHorizontalDragUpdate
具有负
primaryDelta
值,但得到的
onHorizontalDragUpdate
的速度值为正值:

I/flutter (17305): Horizontal Drag Down - flop.
I/flutter (17305): Horizontal Drag Start - flop.
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -12.191685267857167
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -11.42578125
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -14.476841517857167
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -13.334263392857139
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -11.049107142857139
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -6.85546875
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -6.85546875
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -4.193638392857139
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -3.427734375
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -3.427734375
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -1.142578125
I/flutter (17305): Horizontal Drag Update - flop. Velocity Delta: -1.142578125
I/flutter (17305): Horizontal Drag End - flop. Velocity: 58.203062840330496
如有任何建议,将不胜感激。让我知道是否有任何额外的代码,我可以提供帮助回答问题。谢谢

编辑

根据Ulas的建议,我更新了所有插件/IDE。看起来第一个问题已经解决了-我不再得到0.0的速度了

然而,我仍然遇到第二个问题:

I/flutter (18942): Horizontal Drag Down - flop.
I/flutter (18942): Horizontal Drag Start - flop.
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -6.478794642857167
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -7.998046875
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -8.763950892857167
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -9.140625
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -9.906529017857167
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -10.283203125
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -13.334263392857167
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -13.334263392857167
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -14.476841517857139
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -12.191685267857139
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -10.283203125
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -12.191685267857139
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -10.283203125
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -8.763950892857139
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -6.85546875
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -5.336216517857139
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -4.5703125
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -3.427734375
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -3.427734375
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -1.9084821428571388
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -1.142578125
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: 0.0
I/flutter (18942): Horizontal Drag End - flop. Velocity: 220.44058450541567

我在你的代码中没有获得任何0.0速度,你可以尝试其他颤振通道,如beta和升级最新版本吗?

嗨,Ulas,我更新到了最新版本,这似乎解决了0速度问题。然而,我仍然在经历另一个。
I/flutter (18942): Horizontal Drag Down - flop.
I/flutter (18942): Horizontal Drag Start - flop.
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -6.478794642857167
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -7.998046875
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -8.763950892857167
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -9.140625
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -9.906529017857167
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -10.283203125
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -13.334263392857167
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -13.334263392857167
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -14.476841517857139
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -12.191685267857139
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -10.283203125
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -12.191685267857139
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -10.283203125
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -8.763950892857139
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -6.85546875
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -5.336216517857139
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -4.5703125
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -3.427734375
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -3.427734375
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -1.9084821428571388
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: -1.142578125
I/flutter (18942): Horizontal Drag Update - flop. Velocity Delta: 0.0
I/flutter (18942): Horizontal Drag End - flop. Velocity: 220.44058450541567