请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

没有动画效果

class LogoWidget extends StatelessWidget {
const LogoWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
margin: const EdgeInsets.symmetric(vertical: 10),
child: const FlutterLogo(),
);}}
class GrowTransition extends StatelessWidget {
GrowTransition({required this.child, required this.animation});
final Widget child;
final Animation animation;
@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: animation,
builder: (context,child)=>Container(
height: animation.value,
width: animation.value,
child: child,
),
child: child,
);}}
class _LogoAppState extends State with SingleTickerProviderStateMixin {
late Animation animation;
late AnimationController controller;
@override
void initState() {
super.initState();
controller =
AnimationController(vsync: this, duration: const Duration(seconds: 2));
animation = Tween(begin: 0, end: 300).animate(controller);
controller.forward();
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return GrowTransition(child:const LogoWidget(),animation: animation);
}}

正在回答 回答被采纳积分+3

插入代码

1回答

CrazyCodeBoy 2021-11-19 15:22:23

对照下这块课程源码检查下你的代码实现看是否有不一样的地方呢:https://git.imooc.com/coding-321/flutter_trip/src/master/doc/%E5%8A%A8%E7%94%BBAnimation%E5%BC%80%E5%8F%91%E6%8C%87%E5%8D%97.md

0 回复 有任何疑惑可以回复我~
  • 提问者 Svanur #1
    GrowTransition类不对
    回复 有任何疑惑可以回复我~ 2021-11-19 15:41:47
  • Junble 回复 提问者 Svanur #2
    你解决了吗,我这里也是同样情况,教学代码跑起来也没动画效果
    回复 有任何疑惑可以回复我~ 2022-09-02 16:14:23
  • 他这里是因为直接 return AnimatedBuild 导致无效的,老师代码是用Center包裹的,如果外层不用Center包裹就会变成 Container 包 Container,那样就不会有动画效果
    正确的:
    Widget build(BuildContext context) {
        return Center(
          child: AnimatedBuilder(
            animation: animation,
            builder: (context, child) => Container(
              height: animation.value,
              width: animation.value,
              child: child,
            ),
            child: child,
          ),
        );
      }
    回复 有任何疑惑可以回复我~ 2022-09-19 01:45:57
问题已解决,确定采纳
还有疑问,暂不采纳
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号