Flutter - Dynamic links send user to a website if not android

992

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;
Share:
992
Jagadish
Author by

Jagadish

I develop cross-platform apps and websites. I have developed 3 android apps and published them on the Play Store, one of them is Just Meet with thousands of daily users. I have been coding from class 8 and have gained 3 years of experience with flutter language and android app development. I am a student of class 10 presently, I study all day and code at night. I believe in developing free or low-cost high-quality premium apps available to all the people of India. Recently I developed Just Meet, a video conferencing app that gives complete privacy, is secured and end to end encrypted, uses lesser data and battery, and works well in bad network areas like a charm and the best thing is it has no restriction on the number of participants or meeting duration and that too completely free! As I code alone it took me about 3 months to complete the initial release of it. It has a lot of features, some are new and very helpful. I believe this app will help a lot of people save their money and continue their meetings even in the worst network peacefully without having the tension of their user data! I have experience working on Firebase, Adsense, Admob, Facebook Audience Network, Unity Ads, etc, and also little in Python, Java, JavaScript, HTML, CSS, AIML. When am not studying and frustrated with bugs and errors usually spend my time working out on my muscles, painting, and playing with my pet dog "Ani".

Updated on December 30, 2022

Comments

  • Jagadish
    Jagadish over 1 year

    I am using the dynamic links plugin to create a link, I want that when user clicks on the link if her or she is not on android then he or she must be sent to a website as I have only an android app, but if on android then he must be sent to the app. How to get the desired result? there is no method in the plugin for fallback links for different os. I am creating a dynamic link through code and not in the firebase console.

    according to firebase while constructing dynamic links manually we can give Other platform parameters as ofl:

    ofl: The link to open on platforms besides Android and iOS. This is useful to specify a different behavior on a desktop, like displaying a full web page of the app content/payload (as specified by param link) with another dynamic link to install the app.

    it also has a ifl, i.e if app is not installed on ios:

    ifl: The link to open when the app isn't installed. Specify this to do something other than install your app from the App Store when the app isn't installed, such as open the mobile web version of the content, or display a promotional page for your app.

    But can't find both ifl and ofl feature in the flutter firebase dynamic links plugin.

  • Jagadish
    Jagadish almost 3 years
    No u didn't understand it, I want that if the link is clicked on any other os such as windows, os except ios, then the link should redirect the user to a website and if android then opens the app. The code which you have given can only be applied inside the app once it receives the link but i don't have an app for ios and windows so the link needs to decide without the help of tghe app.
  • Jaime Ortiz
    Jaime Ortiz almost 3 years
    Oh i understand now, mb. I'll come back with an answer if i figure it out.
  • Jagadish
    Jagadish almost 3 years
    yes, i have edited the question, check it out
  • Jagadish
    Jagadish almost 3 years
    Great you answered what I wanted but, can you show how to use ofl ifl in parameters? When I try there I no such thing in the plugin....but your logic matches with what I thought of doing but couldn't. Please write the complete code you have left the main part.
  • shadysamir
    shadysamir almost 3 years
    @Jagadish The thing is, you can't. It is not supported yet in parameters that builds a URL for you. Hence the workaround. They are only available if you build the URL manually. So we get parameters to do all the work for us then add this in the end.
  • shadysamir
    shadysamir almost 3 years
    @Jagadish the only supported options in DynamicLinkParameters now are fallback on iOS and fallback on Android, which takes you to a URL instead of a store if the app is not installed on either platforms.
  • Jagadish
    Jagadish almost 3 years
    ok if I don't have an Ios app then can I give the fallback link for Ios?
  • shadysamir
    shadysamir almost 3 years
    Yes by passing a IosParameters object with fallbackUrl argument to the iosParameters argument in DynamicLinkParameters pub.dev/documentation/firebase_dynamic_links/latest/…
  • Jagadish
    Jagadish almost 3 years
    ok, so what do I write i place of Ios app ID?
  • shadysamir
    shadysamir almost 3 years
    You leave it empty. It's nullable.
  • Jagadish
    Jagadish almost 3 years
    Thanks! Lemme try it and then I will tell u
  • Suresh Sharma
    Suresh Sharma over 2 years
    Does this work? I tried but no luck. a sample that I tried is appname.page.link/onboarding_page/… What am I missing here?