使用 go_router 推送一个透明页面?

huangapple go评论108阅读模式
英文:

Push a transparent page with go_router?

问题

为了显示覆盖我的shellroute的抽屉,我需要在我的页面堆栈顶部推送一个半透明的页面。到目前为止,当我使用

  1. GoRouter.of(rootNavigatorKey.currentContext!).pushNamed('myDrawer');

时,背景仍然不透明。我找到了一个办法,使用传统的Navigator和PageRouteBuilder:

  1. Navigator.of(rootNavigatorKey.currentContext!).push(
  2. PageRouteBuilder(
  3. fullscreenDialog: true,
  4. opaque: false,
  5. pageBuilder: (_, __, ___) => MyDrawer(),
  6. ),
  7. );

在使用go_router时,是否有一种方式可以使用类似opaque参数的选项来推送路由?

英文:

In order show a drawer that covers my shellroute, i need to push a semi-transparent page on top of my page stack. So far the background remain opaque when i use the

  1. GoRouter.of(rootNavigatorKey.currentContext!).pushNamed('myDrawer');

I have found a ruse using the traditional Navigator and PageRouteBuilder :

  1. Navigator.of(rootNavigatorKey.currentContext!).push(
  2. PageRouteBuilder(
  3. fullscreenDialog: true,
  4. opaque: false,
  5. pageBuilder: (_, __, ___) => MyDrawer(),
  6. ),
  7. );

Is there a way to use an option like the opaque parameter, with go_router, when pushing routes ?

答案1

得分: 2

你可以使用CustomTransitionPage。在你的应用程序中,需要找到定义GoRouter实例的位置,并按照以下方式将其添加到路由列表中:

  1. GoRoute(
  2. path: '/myDrawer',
  3. name: 'myDrawer',
  4. pageBuilder: (context, state) => CustomTransitionPage(
  5. fullscreenDialog: true,
  6. opaque: false,
  7. transitionsBuilder: (_, __, ___, child) => child,
  8. child: const MyDrawer(),
  9. ),
  10. )
英文:

You can use CustomTransitionPage for that. You'll have to go to where the GoRouter instance of your app is defined and add it like below to list of routes:

  1. GoRoute(
  2. path: '/myDrawer',
  3. name: 'myDrawer',
  4. pageBuilder: (context, state) => CustomTransitionPage(
  5. fullscreenDialog: true,
  6. opaque: false,
  7. transitionsBuilder: (_, __, ___, child) => child,
  8. child: const MyDrawer(),
  9. ),
  10. )

huangapple
  • 本文由 发表于 2023年4月6日 21:09:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75949913.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定