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

onTap: (index) {
                    Navigator.of(context).push(new PageRouteBuilder(pageBuilder:
                        (BuildContext context, Animation animation,
                            Animation secondaryAnimation) {
                      return new MyselfDetails();
                    }, transitionsBuilder: (
                      BuildContext context,
                      Animation animation,
                      Animation secondaryAnimation,
                      Widget child,
                    ) {
                      // 添加一个平移动画
                      return BRouter.createTransition(animation, child);
                    }));
                  }

动画效果

class BRouter {
  /// 创建一个平移变换
  /// 跳转过去查看源代码,可以看到有各种各样定义好的变换
  static SlideTransition createTransition(
      Animation animation, Widget child) {
    return new SlideTransition(
      position: new Tween(
        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跳转(添加一个动画效果))