From 1c7ece163a1be490ee6f73eec4e157de60aec239 Mon Sep 17 00:00:00 2001 From: RainVisitor Date: Thu, 10 Sep 2020 23:20:02 +0800 Subject: [PATCH] Fix firebase crashlytics record error --- lib/main.dart | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 117e24e..0c26680 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,7 +4,6 @@ import 'dart:io'; import 'package:ap_common/utils/preferences.dart'; import 'package:ap_common_firebase/utils/firebase_utils.dart'; import 'package:firebase_crashlytics/firebase_crashlytics.dart'; -import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:nsysu_ap/config/constants.dart'; @@ -21,7 +20,11 @@ void main() async { await Firebase.initializeApp(); if (FirebaseUtils.isSupportCrashlytics) { await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true); - FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError; - } - runApp(MyApp()); + runZonedGuarded(() { + runApp(MyApp()); + }, (error, stackTrace) { + FirebaseCrashlytics.instance.recordError(error, stackTrace); + }); + } else + runApp(MyApp()); }