正如路由器描述的那样,很容易为单个页面设置pageBuilder
-Transitions。但是,我希望设置all pages的默认.
如何在颤振中设置使用/用于go_router的默认页面转换?
单页:
// this is the proposed method to do it for single pages
// how can i apply it to all pages without writing the same code?
GoRoute(
path: '/login',
builder: (context, state) => const LoginScreen(),
pageBuilder: (context, state) => CustomTransitionPage<void>(
key: state.pageKey,
child: const LoginScreen(),
transitionsBuilder: (context, animation, secondaryAnimation, child) =>
FadeTransition(opacity: animation, child: child),
),
),
诚挚的问候
发布于 2022-03-27 21:16:43
go_router
包目前不支持这一点,但是为了减少代码重复,您可以创建一个帮助函数,用于为您的路由应用自定义转换,如下所示:
CustomTransitionPage buildPageWithDefaultTransition<T>({
required BuildContext context,
required GoRouterState state,
required Widget child,
}) {
return CustomTransitionPage<T>(
key: state.pageKey,
child: child,
transitionsBuilder: (context, animation, secondaryAnimation, child) =>
FadeTransition(opacity: animation, child: child),
);
}
<...>
GoRoute(
path: '/login',
builder: (context, state) => const LoginScreen(),
pageBuilder: (context, state) => buildPageWithDefaultTransition<void>(
context: context,
state: state,
child: LoginScreen(),
),
),
https://stackoverflow.com/questions/71636397
复制相似问题