简体   繁体   English

我正在使用 Flutter swiper package 我想实现以下活动

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

I am Using a Swiper Widget.我正在使用 Swiper 小部件。 I was able to swipe front and back.我能够前后滑动。 But i also want the functionality swiping to the next card while on a onPressed event.但我也希望在 onPressed 事件中刷卡到下一张卡片的功能。 Moreover by pressing a button, I want to move to the next card.此外,通过按一个按钮,我想移动到下一张卡片。 How to achieve this functionality.如何实现这个功能。 This is my Swiper Widget.这是我的 Swiper 小部件。

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,
                              ),
                            )

And this is my button这是我的按钮

 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(),
          ),

add a controller to the swipper SwiperController controller = SwiperController();将 controller 添加到SwiperController controller = SwiperController(); then on the onTap call controller.next()然后在onTap上调用controller.next()

You have to define and add controller to the swipper after that you can control the swipper on onTap event.such as您必须定义 controller 并将其添加到 swipper 之后,您才能在 onTap 事件上控制 swipper。例如

final controller=SwiperController()

After that assign it to the Swipper as之后将其分配给 Swipper 作为

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

Now you can control the index of the swipper using the controller and change the state by calling method such as现在您可以使用 controller 控制 swipper 的索引,并通过调用方法更改 state,例如

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


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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在颤振中实现以下布局? - How can I achieve the following layout in flutter? Flutter/Dart - 如何使用 onPressed 和 flutter_Swiper 包中的 flatButton 播放列表中的声音? - Flutter/Dart - How can I play sounds from a list using onPressed with a flatButton in flutter_Swiper package? 在 Flutter 中,我使用 local_auth 0.6.2+3 package 并实现了示例代码。 单击身份验证按钮时出现以下错误 - In Flutter, I am using local_auth 0.6.2+3 package and implemented the example code. I get the following error when I click the authenticate button Flutter - 我无法使用文件选取器加载文件 package - Flutter - I am unable to load file using File Picker package 嗨,我正在使用颤振开发移动应用程序,如果我遵循的策略正确,我会感到有点困惑? - Hi, I am developing an mobile application using flutter and I am bit confused if the strategy I am following is correct? 我如何实现以下布局 - How I achieve the following layout 我在运行 flutter create my_appName: "my_appName" is not a valid Dart package name 时收到以下错误 - I am getting the following error on running flutter create my_appName: "my_appName" is not a valid Dart package name 我正在使用Flutter Preview 1 - Am I using Flutter Preview 1 "<i>I am using &quot;jitsi meet&quot; in Flutter.<\/i>我在 Flutter 中使用“jitsi meet”。<\/b> <i>I want to get rid of the menu tabs on the call screen<\/i>我想摆脱通话屏幕上的菜单选项卡<\/b>" - I am using "jitsi meet" in Flutter. I want to get rid of the menu tabs on the call screen 我想从颤动中的以下数据中检索每个实体 - I want to retrive each entity from following data in flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM