Flutter:滑动窗口小部件itemCount从无限(?)起变化

问题描述 投票:0回答:1

我正在使用Swiper小部件构建助手列表。问题是,例如,从助手列表中来的只有1个用户或2个用户,而刷卡器无限次地向这些用户致敬,我想知道如何将其限制为助手的数量。谢谢!这是我的代码:

    child: Swiper(
      autoplay: true,
      autoplayDelay: 2000,
      itemBuilder: (BuildContext context, int index) {
        return Column(
          mainAxisSize: MainAxisSize.min,
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: <Widget>[
            CircleAvatar(
              backgroundImage: NetworkImage(
                  "host${_user.img}"),
              radius: 35.0,
            ),
            Text(
              assistants[index].username,
              style: TextStyle(fontSize: 12.0),
            ),
          ],
        );
      },
      scale: .01,
      itemCount: assistants.length,
      viewportFraction: .18,
    ),
flutter dart flutter-layout
1个回答
0
投票

实际上,它已经只构建了2个项目(或者最好根据助手列表的长度来说明它的构建项目)。因此,如果您希望它结束​​于某个地方,则可以轻松地将loop属性设置为false。尝试下面的代码: child: Swiper( autoplay: true, loop: false, //this is the property that prevents the swiper from looping autoplayDelay: 2000, itemBuilder: (BuildContext context, int index) { return Column( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: <Widget>[ CircleAvatar( backgroundImage: NetworkImage( "host${_user.img}"), radius: 35.0, ), Text( assistants[index].username, style: TextStyle(fontSize: 12.0), ), ], ); }, scale: .01, itemCount: assistants.length, viewportFraction: .18, ),

© www.soinside.com 2019 - 2024. All rights reserved.