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),
),
),
),
),
);
}
您在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的这篇中等文章>