【问题标题】:How to insert custom page in Flutter Pageview.builder?如何在 Flutter Pageview.builder 中插入自定义页面?
【发布时间】:2021-05-28 17:30:55
【问题描述】:

我在我的应用程序中使用 Pageview.builder() 小部件。

PageView.builder(
     itemCount: _newsList.length,
     itemBuilder: (context, index){
      if(_newsList.Length != null){
        return Image.network(_newsList[index].image);
     } else Text("No Data");
   }
)

现在我想在每 5 次浏览图片后显示一个自定义图片,请指导我

【问题讨论】:

    标签: android flutter dart flutter-layout flutter-animation


    【解决方案1】:

    每 5 张图片后,返回自定义图片。

    final customImagesCount = (_newsList.length/5).floor;
    
    var customImagesDisplayedCount = 0;
    PageView.builder(
         itemCount: _newsList.length + customImagesCount,
         itemBuilder: (context, index){
          if(index % 5 != 0){
            return Image.network(_newsList[index - customImagesDisplayedCount].image);
          } else {
            customImageDisplayCount++;
            // return your CustomImage
          }
       }
    )
    

    【讨论】:

    • RangeError(索引):无效值:不在包含范围 0..9:10
    • 更新了解决方案。这是由于访问 _newsList 数组所致。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-16
    相关资源
    最近更新 更多