#48 viewer: parallax effect when scrolling
This commit is contained in:
parent
1841c60c09
commit
dc4db4c4e3
1 changed files with 20 additions and 1 deletions
|
@ -29,6 +29,8 @@ class MultiEntryScroller extends StatefulWidget {
|
||||||
class _MultiEntryScrollerState extends State<MultiEntryScroller> with AutomaticKeepAliveClientMixin {
|
class _MultiEntryScrollerState extends State<MultiEntryScroller> with AutomaticKeepAliveClientMixin {
|
||||||
List<AvesEntry> get entries => widget.collection.sortedEntries;
|
List<AvesEntry> get entries => widget.collection.sortedEntries;
|
||||||
|
|
||||||
|
PageController get pageController => widget.pageController;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
super.build(context);
|
super.build(context);
|
||||||
|
@ -38,7 +40,7 @@ class _MultiEntryScrollerState extends State<MultiEntryScroller> with AutomaticK
|
||||||
child: PageView.builder(
|
child: PageView.builder(
|
||||||
key: const Key('horizontal-pageview'),
|
key: const Key('horizontal-pageview'),
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
controller: widget.pageController,
|
controller: pageController,
|
||||||
physics: const MagnifierScrollerPhysics(parent: BouncingScrollPhysics()),
|
physics: const MagnifierScrollerPhysics(parent: BouncingScrollPhysics()),
|
||||||
onPageChanged: widget.onPageChanged,
|
onPageChanged: widget.onPageChanged,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
|
@ -64,6 +66,23 @@ class _MultiEntryScrollerState extends State<MultiEntryScroller> with AutomaticK
|
||||||
}
|
}
|
||||||
child ??= _buildViewer(entry);
|
child ??= _buildViewer(entry);
|
||||||
|
|
||||||
|
child = AnimatedBuilder(
|
||||||
|
animation: pageController,
|
||||||
|
builder: (context, child) {
|
||||||
|
// parallax scrolling
|
||||||
|
double dx = 0;
|
||||||
|
if (pageController.hasClients && pageController.position.haveDimensions) {
|
||||||
|
final delta = pageController.page! - index;
|
||||||
|
dx = delta * pageController.position.viewportDimension / 2;
|
||||||
|
}
|
||||||
|
return Transform.translate(
|
||||||
|
offset: Offset(dx, 0),
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
|
||||||
return ClipRect(
|
return ClipRect(
|
||||||
child: child,
|
child: child,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue