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

2019-06-18  本文已影响0人  Gavin113
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
    );
  }
}
上一篇下一篇

猜你喜欢

热点阅读