Files
flutter-samples/packages/stream_chat_v1/lib/main.dart
T
2023-05-05 13:39:12 -07:00

66 lines
2.0 KiB
Dart

import 'dart:async';
import 'package:example/utils/app_config.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:example/app.dart';
import 'firebase_options.dart';
@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
print("#firebase; PN_2 ");
await Firebase.initializeApp();
// If you're going to use other Firebase services in the background, such as Firestore,
// make sure you call `initializeApp` before using other Firebase services.
print('[setupPushNotifications] newMessage: ${message.toMap()}');
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
print("#firebase; PN_1");
await Firebase.initializeApp();
Firebase.apps.forEach((it) {
print("#firebase; app: $it");
});
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
/// Captures errors reported by the Flutter framework.
FlutterError.onError = (FlutterErrorDetails details) {
if (kDebugMode) {
// In development mode, simply print to console.
FlutterError.dumpErrorToConsole(details);
} else {
// In production mode, report to the application zone to report to sentry.
Zone.current.handleUncaughtError(details.exception, details.stack!);
}
};
Future<void> reportError(dynamic error, StackTrace stackTrace) async {
// Print the exception to the console.
if (kDebugMode) {
// Print the full stacktrace in debug mode.
print(stackTrace);
return;
} else {
// Send the Exception and Stacktrace to sentry in Production mode.
await Sentry.captureException(error, stackTrace: stackTrace);
}
}
runZonedGuarded(
() async {
await SentryFlutter.init(
(options) => options.dsn = sentryDsn,
);
runApp(const StreamChatSampleApp());
},
reportError,
);
}