flutter的firebase动态链接在创建链接时会自动删除自定义Queryparameters
大家好,我在从Firebase Dynamic Link和Flutter中获取参数很难。即使在创建链接时提供值时,它也不会以某种方式显示在动态链接中。谁能帮我解决这个问题?在过去的两天里,我没有任何帮助。
这是代码。
class DynamicLinkService {
String? _linkMessage;
Future<String?> createDynamicLink(bool short, String? slug) async {
final dynamicLinkParams = DynamicLinkParameters(
link: Uri.parse("https://xyz.page.link/"),
uriPrefix: "https://xyz.page.link/product?prdt=$slug",
androidParameters: AndroidParameters(
packageName: "com.example.example",
minimumVersion: 24,
),
iosParameters: IosParameters(
bundleId: "com.example.iosexample",
appStoreId: "13719873",
minimumVersion: "1.0.1",
),
);
Uri? url;
if (short) {
// final dynamicLink =
// await FirebaseDynamicLinks.instance.buildShortLink(dynamicLinkParams);
final dynamicLink = await dynamicLinkParams.buildShortLink();
url = dynamicLink.shortUrl;
} else {
final dynamicLink = await dynamicLinkParams.buildUrl();
// await FirebaseDynamicLinks.instance.buildLink(dynamicLinkParams);
url = dynamicLink;
}
_linkMessage = url.toString();
return _linkMessage;
}
Future<void> initDynamicLink(BuildContext context) async {
FirebaseDynamicLinks.instance.onLink(
onSuccess: (dynamicLink) async {
final Uri? deepLink = dynamicLink?.link;
var isProduct = deepLink?.pathSegments.contains('product');
if (isProduct == true) {
String? slug = deepLink?.queryParameters['prdt'];
print("2Li $slug");
if (deepLink != null) {
if (slug != null || slug != "") {
context.read<ProductController>().saveSlug(slug!).whenComplete(() {
Navigator.of(context).pushNamed("/ProductDetail");
});
}
} else {
return null;
}
} else {
return null;
}
}
);
final PendingDynamicLinkData? data =
await FirebaseDynamicLinks.instance.getInitialLink();
try {
final Uri? deepLink = data?.link;
print("1111111, $deepLink");
var isProduct = deepLink?.pathSegments.contains('product');
if (isProduct == true) {
String? slug = deepLink?.queryParameters['prdt'];
print("2Li $slug");
if (deepLink != null) {
if (slug != null || slug != "") {
context.read<ProductController>().saveSlug(slug!).whenComplete(() {
Navigator.of(context).pushNamed("/ProductDetail");
});
}
} else {
return null;
}
} else {
return null;
}
} catch(e) {
print("No DeepLink Found");
}
}
}
这是正在创建的URL,
https://xyz.page.link/product?amv=24&apn=com.example.example&ibi=com.example.example&imv=1.0.1&isi=1613285148&link=https%3A%2F%2Fxyz.page.link%2F
我尝试了几种方法,但找不到获得Queryparams的方法。
帮助您将不胜感激。
谢谢。
Hello guys I am having trouble with getting parameters from firebase dynamic links and flutter. Even while providing the value at the time of creating links, it is somehow not showing up in the dynamic link. Can anyone help me with the issue? I am stuck for the past two days without any help.
This is the code.
class DynamicLinkService {
String? _linkMessage;
Future<String?> createDynamicLink(bool short, String? slug) async {
final dynamicLinkParams = DynamicLinkParameters(
link: Uri.parse("https://xyz.page.link/"),
uriPrefix: "https://xyz.page.link/product?prdt=$slug",
androidParameters: AndroidParameters(
packageName: "com.example.example",
minimumVersion: 24,
),
iosParameters: IosParameters(
bundleId: "com.example.iosexample",
appStoreId: "13719873",
minimumVersion: "1.0.1",
),
);
Uri? url;
if (short) {
// final dynamicLink =
// await FirebaseDynamicLinks.instance.buildShortLink(dynamicLinkParams);
final dynamicLink = await dynamicLinkParams.buildShortLink();
url = dynamicLink.shortUrl;
} else {
final dynamicLink = await dynamicLinkParams.buildUrl();
// await FirebaseDynamicLinks.instance.buildLink(dynamicLinkParams);
url = dynamicLink;
}
_linkMessage = url.toString();
return _linkMessage;
}
Future<void> initDynamicLink(BuildContext context) async {
FirebaseDynamicLinks.instance.onLink(
onSuccess: (dynamicLink) async {
final Uri? deepLink = dynamicLink?.link;
var isProduct = deepLink?.pathSegments.contains('product');
if (isProduct == true) {
String? slug = deepLink?.queryParameters['prdt'];
print("2Li $slug");
if (deepLink != null) {
if (slug != null || slug != "") {
context.read<ProductController>().saveSlug(slug!).whenComplete(() {
Navigator.of(context).pushNamed("/ProductDetail");
});
}
} else {
return null;
}
} else {
return null;
}
}
);
final PendingDynamicLinkData? data =
await FirebaseDynamicLinks.instance.getInitialLink();
try {
final Uri? deepLink = data?.link;
print("1111111, $deepLink");
var isProduct = deepLink?.pathSegments.contains('product');
if (isProduct == true) {
String? slug = deepLink?.queryParameters['prdt'];
print("2Li $slug");
if (deepLink != null) {
if (slug != null || slug != "") {
context.read<ProductController>().saveSlug(slug!).whenComplete(() {
Navigator.of(context).pushNamed("/ProductDetail");
});
}
} else {
return null;
}
} else {
return null;
}
} catch(e) {
print("No DeepLink Found");
}
}
}
This is the url, which is being created
https://xyz.page.link/product?amv=24&apn=com.example.example&ibi=com.example.example&imv=1.0.1&isi=1613285148&link=https%3A%2F%2Fxyz.page.link%2F
I tried several ways, but couldn't find a way to get the queryparams.
Help would be highly appreciated.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查询参数应在链接中(目标应用程序将打开的链接),而不是uriprefix(应用程序的域URI前缀):
The query parameters should be in the link (The link the target app will open) rather than the uriPrefix (Domain URI Prefix of your App):