flutter 如何在Getx/GetPage中使用命名路由的customTransition?

v8wbuo2f  于 2023-01-21  发布在  Flutter
关注(0)|答案(1)|浏览(473)

我想要一个页面过渡取决于我去的页面。库比蒂诺是完美的一种方式,像这样:

GetPage(
    name: Routes.SPLASH_SCREEN,
    page: () => SplashView(),
    binding: SplashScreenBinding(),
    transition: Transition.cupertino,
    transitionDuration: Duration(milliseconds: screenTransitionTime)),

...但是当返回时,我想要相同类型的过渡(一个页面在视觉上将另一个页面推出),但是从左向右移动,而不是从右向左移动。Transition类中没有这样的过渡,所以我尝试自定义我自己的过渡。
我试了几个小时,但找不到任何可用的示例。我需要知道这里发生了什么:

GetPage(
name: Routes.SPLASH_SCREEN,
page: () => SplashView(),
binding: SplashScreenBinding(),
customTransition: ????,
transitionDuration: Duration(milliseconds: screenTransitionTime)),

这是我已经尝试过没有成功:

TransitionBuilder customTransition = (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
    return PageTransition(
      child: child,
      type: PageTransitionType.scale,
      alignment: Alignment.topCenter,
      duration: Duration(milliseconds: 800),
      curve: Curves.elasticOut,
    );
  };

GetPage(
  customTransition: customTransition,
  page: NewPage(),
)

以及

TransitionBuilder customTransition = (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
    return ScaleTransition(
      scale: Tween<double>(begin: 0.0, end: 1.0).animate(
        CurvedAnimation(
          parent: animation,
          curve: Curves.elasticOut,
        ),
      ),
      child: child,
    );
  };

GetPage(
  customTransition: customTransition,
  page: NewPage(),
)
g6ll5ycj

g6ll5ycj1#

你可以用Willpopscope Package 你的整个小部件,并在其中添加这个方法:

Get.off(
      null,
      routeName: route,
      arguments: arguments,
      transition: transition ?? Transition.rightToLeft,
      duration: const Duration(milliseconds: 350),
    );

这将在GetX中添加自定义向后过渡。

相关问题