Skip to content

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

@wiimiiesc

Description

@wiimiiesc

我尝试了 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)),
                      )
                    ],
                  );
                });
          },
        ),
      ))
    );
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions