Swiper小部件itemCount从无穷大变化

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

我正在使用Swiper Library建立助手列表。但是问题是从助手列表中我仅接收1或2个实例,但是Swiper无限次重复这些用户。我想知道如何将其限制为助手的数量。这是我的代码:

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

还有这是Swiper库属性的列表,您可以查看其中的任何内容进一步的更改。

enter image description here

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