Flutter web error pluginConstants['isCrashlyticsCollectionEnabled'] != null

584

Replace:

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

with:

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

Calling setCrashlytics() will produce the error because Crashlytics is not supported on web.

Share:
584
Rohmatul Laily
Author by

Rohmatul Laily

Updated on November 23, 2022

Comments

  • Rohmatul Laily
    Rohmatul Laily over 1 year

    I have a code like below, initially I used this code for iOS and Android applications, now I want the application to run on the web, but when I run I get this error

    runZonedGuarded: Caught error in my root zone. pluginConstants['isCrashlyticsCollectionEnabled'] != null is not true

    someone suggested using kisweb, I've used it, but I still get the same error, please help, here's my code

    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>
    
  • dogeen
    dogeen about 2 years
    The question mentions a crash on web. Instructions provided in this answer would only affect IOS.