【发布时间】:2021-05-29 04:55:55
【问题描述】:
我正在使用 PageView.builder 小部件,我想在每 5 次网页浏览后插入一个自定义页面。
return PageView.builder(
itemCount: 50,
itemBuilder: (context, index) {
if (index % 5 == 0 && index != 0)
return Column(
children: [
customImage(), // this will be my custom pageview
Image.network(_newList[index].image),
],
);
else
return Image.network(_newList[index].image);
},
);
上面的代码工作正常,但它正在替换索引 5 的图像并显示我的自定义页面。
所以请帮助我如何在不丢失任何索引数据的情况下显示 customImage。
【问题讨论】:
-
Image.network(_newList[index - index ~/ 5].image)或类似的东西 -
不工作,您能提供任何其他解决方案
-
我丢失了 index = 5 个数据
-
不,你没有输:
child: PageView.builder( itemCount: 50, itemBuilder: (ctx, i) { return FittedBox( child: i % 5 == 0 && i != 0 ? FlutterLogo() : Text('${i - i ~/ 5}') ); } ),- 基本上你必须跳过i ~/ 5元素,它是用i - i ~/ 5完成的 -
我正在丢失数据,itemCount 是 50,这意味着我必须获得索引 0 到 49,但我却达到了 40,为什么?
标签: android flutter dart flutter-dependencies flutter-animation