0

I have a detailsPage.dart containing codes for generating firebase dynamic links. I wish to access this page from a dynamic each time the link is clicked.

Here is my detailsPage.dart codes:

_createAndShare() async {
  final DynamicLinkParameters parameters = DynamicLinkParameters(
    uriPrefix: 'https://mydomain.page.link',

    // link: Uri.https('mydomain.com', '$docId', {'postId': '$docId'}),
    link: Uri.parse('https://mydomain.page.link/posts?id=$docId'),


    androidParameters: AndroidParameters(
      packageName: 'com.example.android',
    ),
    dynamicLinkParametersOptions: DynamicLinkParametersOptions(
      shortDynamicLinkPathLength: ShortDynamicLinkPathLength.short,
    ),
    navigationInfoParameters: NavigationInfoParameters(
      forcedRedirectEnabled: true,
      
    ),

    // navigationInfoParameters: ,

    
    socialMetaTagParameters: SocialMetaTagParameters(
      title: $title',
    
    ),
  );

  final ShortDynamicLink shortDynamicLink =
      await parameters.buildShortLink();
  final Uri shortUrl = shortDynamicLink.shortUrl;
  print(shortUrl);
  Share.share('Post link: $shortUrl');
}

In my homepage.dart, I have the following codes:

void initDynamicLinks() async {
//when the app is in the background
FirebaseDynamicLinks.instance.onLink(
    onSuccess: (PendingDynamicLinkData dynamicLink) async {
  final Uri deepLink = dynamicLink?.link;

  if (deepLink != null) {
    // Get.to(JobDetails(docId: deepLink.queryParameters['id'));
    final queryParams = deepLink.queryParameters;

    print("Deep link1= ${deepLink.path}");
    print("params: ${deepLink.queryParameters['id']}");
    DocumentSnapshot id = deepLink.path as DocumentSnapshot;
    Navigator.push(
      context,
      new MaterialPageRoute(
        builder: (BuildContext context) => PostDetails(docId: id),
      ),
    );

    //

  }
}, onError: (OnLinkErrorException e) async {
  print('onLinkError');
  print(e.message);
});

//when the app is opened newly

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

if (deepLink != null) {
  // Navigator.pushNamed(context, deepLink.path);

  print("Deep link2= ${deepLink.path}");
}

} I tried navigating from the home page to the Post details page, but it is not working. How do I pass the document snapshot into the dynamic link? Thanks.

QOU
  • 5
  • 2
  • 6
  • Does the error still persist? It seems that you have a typo in your first piece of code, which I suppose is not on your real code. – JMA Jun 03 '21 at 14:43
  • Hi, I was able to resolve it using the explanation here: https://stackoverflow.com/questions/58481840/flutter-how-to-pass-custom-arguments-in-firebase-dynamic-links-for-app-invite – QOU Jun 04 '21 at 20:03
  • I am glad that you managed to solve it, I suggest to post it as an answer to help other users with the same issue! – Jordi Jun 18 '21 at 07:05

0 Answers0