动画值,以及您在Flutter中的PageView中滚动的距离

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

所以我想知道是否可以为滚动到下一页的值设置动画。但不仅是onPageChanged,而且还介于两者之间。因此,例如在Snapchat中,顶部元素(搜索栏等)随着不透明度而逐渐消失,具体取决于您离下一页的距离(或距当前页面的距离)。

flutter flutter-animation
1个回答
0
投票
PageView.builder( controller: controller, itemBuilder: (context, position) { if (position == currentPageValue.floor()) { return Transform( transform: Matrix4.identity()..rotateX(currentPageValue - position), child: Container( color: position % 2 == 0 ? Colors.blue : Colors.pink, child: Center( child: Text( "Page", style: TextStyle(color: Colors.white, fontSize: 22.0), ), ), ), ); } else if (position == currentPageValue.floor() + 1){ return Transform( transform: Matrix4.identity()..rotateX(currentPageValue - position), child: Container( color: position % 2 == 0 ? Colors.blue : Colors.pink, child: Center( child: Text( "Page", style: TextStyle(color: Colors.white, fontSize: 22.0), ), ), ), ); } else { return Container( color: position % 2 == 0 ? Colors.blue : Colors.pink, child: Center( child: Text( "Page", style: TextStyle(color: Colors.white, fontSize: 22.0), ), ), ); } }, itemCount: 10, )

您可以查看此文章以获取此类结果:https://medium.com/flutter-community/a-deep-dive-into-pageview-in-flutter-with-custom-transitions-581d9ea6dded

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