gpt4 book ai didi

flutter - 上滑换屏动画

转载 作者:IT王子 更新时间:2023-10-29 06:42:27 24 4
gpt4 key购买 nike

刚接触flutter开发,想做这种换屏时的动画(第一页也往上滑)。我搜索了有关此的教程和帖子,但没有找到。有办法做到这一点吗?

enter image description here

最佳答案

这是工作代码。您可以尝试更改持续时间和值 from 以进行反向动画。但现在它似乎工作得很好

class _MyWidgetState extends State<MyWidget>
with SingleTickerProviderStateMixin {

AnimationController _animationController;

@override
void initState() {
_animationController = AnimationController(vsync: this, duration: Duration(milliseconds: 2000)); // you can try to set another duration
super.initState();
}

@override
Widget build(BuildContext context) {
_animationController.reverse(from: 0.2); // you can try to set another value for from
return SlideTransition(
position: Tween<Offset>(
begin: Offset.zero,
end: const Offset(0.0, -1.0),
).animate(_animationController),
child: Scaffold(
appBar: AppBar(
title: Text('MyWidget'),
),
body: _createBody(),
));
}

Widget _createBody() {
// create body here
// perform this action on click:
Navigator.of(context).push(getRoute());
}

PageRoute getRoute() {
_animationController.forward(from: 0.0);
return PageRouteBuilder(
pageBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
return MySecondScreen();
},
transitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
return SlideTransition(
position: Tween<Offset>(
begin: const Offset(0.0, 1.0),
end: Offset.zero,
).animate(animation),
child: SlideTransition(
position: Tween<Offset>(
begin: Offset.zero,
end: const Offset(0.0, 1.0),
).animate(secondaryAnimation),
child: child,
),
);
},
);
}

dispose() {
super.dispose();
_animationController.dispose();
}
}

关于flutter - 上滑换屏动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57269078/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com