0

My Use Case:

Users in my app can create lists of items. I want the users to be able to share a link to one of their lists.

I want individuals who click the shared link to see the list of items in a web browser and not need the app installed.

Create the Dynamic Link

The first thing I need to do is create a dynamic link for a user to share. I struggled with this at first and then looked at this question here: Flutter - How to pass custom arguments in firebase dynamic links for app invite feature?

After looking at that I build my own class like so:

class PackDynamicLinkService {
  Future<Uri> createDynamicLink({required String packID}) async {
    final DynamicLinkParameters parameters = DynamicLinkParameters(
      // This should match firebase but without the username query param
      uriPrefix: 'ttps://appName.app/p',
      // This can be whatever you want for the uri, https://yourapp.com/groupinvite?username=$userName
      link: Uri.parse('https://appName.app/p?pack=$packID'),
      androidParameters: const AndroidParameters(
        packageName: 'com.test.demo',
        minimumVersion: 1,
      ),
      iosParameters: const IOSParameters(
        bundleId: 'com.test.demo',
        minimumVersion: '1',
        appStoreId: '',
      ),
    );

    final dynamicLink = await FirebaseDynamicLinks.instance.buildShortLink(
      parameters,
      shortLinkType: ShortDynamicLinkType.unguessable,
    );
    return dynamicLink.shortUrl;
  }
}

I then called that function in my app and I am able to get a URL that looks like this: https://appName.app/p?pack=lVeSBUHoLX52zPqAiB9A

So far so good. Now I just need to click the link and read the parameter $packID that I passed to it inside my web app. Then I can route them to the correct view and display the list.

Processing Dynamic Link

in my marin.dart I tried to retrieve the params with:

//get link stuff
  final PendingDynamicLinkData? initialLink =
      await FirebaseDynamicLinks.instance.getInitialLink();
  if (initialLink != null) {
    final Uri fullLink = initialLink.link;
    print(fullLink.queryParameters['pack']);
  }

but when I upload to firebase hosting to see if this code works for testing, I get this error:

Uncaught MissingPluginException(No implementation found for method FirebaseDynamicLinks#getInitialLink on channel plugins.flutter.io/firebase_dynamic_links)

After doing some more research it seems that firebase_dynamic_links package may not be available for web? So does that mean my original use case is not possible with flutter at this time?

Ten Digit Grid
  • 1,315
  • 4
  • 22
  • 43

1 Answers1

-1

You would want to take the link received and parse it using something like:

var PendingDynamicLinkData? initialLink =
      await FirebaseDynamicLinks.instance.getInitialLink();

if (kIsWeb) {
  String link = Uri.base;

  initialLink = await 
  FirebaseDynamicLinks.instance.getDynamicLink(Uri.parse(link));
}

if (initialLink != null) {
  final Uri fullLink = initialLink.link;
  print(fullLink.queryParameters['pack']);
} 

Here, we are checking if its a web app and then we can parse the dynamic link and get the info for it. We just check for the Uri that was used in our web app.

Alexander N.
  • 1,458
  • 14
  • 25
  • what does this line do, if you are resetting initialLink a few lines later: var PendingDynamicLinkData? initialLink = await FirebaseDynamicLinks.instance.getInitialLink(); – Ten Digit Grid Nov 15 '22 at 14:23
  • Also I dont think this solves my original problem that package:firebase_dynamic_links is not available for web. This would still crash on web no? SInce that package isnt available for web? – Ten Digit Grid Nov 15 '22 at 14:26
  • 1
    The if (kIsWeb) checks that the app is running in a browser and then handles the dynamic link. Ahh I did not realize that the package was not available on the web – Alexander N. Nov 15 '22 at 15:01
  • firebase dynamic link won't support to flutter web – Balaji Jan 17 '23 at 14:16