flutter 使用go_router推送透明页面?

5jvtdoz2  于 2023-04-13  发布在  Flutter
关注(0)|答案(1)|浏览(175)

为了显示覆盖shellroute的drawer,我需要在页面堆栈的顶部推一个半透明的页面。

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

我发现了一个使用传统导航器和PageRouteBuilder的鲁塞:

Navigator.of(rootNavigatorKey.currentContext!).push(
                    PageRouteBuilder(
                      fullscreenDialog: true,
                      opaque: false,
                      pageBuilder: (_, __, ___) => MyDrawer(),
                    ),
                  );

在推送路由时,有没有办法在go_router中使用类似opaque参数的选项?

rt4zxlrg

rt4zxlrg1#

你可以使用CustomTransitionPage来实现。你必须转到应用的GoRouter示例的定义位置,并将其添加到路由列表中,如下所示:

GoRoute(
       path: '/myDrawer',
       name: 'myDrawer',
       pageBuilder: (context, state) => CustomTransitionPage(
           fullscreenDialog: true,
           opaque: false,
           transitionsBuilder: (_, __, ___, child) => child,
           child: const MyDrawer(),
       ),
)

相关问题