Home > Software design >  Get Query Parameters from Flutter deep link
Get Query Parameters from Flutter deep link

Time:10-13

Using a deep link in an email, I am able to open my app and have it go to the correct page. However, the query parameters are coming up empty. The link in the email definitely includes the parameters, but when I try to access them in the app, it says there are none.

Is there no way to get query parameters unless you use Dynamic links with firebase? I would like to avoid that if possible.

I looked into the uni_links plugin, but it has no mention of query parameters.

CodePudding user response:

I have developed myself an app with deep linking which fetches one parameter from the url. I have achieved that using the official Navigator 2.0 extending the RouteInformationParser and RouteInformationParser. So from the parser I could read the query parameters like this.

uri.queryParameters['param']

Setting my customized configuration in such a way that it could load the screen I needed with the parameter from the url.

The main drawback is that this implementation requires to change all the navigation inside the app for achieving a correct behaviour and it may be quite complex to program first.

The main advantage is that this is official and you will be able to tune more the navigator behaviour.

There are some guides on the Internet like this one teaching you how to do it. The size of the solution is too great for explaining it here.

Other more simple solutions like uni_links plugin seems able to fetch these parameters as long as you know how to properly retrieve them from de URI. You can check this solution.

My recommendation is that you debug and fix that bug analyzing where you are actually losing those parameters from the flow of the app.

CodePudding user response:

void initDynamicLinks() async {
    final PendingDynamicLinkData data = await FirebaseDynamicLinks.instance.getInitialLink();
    final Uri deepLink = data?.link;

    if (deepLink != null) {
    var myParam = deepLink.queryParameters["myParam"];
    }

    FirebaseDynamicLinks.instance.onLink( onSuccess: (PendingDynamicLinkData dynamicLink) async {
      final Uri deepLink = dynamicLink?.link;

      if (deepLink != null) {
        var myParam =  deepLink.queryParameters["myParam"];
      }
    }, one rror: (OnLinkErrorException e) async {
     
    });
}
  • Related