How can i get Uri params in Flutter Mobile when open with Deeplink

261 Views Asked by At

I configured Navigator through GoRouter and I want to know how to receive a parameter through a deep link. Instead of configuring arguments in Widget corresponding to the destination, For iOS simulators, on the connected terminal,

xcrun simctl openurl booted "customScheme://myHost.name.com/login?p=0"

If I enter , I want to enter the login screen and use the parameter p=0 in Login Widget at the same time. Is there any other way?

I considered using uni_links, but I do not want to use it because it interferes with Flutter's basic Deeplinking activities.

(The reason is that if you run the command from the terminal as shown above, if you have uni_links, you will only move to the root and not reach the sub-destination.)

Below is the routerConfig of GoRouter.

final _router = GoRouter(
  initialLocation: '/home',
  navigatorKey: _rootNavigatorKey,
  observers: [
    GoRouterObserver(),
    routeObserver
  ],
  routes: [
    GoRoute(
      path: "/",
      builder: (context, state) {
        return const Root();
      },
      routes: [
        ShellRoute(
          navigatorKey: _shellNavigatorKey,
          builder: (context, state, child) {
            return ScaffoldWithNavBar(child: child);
          },
          routes: [
            GoRoute(
              path: 'home',
              builder: (context, state) {
                return const Home();
              },
            ),
            GoRoute(
              path: 'discover',
              builder: (context, state) {
                return const Discover();
              },
            ),
            GoRoute(
                path: 'shop',
                builder: (context, state) {
                  return const Shop();
                }),
          ],
        ),
        GoRoute(
            path: 'login',
            parentNavigatorKey: _rootNavigatorKey,
            builder: (context, state) {
              return const Login();
            },
            routes: loginRouter),
      ],
    )
  ],
);
0

There are 0 best solutions below