Vid*_*rom 9 dart firebase flutter firebase-dynamic-links
如何从flutter中的firebase动态链接接收参数?
我创建了一个短网址:
这指向
但我想添加一个 url 查询参数,如:
https://example.com/view-product?id=56
请注意,“56”是可变的,并且在应用程序流程中动态变化。我无法接收这个“id”参数。
在浏览器上,我尝试输入https://subdomain.example.com/product?id=56
我收到了链接:https : //example.com/view-product
FirebaseDynamicLinks.instance.onLink(
onSuccess: (PendingDynamicLinkData dynamicLink) async {
final Uri deepLink = dynamicLink?.link;
showModalBottomSheet(context: context, builder: (context){
return Container(
height: 100.0,
child: Text(deepLink.toString()),
);
});
if (deepLink != null) {
debugPrint("Link found on line: "+deepLink.queryParameters.toString());
}
}, onError: (OnLinkErrorException e) async {
print('onLinkError');
print(e.message);
});
Run Code Online (Sandbox Code Playgroud)
Vid*_*rom 22
我终于想通了!
我在这里完全理解这个概念是错误的。
到目前为止,有 4 种方法可以创建动态链接。
1) Firebase Console
2) Manually
3) Rest API
4) Dynamic Link Builder API on iOS and Android
Run Code Online (Sandbox Code Playgroud)
我在这里做错的是,我从 firebase 控制台创建了https://subdomain.example.com/product一个动态链接,并针对手动创建的链接对其进行了测试。
第二种方法(手动)更强大,您需要从您的网站链接中链接动态内容。
上面提到的是创建动态链接的标准手动程序。
让我们分解上面的链接,让它看起来不那么可怕:
https://your_subdomain.page.link ==> 这只是您在 firebase 控制台上注册的子域。在我们的例子中是https://subdomain.example.com
link=your_deep_link ==> your_deep_link 基本上是您的深层链接(您要打开的链接存在于您的服务器上,它可以包含您需要的所有参数)。在我们的例子中是https://example.com/view-product?id=56。但请注意,此链接将嵌入到 url 中,因此需要先对其进行 urlencoded。为此目的使用任何 url 编码器。生成的编码字符串变为
https%3A%2F%2Fexample.com%2Fview-product%3Fid%3D56
apn=package_name ==> IOS 或 Android 各自的包名
[&amv=minimum_version] ==> "[]" 将此表示为可选参数。此参数是您的应用程序应响应此动态链接的最小应用程序版本号(如果您希望所有版本都支持,则为 0)
[&afl=fallback_link] ==> ==> "[]" 将此表示为可选参数。这是后备 url,也是 url 编码的。可能是您的 android play 商店链接。
所以我们最终的动态链接看起来像:
| 归档时间: |
|
| 查看次数: |
5124 次 |
| 最近记录: |