Flutterfire: [flutter_dynamic_links] Query parameters passed are not fetching ?

Created on 21 Oct 2019  路  11Comments  路  Source: FirebaseExtended/flutterfire

Currently, i am using following code to create dynamic link with the custom query parameter "username".

_generateAndShareDynamicLink() async {
   final DynamicLinkParameters parameters = DynamicLinkParameters(
     uriPrefix: 'https://test.page.link/groupinvite',
     link: Uri.parse('https://test.page.link/groupinvite'),
     androidParameters: AndroidParameters(
       packageName: 'com.test.flutter_authentication',
       minimumVersion: 0,
     ),
     dynamicLinkParametersOptions: DynamicLinkParametersOptions(
       shortDynamicLinkPathLength: ShortDynamicLinkPathLength.unguessable,
     ),
   );
   Uri url = await parameters.buildUrl();
   shareURL(Uri.https(url.authority, url.path, {"username": "Test"}));
}

also, i am using following code to fetch dynamic link with the custom query parameter "username" while app opened via dynamic link.

FirebaseDynamicLinks.instance.onLink(
       onSuccess: (PendingDynamicLinkData dynamicLink) async {
         final Uri deepLink = dynamicLink?.link;
         _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("deepLink2 : ${deepLink}",)));
         if (deepLink != null) {
           Map sharedListId = deepLink.queryParameters;
           print("sharedListId : ${sharedListId}");
           String username=sharedListId["username"];
           print("username : ${username}");
           Navigator.pushNamed(context, deepLink.path);
         }
       }, onError: (OnLinkErrorException e) async {
     print('onLinkError');
     print(e.message);
   });

But, i am not able to fetch data.

@kroikie @roughike @jherencia @zoechi @quetool Can anyone please suggest me how can i pass and fetch data using dynamic links.

Thanks.

dynamic_links bug

All 11 comments

Thank you @JayM96.

Why don't you do this?

_generateAndShareDynamicLink() async {
   final DynamicLinkParameters parameters = DynamicLinkParameters(
     uriPrefix: 'https://test.page.link/groupinvite',
     link: Uri.parse('https://test.page.link/groupinvite?username=Test'),
     androidParameters: AndroidParameters(
       packageName: 'com.test.flutter_authentication',
       minimumVersion: 0,
     ),
     dynamicLinkParametersOptions: DynamicLinkParametersOptions(
       shortDynamicLinkPathLength: ShortDynamicLinkPathLength.unguessable,
     ),
   );
   Uri url = await parameters.buildUrl();
   shareURL(url);
}

@jherencia First i had try the same things as you send me except i was using "short" value instead of "unguessable". But, it didn't worked.

It gives me the null data every time.

After that someone suggest me to try with Uri.https()

That's why i have used it.

I am again send you the whole code with my dynamic link.

import 'package:firebase_dynamic_links/firebase_dynamic_links.dart';
import 'package:flutter/material.dart';
import 'package:share/share.dart';

class TestPage extends StatefulWidget {
  @override
  _TestPageState createState() => _TestPageState();
}

class _TestPageState extends State<TestPage> {
  GlobalKey<ScaffoldState> _scaffoldKey=GlobalKey();

  @override
  void initState() {
    super.initState();

    FirebaseDynamicLinks.instance.onLink(
        onSuccess: (PendingDynamicLinkData dynamicLink) async {
          final Uri deepLink = dynamicLink?.link;
          _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("deepLink2 : ${deepLink}",)));
          if (deepLink != null) {
            Map sharedListId = deepLink.queryParameters;
            print("sharedListId : ${sharedListId}");
            String username=sharedListId["username"];
            print("username : ${username}");

            _scaffoldKey.currentState.showSnackBar(SnackBar(content: Text("username : ${username}",)));
          }
        }, onError: (OnLinkErrorException e) async {
      print('onLinkError');
      print(e.message);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      appBar: AppBar(
        title: Text("Sample"),
      ),
      body: Center(
        child: Text("Test"),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          _generateAndShareDynamicLink();
        },
        child: Icon(
          Icons.add,
          color: Colors.white,
        ),
      ),
    );
  }

  _generateAndShareDynamicLink() async {
    final DynamicLinkParameters parameters = DynamicLinkParameters(
      uriPrefix: 'https://jaymtest.page.link/groupinvite',
      link: Uri.parse('https://jaymtest.page.link/groupinvite?username=Test'),
      androidParameters: AndroidParameters(
        packageName: 'com.test.flutter_authentication',
        minimumVersion: 0,
      ),
      dynamicLinkParametersOptions: DynamicLinkParametersOptions(
        shortDynamicLinkPathLength: ShortDynamicLinkPathLength.unguessable,
      ),
    );
    Uri url = await parameters.buildUrl();
    shareURL(url);
  }

  shareURL(Uri url){
    Share.share(url.toString());
  }
}

You can test this on your code with two plugins Share and Dynamic links

I have no issues getting query parameters. Are you able to retrieve them when you create a manual dynamicLink in the Firebase console?

(have not applied the patch from @jherencia though)

Do you think the code I have written is okay ?

I am getting only one data from pending dynamicdata.getinitialilink() which is www.https://jaym.page.link?groupinvite which is my dynamic link in firebase.

Code looks ok apart from the fact that i would use a company URL in the link and not the pages.link url. But why dont you try creating a manual dynamicLink first and see if this works. Because if it does, then there is something wrong with your Link-Creation method.

Okay I will try.

If the manual one works, i will modify my very own URL to have link parameters and test it myself. Currently i am using REST style urls like http://company.com/invite/12345 ... you can easily grab the parts with:

deepLink.pathSegments[0] --> "invite"
deepLink.pathSegments[1] --> "12345"

Thanks @logemann for the instant reply.

I'll try and let you know asap.

Thanks @logemann for the instant reply.

I'll try and let you know asap.

@JayM96 Did it work for you? Because I have the same problem, I can't get the parameters by any mean!

@ahzmie Following is the stack overflow link where i have pasted the working solution with explanation from how you can implement this functionality from scratch to end.

https://stackoverflow.com/questions/58481840/flutter-how-to-pass-custom-arguments-in-firebase-dynamic-links-for-app-invite/58849538#58849538

@ahzmie Following is the stack overflow link where i have pasted the working solution with explanation from how you can implement this functionality from scratch to end.

https://stackoverflow.com/questions/58481840/flutter-how-to-pass-custom-arguments-in-firebase-dynamic-links-for-app-invite/58849538#58849538

Thank you, I got it.

Was this page helpful?
0 / 5 - 0 ratings