如何执行滑动动作以将有色瓷砖移动到无色瓷砖编号拼图扑?

问题描述 投票:0回答:1

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个回答
0
投票

您在GestureDetector的正确轨道上。使用onPanUpdate属性而不是onTaponPanUpdate具有如下功能:

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

也请查阅有关构建自定义滑块https://medium.com/@rjstech/building-a-custom-slider-in-flutter-with-gesturedetector-fcdd76224acd的这篇中等文章>

© www.soinside.com 2019 - 2024. All rights reserved.