【问题标题】:How to implement swipe action to move the colored tile to uncolored tile number puzzle flutter?如何实现滑动动作将彩色瓷砖移动到无色瓷砖数字拼图颤动?
【发布时间】:2020-02-28 06:02:00
【问题描述】:

Screen of the number puzzle game

这是我的代码.. 当点击按钮时,我使用了手势检测器的 ontap() 函数来移动磁贴。我想实现滑动的功能,将磁贴移动到无色部分。

main.dart

 Widget tiles(int i) {
bool isZero = i == 0;
return GestureDetector(
  onTap: (){
    movePosition(i);
 },

  child: ShakeView(
   controller: _shakeController,
    child: Container(

      width: 125,
      height: 100,
      margin: EdgeInsets.all(5.0),
      decoration: BoxDecoration(

        color: isZero ? Colors.white : Color(0xff000080),
        border: Border.all(width: 2.0),
      ),
      child: Center(
        child: Text(
          '$i',
          style: TextStyle(color: Colors.white, fontSize: 25),
        ),
      ),
    ),

  ),
);

}

【问题讨论】:

  • 尝试动画容器。

标签: flutter flutter-layout flutter-animation


【解决方案1】:

GestureDetector 让您走在正确的轨道上。使用onPanUpdate 属性,而不是onTap。 onPanUpdate 采用这样的函数:

GestureDetector(onPanUpdate: (details) {
  if (details.delta.dx > 0) {
    // detecting swipe right
  }
});

另外,请查看这篇关于构建自定义滑块的中型文章 https://medium.com/@rjstech/building-a-custom-slider-in-flutter-with-gesturedetector-fcdd76224acd

【讨论】:

    猜你喜欢
    • 2014-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-28
    • 1970-01-01
    相关资源
    最近更新 更多