I have setup deeplinking on my flutter application but I'm having trouble in being able to pass and use a parameter. Normally, the deeplink works for a predefined named route, say I press a link https://domain/signup - this will redirect the user to the signup page on my Flutter app. But the issue here is, I'm not able to pass a parameter so that I can make my page more dynamic - say a user presses on a link https://domain/course/:some-id - I want to redirect the user to that specific course page. I believe I have setup the deeplink correctly - well at least to what I have seen from the flutter docs. I'm using named route and I know it says using router is a preferred way to Here is my AndroidXML file setup
<!-- Deep Links -->
<meta-data
android:name="flutter_deeplinking_enabled"
android:value="true"
/>
<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="scheme"
android:host="domain" />
</intent-filter>
<!-- App Links -->
<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="https"
android:host="domain.com" />
<data
android:scheme="http" />
</intent-filter>
I have made a custom deeplink handler - and its not working how I wanted it to
class DeepLinkHandler {
static Future<void> initUniLinks(BuildContext context) async {
try {
// Get the initial deep link
final initialLink = await getInitialLink();
// Handle the initial deep link if it exists
_handleLink(initialLink, context);
// Listen for incoming deep links
linkStream.listen((String? link) {
_handleLink(link, context);
}, onError: (error) {});
} catch (error) {
throw Exception();
}
}
static void _handleLink(String? link, BuildContext context) {
if (link != null) {
final Uri deepLink = Uri.parse(link);
print('deeplink opened was $deepLink');
// This is where I want to navigate the user to the right page
}
}
static Future<void> openLink(String link) async {
if (await canLaunchUrl(Uri.parse(link))) {
await launchUrl(Uri.parse(link));
}
}
}
How can I route to a specific pages with a certain parameter attached to it.