How can I send parameters to deep links in Flutter?
Asked Answered
I

2

6

I've managed to set up a deep link on Flutter for my app (currently only on android), here is the intent filter in the AndroidManifest.xml file to set up the deep link (using example host name and prefix):

<intent-filter>
    <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="example.com" android:pathPrefix="/prefix"/>
</intent-filter>

This works, whenever I access http://example.com/prefix on my phone, it suggests to open my app.

Now, I want to be able to pass in parameters to the deep link, maybe a URL parameter like http://example.com/prefix?code=abc123. So I can read it from my Flutter app like getParam('code') returns abc123 for example.

Is this possible?

Informality answered 10/12, 2020 at 23:41 Comment(2)
Yes, this is possible. I suggest you read about uni_links package in flutter.Yung
Thank you so much, been looking at so many articles that got me nowhere. Need to start looking into the docs more often. Thank you again! :)Informality
H
1

If you need more advance Deep linking experience with specific domain name, Google firebase has a great product named Dynamic links and it is free.

There is an official package for Flutter to use as firebase_dynamic_links.

Dynamic Links eliminates DeepLink weaknesses. With Dynamic Links, you treat on all platforms such as Android, iOS and web in a similar way. It seamlessly transits users from your mobile website to the equivalent content within your app (if the user has not installed your app on her/his device, the content would be shown after app installation). Furthermore, you can see the log of a Dynamic Link in the Firebase console. Another feature is to find out where the user clicked on the link.more info

Histochemistry answered 11/12, 2020 at 2:26 Comment(4)
Thank you for the information. Dynamic Links sound interesting, will look into them.Informality
Were you able to get data from clicked web link using Firebase dynamic links?Infinity
really stupid question, do you need to be using firebase db to use dynamic links or are they unrelated?Hogarth
I think Firebase Dynamic Links is not useful for including parameters in URL.Ryannryazan
A
0

Use go router for your deep linking needs. It can handle two kind of scenarios.

You can use ":" prefix to mark any segment as parameter. Define it in GoRoute like this:

GoRoute(
  path: '/search/:keyword',
  builder: (context, state) => const UserScreen(id:state.pathParameters['keyword']),
),

If you use classic parameters instead of segments, where you put ?query=keyword at the end of url, you can define GoRoute like this:

GoRoute(
  path: '/search',
  builder: (context, state) => const UsersScreen(filter: state.uri.queryParameters['keyword']),
),
Aliphatic answered 22/3 at 9:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.