如何在网格视图中滑动元素

How can i swipe the elements in a grid view

我正在尝试制作游戏。其中我有一个矩阵,其中有 9 个元素,即 3X3 矩阵。正如您在这张图片中看到的那样,谁能告诉我如何在其中实现 2 个元素的滑动。例如,用户想要滑动 4 和 6,那么他只需用手指滑动即可。

我的 Matrix 代码:-

GridView.count(
            crossAxisCount: 3,
            shrinkWrap: true,
            children: List.generate(array.length, (index) => Container(
              decoration: BoxDecoration(
                  border: Border.all(color: Colors.white)
              ),
              child: Center(child: Text(array[index].toString(),style: TextStyle(color: Colors.white,fontSize: 20.0,fontWeight: FontWeight.w500),)),
            )),
          ),

wrap your widget in a dismissible.. this worked well in my case because it has an interactive animation, allowing a clear way for user to abort

    GridView.count(
        crossAxisCount: 3,
        shrinkWrap: true,
        children: List.generate(array.length, (index) => 

Dismissible(
            key: UniqueKey(),
            child:Container(
          decoration: BoxDecoration(
              border: Border.all(color: Colors.white)
          ),
          child: Center(child: Text(array[index].toString(),style: TextStyle(color: Colors.white,fontSize: 20.0,fontWeight: FontWeight.w500),)),
        )),
      ), //the widget you want the swipe to be detected on
            direction: DismissDirection.up, // or whatever
            confirmDismiss: (direction) {
              if (direction == DismissDirection.up) { // or other directions
                // Swiped up do your thing.
              }
              return Future.value(false); // always deny the actual dismiss, else it will expect the widget to be removed
            })