美文网首页
flutter跳转(添加一个动画效果)

flutter跳转(添加一个动画效果)

作者: Gavin113 | 来源:发表于2019-06-18 12:10 被阅读0次
    onTap: (index) {
                        Navigator.of(context).push(new PageRouteBuilder(pageBuilder:
                            (BuildContext context, Animation<double> animation,
                                Animation<double> secondaryAnimation) {
                          return new MyselfDetails();
                        }, transitionsBuilder: (
                          BuildContext context,
                          Animation<double> animation,
                          Animation<double> secondaryAnimation,
                          Widget child,
                        ) {
                          // 添加一个平移动画
                          return BRouter.createTransition(animation, child);
                        }));
                      }
    

    动画效果

    class BRouter {
      /// 创建一个平移变换
      /// 跳转过去查看源代码,可以看到有各种各样定义好的变换
      static SlideTransition createTransition(
          Animation<double> animation, Widget child) {
        return new SlideTransition(
          position: new Tween<Offset>(
            begin: const Offset(1.0, 0.0),
            end: const Offset(0.0, 0.0),
          ).animate(animation),
          child: child, // child is the value returned by pageBuilder
        );
      }
    }
    

    相关文章

      网友评论

          本文标题:flutter跳转(添加一个动画效果)

          本文链接:https://www.haomeiwen.com/subject/amzxqctx.html