我正在使用 Flutter swiper 包,我想实现以下 activity

I am using Flutter swiper package and I want to achieve the following activity

我正在使用 Swiper Widget。我能够前后滑动。但我也希望在 onPressed 事件中滑动到下一张卡片的功能。此外,通过按下一个按钮,我想移动到下一张卡片。如何实现这个功能。 这是我的 Swiper Widget。

Swiper(
                              scrollDirection: Axis.horizontal,
                              itemCount: studentDataWithAttendanceData.isEmpty
                                  ? 0
                                  : studentDataWithAttendanceData.length,
                              itemBuilder: (BuildContext context, int index) {
                                return MyClassRoomCard(
                                  studentData:
                                      studentDataWithAttendanceData[index]
                                          .studentData,
                                  attendanceStatus:
                                      studentDataWithAttendanceData[index]
                                          .attendanceStatus,
                                );
                              },
                              scale: 0.8,
                              viewportFraction: 0.9,
                              onIndexChanged: rollNumberCallback,
                              layout: SwiperLayout.STACK,
                              itemWidth: 375,
                              itemHeight: 500,
                              pagination: SwiperPagination(
                                builder: DotSwiperPaginationBuilder(
                                  activeColor: Colors.indigo.shade400,
                                  color: Colors.grey.shade400,
                                ),
                              ),
                              control: SwiperControl(
                                color: Colors.indigo.shade400,
                                padding: EdgeInsets.symmetric(horizontal: 15.0),
                                iconPrevious: Icons.arrow_back_ios_rounded,
                                iconNext: Icons.arrow_forward_ios_rounded,
                                size: 20,
                              ),
                            )

这是我的按钮

 RaisedButton(
            elevation: 5.0,
            padding: EdgeInsets.all(22.0),
            onPressed: onTap,//---------------->by tapping this, I want to change the card to the next.
            child: Icon(
              icon,
              color: iconColor,
              size: 50.0,
            ),
            color: buttonColor,
            shape: CircleBorder(),
          ),

向刷卡器添加一个控制器 SwiperController controller = SwiperController(); 然后在 onTap 称呼 controller.next()

您必须定义控制器并将其添加到刷卡器,然后您可以在 onTap 上控制刷卡器 event.such as

final controller=SwiperController()

之后将其分配给 Swipper 作为

Swiper(
    controller: SwiperController(),
    //Rest are the same...
)

现在可以通过controller控制swipper的index,调用方法改变状态,比如

controller.move(1);
controller.next();
controller.previous();


onTap(){
    controller.next();
    //call the method
}