如何在Flutter中从Firebase动态链接获取参数

时间:2020-03-16 12:25:09

标签: firebase flutter firebase-dynamic-links

我在firebase动态链接中接收参数时遇到问题。 我需要从动态链接中获取 UserId ,但是我只能 https://albyrak.page.link/referral

我如何创建动态链接

 Future<Uri> createDynamicLink({@required String userId}) async {
    final DynamicLinkParameters parameters = DynamicLinkParameters(
      uriPrefix: 'https://albyrak.page.link/referral',
      link: Uri.parse('?userId=$userId'),
      androidParameters: AndroidParameters(
        packageName: 'albyrak.cvit',
        minimumVersion: 1,
      ),
      iosParameters: IosParameters(
        bundleId: 'com.cvit.albyrak',
        minimumVersion: '1',
        appStoreId: '1479999546',
      ),
    );

    final link = await parameters.buildUrl();
   //https://albyrak.page.link/referral?amv=1&apn=albyrak.cvit&ibi=com.cvit.albyrak&imv=1&isi=1479999546&link=https%3A%2F%2Falbyrak.page.link%2Freferral%2F%3FuserId%3D42yGqAKiZHR2lJOpZtDsSHgL0DB2
    return link;
  }

我如何接收动态链接

 void initDynamicLinks() async {
    final PendingDynamicLinkData data =
        await FirebaseDynamicLinks.instance.getInitialLink();
    final Uri deepLink = data?.link;
    print(deepLink);

    FirebaseDynamicLinks.instance.onLink(
        onSuccess: (PendingDynamicLinkData dynamicLink) async {
      final Uri deepLink = dynamicLink?.link;
      print(deepLink); // <- The outbut is always "https://albyrak.page.link/referral"
      if (deepLink != null) {
        print(deepLink.queryParameters['userId']); // <- This is always null
      }
    }, onError: (OnLinkErrorException e) async {
      print('onLinkError');
      print(e.message);
    });
  }

0 个答案:

没有答案