list - 如何编写 PageView 在背景也滚动的同时滚动普通列表?
问题描述
我想构建一个屏幕,其中包含可以滚动的项目列表,这些项目具有独特的背景,当我继续滚动时,它也应该滚动(看起来像滚动)。这是一个示例,如您所见,当我滚动项目时,背景变化非常平滑,就好像它是它的一部分一样。
到目前为止,我已经尝试操纵 PageViews 来实现这一点,但我现在最好的方法是在项目上使用单个 PageView,我已经在其中编写了代码,当页面更改时,一个接一个地移动背景。这是代码:
页面预览:
Column(
children: [
Container(
width: sizes.width(context, 414),
height: sizes.height(context, 100),
decoration: topImage == null ? BoxDecoration(color: Colors.blue) : BoxDecoration(
image: DecorationImage(
image: FileImage(topImage),
fit: BoxFit.fitWidth
)
),
), // first image
Container(
width: sizes.width(context, 414),
height: sizes.height(context, 696),
decoration: mainImage == null ? BoxDecoration(color: colours.black()) : BoxDecoration(
image: DecorationImage(
image: FileImage(mainImage),
fit: BoxFit.fitHeight
)
),
child: Stack(
children: [
// a widget here
PageView.builder(
itemCount: (allModes.length + 1),
onPageChanged: (index) {
setState(() {
topImage = index == 0 ? null : File(allModes[index-1].wallpaperPath);
mainImage = index == allModes.length ? null : File(allModes[index].wallpaperPath);
bottomImage = index >= (allModes.length-1) ? null : File(allModes[index+1].wallpaperPath);
});
},
itemBuilder: (context, index) {
if(index == allModes.length) {
return Text(
"add + " + " :: " + index.toString(),
textAlign: TextAlign.center,
style: TextStyle(
color: colours.white(),
fontFamily: 'ProductSans',
fontWeight: FontWeight.bold,
fontSize: _pageController.page.toInt() == index ? 36 : 24
),
);
}
else {
return Text(
allModes[index].title + " :: " + index.toString(),
textAlign: TextAlign.center,
style: TextStyle(
color: colours.white(),
fontFamily: 'ProductSans',
fontWeight: FontWeight.bold,
fontSize: _pageController.page.toInt() == index ? 36 : 24
),
);
}
},
scrollDirection: Axis.vertical,
controller: _pageController,
),
],
),
), // main image
Container(
width: sizes.width(context, 414),
height: sizes.height(context, 100),
decoration: bottomImage == null ? BoxDecoration(color: Colors.greenAccent) : BoxDecoration(
image: DecorationImage(
image: FileImage(bottomImage),
fit: BoxFit.fitWidth
)
),
), // last image
],
)
请帮我解决我还能做什么,我的一个朋友建议我使用 ScrollView 作为包装器和可扩展的小部件作为它的孩子,但我不明白如何实际做到这一点。
编辑:这是示例的图像:
解决方案
推荐阅读
- php - 提交表单时,会话数据会变得很多
- php - PhpStorm 是否可以根据更改的项目文件夹结构自动更改命名空间和用途?
- javascript - 如何在 javascript 的 addEventListener 函数中添加函数?
- react-native - React Native 中的基本功能
- java - Corda - 验证公证人抛出 java.lang.IllegalArgumentException
- postgresql - 如何确保 Postgres 中外键的有效性
- java - 完全原生的 Android 应用程序可以调用 Java 吗?
- python-3.x - 如何使用 Pyspark 创建列表 json?
- java - 如何自动检索任意 jar 的依赖项?
- swift - Swift Package Manager:Target可以访问其他Target的依赖