mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 06:46:22 +01:00
Change page switch animation in home
To better handle >2 pages
This commit is contained in:
parent
a2e0dbabe3
commit
363382271f
1 changed files with 31 additions and 4 deletions
|
@ -45,7 +45,7 @@ class Home extends StatefulWidget {
|
|||
final Account account;
|
||||
}
|
||||
|
||||
class _HomeState extends State<Home> {
|
||||
class _HomeState extends State<Home> with TickerProviderStateMixin {
|
||||
@override
|
||||
initState() {
|
||||
super.initState();
|
||||
|
@ -56,6 +56,13 @@ class _HomeState extends State<Home> {
|
|||
}
|
||||
});
|
||||
}
|
||||
_animationController.value = 1;
|
||||
}
|
||||
|
||||
@override
|
||||
dispose() {
|
||||
_animationController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -90,7 +97,16 @@ class _HomeState extends State<Home> {
|
|||
controller: _pageController,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
itemCount: 2,
|
||||
itemBuilder: _buildPage,
|
||||
itemBuilder: (context, index) => SlideTransition(
|
||||
position: Tween(
|
||||
begin: const Offset(0, .05),
|
||||
end: Offset.zero,
|
||||
).animate(_animation),
|
||||
child: FadeTransition(
|
||||
opacity: _animation,
|
||||
child: _buildPage(context, index),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -120,11 +136,13 @@ class _HomeState extends State<Home> {
|
|||
}
|
||||
|
||||
void _onTapNavItem(int index) {
|
||||
_pageController.animateToPage(index,
|
||||
duration: k.animationDurationNormal, curve: Curves.easeInOut);
|
||||
_pageController.jumpToPage(index);
|
||||
setState(() {
|
||||
_nextPage = index;
|
||||
});
|
||||
_animationController
|
||||
..reset()
|
||||
..forward();
|
||||
}
|
||||
|
||||
Future<List<Album>> _importPotentialSharedAlbum() async {
|
||||
|
@ -148,5 +166,14 @@ class _HomeState extends State<Home> {
|
|||
final _pageController = PageController(initialPage: 0, keepPage: false);
|
||||
int _nextPage = 0;
|
||||
|
||||
late final _animationController = AnimationController(
|
||||
duration: k.animationDurationLong,
|
||||
vsync: this,
|
||||
);
|
||||
late final _animation = CurvedAnimation(
|
||||
parent: _animationController,
|
||||
curve: Curves.easeIn,
|
||||
);
|
||||
|
||||
static final _log = Logger("widget.home._HomeState");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue