Skip to content

Instantly share code, notes, and snippets.

@MarcinusX MarcinusX/sliding_cards.dart Secret
Created Apr 25, 2019

Embed
What would you like to do?
class _SlidingCardsViewState extends State<SlidingCardsView> {
PageController pageController;
double pageOffset = 0;
@override
void initState() {
super.initState();
pageController = PageController(viewportFraction: 0.8);
pageController.addListener(() {
setState(() => pageOffset = pageController.page); //<-- add listener and set state
});
}
@override
Widget build(BuildContext context) {
return ...
[
SlidingCard(
name: 'Shenzhen GLOBAL DESIGN AWARD 2018',
date: '4.20-30',
assetName: 'steve-johnson.jpeg',
offset: pageOffset, //<-- pass offset
),
SlidingCard(
name: 'Dawan District, Guangdong Hong Kong and Macao',
date: '4.28-31',
assetName: 'rodion-kutsaev.jpeg',
offset: pageOffset - 1, //<-- pass offset - indexOfCard
),
]
...;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.