Search code examples
flutterdartdeep-linkingfirebase-dynamic-linksplatform

Flutter dynamic links how to set up other platforms fall back link?


I have used dynamic links in my flutter app and I create the link manually through codes through dynamic links package I have configured my link to open play store when not installed on Android and redirect to a particular website in ios and iPad but how to give a fall back link for other platforms ?


Solution

  • You can manually add ofl (or afl, or ifl) to the long Uri string and use it directly, or even build a short URL from it.

    This code creates a DynamicLinkParameters variable parameters using the DynamicLinkParameters() constructor inside an async function, then uses it to create a short link that falls back to https://example.com on desktop:

    final DynamicLinkParameters parameters = DynamicLinkParameters(
    // constructor arguments
    );
    
    final Uri longLink = await parameters.buildUrl();
    final ShortDynamicLink shortDynamicLink = await DynamicLinkParameters.shortenUrl(Uri.parse(longLink.toString() + "&ofl=https://example.com"));
    final Uri dynamicLinkShortUrl = shortDynamicLink.shortUrl;