flutter_swiper icon indicating copy to clipboard operation
flutter_swiper copied to clipboard

怎么使swiper禁止上下滚动,只能左右滑动

Open wiimiiesc opened this issue 1 year ago • 1 comments

我尝试了 physics: const NeverScrollableScrollPhysics(), 之后发现左右滑动被禁止了,但仍然能上下滚动。在这之后尝试了在swiper外层套了一层 GestureDetector 并设置了 onVerticalDragUpdate: (detail){}, 还是没有效果。

这是我的代码:

  Widget _Category() {
    return SizedBox(
      width: ScreenAdapter.widht(1080),
      height: ScreenAdapter.height(400),
      child: Obx(()=>GestureDetector(
        onVerticalDragUpdate: (detail){},
        child: Swiper(
          physics: const NeverScrollableScrollPhysics(),
          scrollDirection:Axis.horizontal,
          autoplayDisableOnInteraction: true,
          itemCount: controller.categoryList.length~/10,
          pagination: SwiperPagination(
              margin: EdgeInsets.only(bottom: 10),
              builder: SwiperCustomPagination(
                  builder: (BuildContext context, SwiperPluginConfig config) {
                    return ConstrainedBox(
                      constraints:
                      BoxConstraints.expand(height: ScreenAdapter.height(30)),
                      child: Row(
                        children: <Widget>[
                          Expanded(
                            child: Align(
                              alignment: Alignment.center,
                              child: const RectSwiperPaginationBuilder(
                                  size: Size(20, 3),
                                  activeSize: Size(20, 3),
                                  color: Colors.black12,
                                  activeColor: Colors.black54)
                                  .build(context, config),
                            ),
                          )
                        ],
                      ),
                    );
                  })),
          loop: false,
          itemBuilder: (context, index) {
            return GridView.builder(
                itemCount: 10,
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 5,
                    crossAxisSpacing: ScreenAdapter.widht(20),
                    mainAxisSpacing: ScreenAdapter.height(20)),
                itemBuilder: (context, i) {
                  String? pic = controller.categoryList[index*10+i].pic;
                  return Column(
                    children: [
                      Container(
                        alignment: Alignment.center,
                        width: ScreenAdapter.widht(116),
                        child: Image.network(
                          "https://miapp.itying.com/${pic!.replaceAll("\\", "/")}",
                          fit: BoxFit.fitWidth,
                        ),
                      ),
                      SizedBox(
                        width: ScreenAdapter.height(0),
                      ),
                      Text(
                        "${controller.categoryList[index*10+i].title}",
                        style: TextStyle(fontSize: ScreenAdapter.size(34)),
                      )
                    ],
                  );
                });
          },
        ),
      ))
    );
  }

wiimiiesc avatar Mar 16 '24 03:03 wiimiiesc

在你的GridView下面添加physics: const NeverScrollableScrollPhysics(), 我是通过这个解决的

yuanzhiji avatar May 26 '24 06:05 yuanzhiji