【问题标题】:Flutter web error pluginConstants['isCrashlyticsCollectionEnabled'] != nullFlutter web 错误 pluginConstants['isCrashlyticsCollectionEnabled'] != null
【发布时间】:2021-10-11 01:05:23
【问题描述】:

我有一个类似下面的代码,最初我将此代码用于 iOS 和 Android 应用程序,现在我希望应用程序在网络上运行,但是当我运行时出现此错误

runZonedGuarded:在我的根区域中发现错误。 pluginConstants['isCrashlyticsCollectionEnabled'] != null 不正确

有人建议使用 kisweb,我用过,但还是出现同样的错误,请帮忙,这是我的代码

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  if(!kIsWeb) {
    await Firebase.initializeApp();
  }

  runZonedGuarded(() async {
    if (kDebugMode) {
    await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(false);
    }else{
    await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
    }
    runApp(App(
      authenticationRepository: AuthenticationRepository(),
      userRepository: UserRepository(),
    ));
  }, (error, stackTrace) async {
    print('runZonedGuarded: Caught error in my root zone. $error');
  });
}

index.html

<!DOCTYPE html>
<html>
<head>
  <!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-messaging.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.6.1/firebase-firestore.js"></script>


<!-- TODO: Add SDKs for Firebase products that you want to use
     https://firebase.google.com/docs/web/setup#available-libraries -->

<script>
  // Your web app's Firebase configuration
  var firebaseConfig = {
    apiKey: "xxx",
    authDomain: "xxx,
    databaseURL: "xxx",
    projectId: "xxxx",
    storageBucket: "xxx,
    messagingSenderId: "xxx",
    appId: "xxxx"
  };
  // Initialize Firebase
  firebase.initializeApp(firebaseConfig);
  firebase.analytics();
</script>
  <!--
    If you are serving your web app in a path other than the root, change the
    href value below to reflect the base path you are serving from.

    The path provided below has to start and end with a slash "/" in order for
    it to work correctly.

    Fore more details:
    * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
  -->
  <base href="/">

  <meta charset="UTF-8">
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">
  <meta name="description" content="A new Flutter project.">

  <!-- iOS meta tags & icons -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-title" content="cashbac_biz">
  <link rel="apple-touch-icon" href="icons/Icon-192.png">

  <!-- Favicon -->
  <link rel="icon" type="image/png" href="favicon.png"/>

  <title>cashbac_biz</title>
  <link rel="manifest" href="manifest.json">

</head>
<body>
  <!-- This script installs service_worker.js to provide PWA functionality to
       application. For more information, see:
       https://developers.google.com/web/fundamentals/primers/service-workers -->
  <script>
    if ('serviceWorker' in navigator) {
      window.addEventListener('flutter-first-frame', function () {
        navigator.serviceWorker.register('flutter_service_worker.js');
      });
    }
  </script>  
  <script src="main.dart.js" type="application/javascript"></script>
</body>
</html>

【问题讨论】:

    标签: flutter web flutter-web


    【解决方案1】:

    我遇到了同样的问题。我按照安装说明here 解决了这个问题,特别是这些步骤将构建阶段添加到 XCode:

    1. 在 Xcode 中,从项目导航中选择 Runner。
    2. 选择 Build Phases 选项卡,然后单击 + > New Run Script Phase。
    3. 将 ${PODS_ROOT}/FirebaseCrashlytics/run 添加到“键入脚本...”文本框中。
    4. (可选)您还可以将应用的构建 Info.plist 位置提供给构建阶段的 Input Files 字段:例如: $(BUILT_PRODUCTS_DIR)/$(INFOPLIST_PATH)

    【讨论】:

      【解决方案2】:

      替换:

       if (kDebugMode) {
          await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(false);
      } else {
          await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
      }
      

      与:

      if (!kIsWeb) {
        if (kDebugMode) {
          await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(false);
        } else {
          await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true);
        }
      }
      

      调用 setCrashlytics() 会产生错误,因为网络不支持 Crashlytics。

      【讨论】:

        猜你喜欢
        • 2022-01-07
        • 2020-09-17
        • 2021-01-28
        • 2020-07-05
        • 2019-03-21
        • 2020-01-06
        • 2021-11-25
        • 2021-12-27
        • 2021-04-12
        相关资源
        最近更新 更多