flutter的firebase动态链接在创建链接时会自动删除自定义Queryparameters

发布于 2025-01-21 16:34:32 字数 3037 浏览 0 评论 0原文

大家好,我在从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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心是晴朗的。 2025-01-28 16:34:32

查询参数应在链接中(目标应用程序将打开的链接),而不是uriprefix(应用程序的域URI前缀):

link: Uri.parse("https://xyz.page.link/product?prdt=$slug"),
uriPrefix:"https://xyz.page.link",

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):

link: Uri.parse("https://xyz.page.link/product?prdt=$slug"),
uriPrefix:"https://xyz.page.link",
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文