|
| 1 | +import 'dart:async'; |
| 2 | + |
1 | 3 | import 'package:firebase_core/firebase_core.dart'; |
2 | 4 | import 'package:firebase_crashlytics/firebase_crashlytics.dart'; |
3 | 5 | import 'package:firebase_messaging/firebase_messaging.dart'; |
| 6 | +import 'package:flutter/foundation.dart'; |
4 | 7 | import 'package:flutter/material.dart'; |
| 8 | +import 'package:sentry_flutter/sentry_flutter.dart'; |
| 9 | + |
| 10 | +import 'data/config/config.dart'; |
5 | 11 |
|
6 | 12 | Future<void> main() async { |
7 | | - // Necessary if you intend to initialize in `main`. |
8 | | - WidgetsFlutterBinding.ensureInitialized(); |
9 | | - |
10 | | - // Firebase section |
11 | | - await Firebase.initializeApp(); |
12 | | - FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true); |
13 | | - FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError; |
14 | | - FirebaseMessaging.onMessage.listen( |
15 | | - (message) { |
16 | | - final notification = message.notification; |
17 | | - if (notification != null) { |
18 | | - debugPrint( |
19 | | - 'title: ${notification.title} \t body: ${notification.body}'); |
20 | | - } |
21 | | - }, |
22 | | - ); |
23 | | - FirebaseMessaging.onMessageOpenedApp.listen( |
24 | | - (message) { |
25 | | - final notification = message.notification; |
26 | | - if (notification != null) { |
27 | | - debugPrint( |
28 | | - 'title: ${notification.title} \t body: ${notification.body}', |
29 | | - ); |
30 | | - } |
| 13 | + runZonedGuarded( |
| 14 | + () async { |
| 15 | + // Necessary if you intend to initialize in an async function. |
| 16 | + WidgetsFlutterBinding.ensureInitialized(); |
| 17 | + |
| 18 | + // Firebase section |
| 19 | + await Firebase.initializeApp(); |
| 20 | + FirebaseCrashlytics.instance.setCrashlyticsCollectionEnabled(true); |
| 21 | + FlutterError.onError = FirebaseCrashlytics.instance.recordFlutterError; |
| 22 | + FirebaseMessaging.onMessage.listen( |
| 23 | + (message) { |
| 24 | + final notification = message.notification; |
| 25 | + if (notification != null) { |
| 26 | + debugPrint( |
| 27 | + 'title: ${notification.title} \t body: ${notification.body}'); |
| 28 | + } |
| 29 | + }, |
| 30 | + ); |
| 31 | + FirebaseMessaging.onMessageOpenedApp.listen( |
| 32 | + (message) { |
| 33 | + final notification = message.notification; |
| 34 | + if (notification != null) { |
| 35 | + debugPrint( |
| 36 | + 'title: ${notification.title} \t body: ${notification.body}', |
| 37 | + ); |
| 38 | + } |
| 39 | + }, |
| 40 | + ); |
| 41 | + |
| 42 | + // Sentry section |
| 43 | + await SentryFlutter.init( |
| 44 | + (SentryFlutterOptions options) { |
| 45 | + options |
| 46 | + ..dsn = Environment.sentryDSN |
| 47 | + ..tracesSampleRate = 1.0 |
| 48 | + ..reportPackages = true |
| 49 | + ..debug = kDebugMode; |
| 50 | + }, |
| 51 | + ); |
| 52 | + |
| 53 | + runApp(const Codephile()); |
31 | 54 | }, |
| 55 | + (Object exception, StackTrace stack) async => Sentry.captureException( |
| 56 | + exception, |
| 57 | + stackTrace: stack, |
| 58 | + ), |
32 | 59 | ); |
33 | | - |
34 | | - runApp(const Codephile()); |
35 | 60 | } |
36 | 61 |
|
37 | 62 | class Codephile extends StatelessWidget { |
|
0 commit comments