Skip to content

Commit

Permalink
Restore reporting uncaught async errors in the app
Browse files Browse the repository at this point in the history
  • Loading branch information
Abestanis committed Jun 27, 2024
1 parent 08e8b66 commit 3166475
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,29 @@ class _WidgetsBindingObserver extends WidgetsBindingObserver {
}

Future<void> main() async {
// Disabling automatic system UI adjustment, which causes system nav bar
// color to be reverted to black when the bottom player route is being expanded.
//
// Related to https://github.com/flutter/flutter/issues/40590
final WidgetsBinding binding = WidgetsFlutterBinding.ensureInitialized();
binding.renderView.automaticSystemUiAdjustment = false;
await NFPrefs.initialize();

await Firebase.initializeApp();
if (kDebugMode) {
FirebaseFunctions.instance.useFunctionsEmulator('http://localhost/', 5001);

// Force disable Crashlytics collection while doing every day development.
// Temporarily toggle this to true if you want to test crash reporting in your app.
await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(false);
}

Isolate.current.addErrorListener(RawReceivePort((pair) async {
final List<dynamic> errorAndStacktrace = pair;
await reportError(errorAndStacktrace.first, errorAndStacktrace.last);
}).sendPort);
FlutterError.onError = reportFlutterError;
runZonedGuarded(() async {
// Disabling automatic system UI adjustment, which causes system nav bar
// color to be reverted to black when the bottom player route is being expanded.
//
// Related to https://github.com/flutter/flutter/issues/40590
final WidgetsBinding binding = WidgetsFlutterBinding.ensureInitialized();
binding.renderView.automaticSystemUiAdjustment = false;
await NFPrefs.initialize();

await Firebase.initializeApp();
if (kDebugMode) {
FirebaseFunctions.instance.useFunctionsEmulator('http://localhost/', 5001);

// Force disable Crashlytics collection while doing every day development.
// Temporarily toggle this to true if you want to test crash reporting in your app.
await FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(false);
}

try {
Isolate.current.addErrorListener(RawReceivePort((pair) async {
final List<dynamic> errorAndStacktrace = pair;
await reportError(errorAndStacktrace.first, errorAndStacktrace.last);
}).sendPort);
FlutterError.onError = reportFlutterError;
WidgetsBinding.instance.addObserver(_WidgetsBindingObserver());

await DeviceInfoControl.instance.init();
Expand All @@ -98,9 +97,7 @@ Future<void> main() async {
await Permissions.instance.init();
await ContentControl.instance.init();
runApp(const ProviderScope(child: App()));
} catch (error, stacktrace) {
await reportError(error, stacktrace);
}
}, reportError);
}

class App extends StatefulWidget {
Expand Down

0 comments on commit 3166475

Please sign in to comment.