Issue
I am creating custom dynamic link as given below:
Future<String> generateDynamicLink(
String pid, String imgurl, String title, String description) async {
final DynamicLinkParameters parameters = DynamicLinkParameters(
uriPrefix: uriPrefix,
link: Uri.parse(
uriPrefix+'/pd?pid=$pid',
),
androidParameters: AndroidParameters(
packageName: 'com.test',
minimumVersion: 0,
),
socialMetaTagParameters: SocialMetaTagParameters(
description: description,
imageUrl: Uri.parse(
imgurl,
),
title: title,
),
dynamicLinkParametersOptions: DynamicLinkParametersOptions(
shortDynamicLinkPathLength: ShortDynamicLinkPathLength.unguessable,
),
);
Uri url = await parameters.buildUrl();
ShortDynamicLink shortenedLink = await DynamicLinkParameters.shortenUrl(
url,
DynamicLinkParametersOptions(
shortDynamicLinkPathLength: ShortDynamicLinkPathLength.unguessable),
);
return shortenedLink.shortUrl.toString();
}
And handling the receiving part by calling the fetchLinkData (see below) inside the initState of my home page
void fetchLinkData(BuildContext context) async {
var link = await FirebaseDynamicLinks.instance.getInitialLink();
handleLinkData(link, context);
FirebaseDynamicLinks.instance.onLink(
onSuccess: (PendingDynamicLinkData dynamicLink) async {
handleLinkData(dynamicLink, context);
},
onError: (OnLinkErrorException error) async {
print(error.message);
},
);
}
void handleLinkData(PendingDynamicLinkData data, BuildContext context) async {
final Uri uri = data?.link;
if (uri != null) {
final queryParams = uri.queryParameters;
if (queryParams.keys.contains("pid")) {
String pid = queryParams["pid"];
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ProductScreen(id: pid),
),
);
}
}
}
Now my problem is, On emulator everything works as expected and when the dynamic link is opened it navigates to the correct page but when I try on my android device only the app is opened.
Solution
If anyone else is having the same problem, removing the intent filter solved the problem for me.
Answered By - Ayush Pratap Singh
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.