Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flutter_dynamic_links] Query parameters passed are not fetching ? #1289

Closed
JayM96 opened this issue Oct 21, 2019 · 12 comments
Closed

[flutter_dynamic_links] Query parameters passed are not fetching ? #1289

JayM96 opened this issue Oct 21, 2019 · 12 comments
Labels
plugin: dynamic_links Stale Issue with no recent activity type: bug Something isn't working

Comments

@JayM96
Copy link

JayM96 commented Oct 21, 2019

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.

@jherencia
Copy link
Contributor

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);
}

@JayM96
Copy link
Author

JayM96 commented Oct 21, 2019

@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

@logemann
Copy link

logemann commented Oct 22, 2019

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)

@JayM96
Copy link
Author

JayM96 commented Oct 22, 2019

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.

@logemann
Copy link

logemann commented Oct 22, 2019

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.

@JayM96
Copy link
Author

JayM96 commented Oct 22, 2019

Okay I will try.

@logemann
Copy link

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"

@JayM96
Copy link
Author

JayM96 commented Oct 22, 2019

Thanks @logemann for the instant reply.

I'll try and let you know asap.

@BondarenkoStas BondarenkoStas changed the title Query parameters passed in flutter dynamic links are not fetching ? [flutter_dynamic_links] Query parameters passed are not fetching ? Oct 23, 2019
@ahzmie
Copy link

ahzmie commented Mar 10, 2020

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!

@JayM96
Copy link
Author

JayM96 commented Mar 11, 2020

@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
Copy link

ahzmie commented Mar 12, 2020

@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.

@russellwheatley
Copy link
Member

I'm going to close this as the issue was resolved here.

@firebase firebase locked and limited conversation to collaborators May 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
plugin: dynamic_links Stale Issue with no recent activity type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

7 participants