【问题标题】:Flutter - Unable to use dynamic links in flutter webFlutter - 无法在flutter web中使用动态链接
【发布时间】:2021-08-15 00:59:42
【问题描述】:

我无法在 Flutter Web 上使用 Firebase 动态链接插件。

当我试图创建一个深层链接时,它给出了错误:

Error: MissingPluginException(No implementation found for method DynamicLinkParameters#buildShortLink on channel plugins.flutter.io/firebase_dynamic_links)
    at Object.throw_ [as throw] (http://localhost:49242/dart_sdk.js:5344:11)
    at MethodChannel._invokeMethod (http://localhost:49242/packages/flutter/src/services/system_channels.dart.lib.js:962:21)
    at _invokeMethod.next (<anonymous>)
    at http://localhost:49242/dart_sdk.js:39201:33
    at _RootZone.runUnary (http://localhost:49242/dart_sdk.js:39058:58)
    at _FutureListener.thenAwait.handleValue (http://localhost:49242/dart_sdk.js:34044:29)
    at handleValueCallback (http://localhost:49242/dart_sdk.js:34604:49)
    at Function._propagateToListeners (http://localhost:49242/dart_sdk.js:34642:17)
    at _Future.new.[_completeWithValue] (http://localhost:49242/dart_sdk.js:34484:23)
    at async._AsyncCallbackEntry.new.callback (http://localhost:49242/dart_sdk.js:34507:35)
    at Object._microtaskLoop (http://localhost:49242/dart_sdk.js:39345:13)
    at _startMicrotaskLoop (http://localhost:49242/dart_sdk.js:39351:13)
    at http://localhost:49242/dart_sdk.js:34858:9

在初始化状态下尝试处理动态链接时也会出现类似的类型错误。

如何解决这个问题?我至少需要在我的 Flutter Web 项目中创建一个动态链接。

【问题讨论】:

    标签: firebase flutter dart flutter-web firebase-dynamic-links


    【解决方案1】:

    您可以使用此guide 对 Dynamiclinks API 的发布请求构建动态链接,如下所示:

        Future<String>? buildDynamicLinks(
          {theID, theTitle, theDescription, companyName, theCategory}) async {
        var  urlToReturn;
        final String postUrl =
            'https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=*****YourApiKey******';
    
        String theUrl =
            "https://sample.page.link/?isi=3223&ibi=app.sample.example&imv=1.0.1&link=https%3A%2F%2Fwww.yourWebsite.net%2F${theCategory ?? 'id'}%2F$theID&si=**imgUrl**&sd=$companyName  -  $theDescription&amv=1&st=$theTitle&apn=app.example.sample";
    
        await http.post(Uri.tryParse(postUrl)!, body: {
          'longDynamicLink': theUrl,
        }).then(
          (http.Response response) {
            final int statusCode = response.statusCode;
    
            if (statusCode < 200 || statusCode > 400 || response == null) {
              throw new Exception("Error while fetching data");
            }
            var decoded = json.decode(response.body);
            urlToReturn = decoded['shortLink'];
            return decoded['shortLink'];
          },
        ).catchError((e) => debugPrint('error $e'));
        return urlToReturn;
      }
    

    【讨论】:

      【解决方案2】:

      目前 web 平台不支持firebase_dynamic_links 插件。

      显示的错误信息MissingPluginException(No implementation found for method DynamicLinkParameters...)表示。

      pub.dev 中可用的所有软件包都有一些tags,表示支持的平台。

      【讨论】:

        猜你喜欢
        • 2021-06-29
        • 2021-06-24
        • 2019-10-28
        • 2021-04-02
        • 2020-06-10
        • 2021-12-15
        • 2019-10-21
        • 2020-04-26
        • 2021-10-29
        相关资源
        最近更新 更多