How can we handle deep links in flutter with Get X for go to Custom pages of the application?

546

Do the page routing in your app, when you process the deeplink.

In my apps, I usually use uni_links (https://pub.dev/packages/uni_links) and in my main.dart, I have something like this:

StreamSubscription<String> _subUniLinks;

@override
initState() {
    super.initState();
    // universal link setup
    initUniLinks();
}

Future<void> initUniLinks() async {
    try {
        final String initialLink = await getInitialLink();
        await processLink(initialLink);
    } on PlatformException {
    }
    _subUniLinks = linkStream.listen(processLink, onError: (err) {});
}

processLink(String link) async {
    // parse link and decide what to do:
    // - use setState
    // - or use Navigator.pushReplacement
    // - or whatever mechanism if you have in your app for routing to a page
}

@override
dispose() {
    if (_subUniLinks != null) _subUniLinks.cancel();
    super.dispose();
}


Share:
546
Huseyn
Author by

Huseyn

I love flutter

Updated on December 31, 2022

Comments

  • Huseyn
    Huseyn over 1 year

    How can we handle deep links in flutter with Get X for go to Custom pages of the application ?

    By default, by adding the desired address to the Android Manifest file:

            <meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="http" android:host="flutterbooksample.com" />
                <data android:scheme="https" android:host="flutterbooksample.com"/>
            </intent-filter>
    

    when the application opens, the main page of application will be displayed to us.

    I am looking to implement this I can direct the user to any page of the application that is needed. A practical example is to pay on the web page and return to the application. When we return, we should show the user a message about the status of the payment, not direct the user to the first page of the application.

    • Infaz
      Infaz over 2 years
      Did you find a solution for this?
    • Huseyn
      Huseyn over 2 years
      Unfortunately no @Infaz
    • Infaz
      Infaz over 2 years
      Ok, Thanks for the response
    • Huseyn
      Huseyn over 2 years
      Hi, @Infaz here is an answer.
    • Infaz
      Infaz over 2 years
      Thanks, @Huseyn, I will try this out.
  • Mijanur Rahaman
    Mijanur Rahaman about 2 years
    where this linkStream come from ?