Skip to content

Commit 9de6a09

Browse files
committed
conf: Set up Sentry.
1 parent 179127e commit 9de6a09

5 files changed

Lines changed: 140 additions & 28 deletions

File tree

analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ linter:
1212
always_declare_return_types: true
1313
always_put_required_named_parameters_first: true
1414
always_require_non_null_named_parameters: true
15-
always_use_package_imports: true
1615
annotate_overrides: true
1716
avoid_annotating_with_dynamic: true
1817
avoid_bool_literals_in_conditional_expressions: true
@@ -122,6 +121,7 @@ linter:
122121
prefer_mixin: true
123122
prefer_null_aware_method_calls: true
124123
prefer_null_aware_operators: true
124+
prefer_relative_imports: true
125125
prefer_single_quotes: true
126126
prefer_spread_collections: true
127127
prefer_typing_uninitialized_variables: true

lib/data/config/config.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
1+
class Environment {
2+
static const String sentryDSN = String.fromEnvironment('SENTRY_DSN');
3+
}

lib/main.dart

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,62 @@
1+
import 'dart:async';
2+
13
import 'package:firebase_core/firebase_core.dart';
24
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
35
import 'package:firebase_messaging/firebase_messaging.dart';
6+
import 'package:flutter/foundation.dart';
47
import 'package:flutter/material.dart';
8+
import 'package:sentry_flutter/sentry_flutter.dart';
9+
10+
import 'data/config/config.dart';
511

612
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());
3154
},
55+
(Object exception, StackTrace stack) async => Sentry.captureException(
56+
exception,
57+
stackTrace: stack,
58+
),
3259
);
33-
34-
runApp(const Codephile());
3560
}
3661

3762
class Codephile extends StatelessWidget {

pubspec.lock

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,13 @@ packages:
176176
url: "https://pub.dartlang.org"
177177
source: hosted
178178
version: "1.2.0"
179+
ffi:
180+
dependency: transitive
181+
description:
182+
name: ffi
183+
url: "https://pub.dartlang.org"
184+
source: hosted
185+
version: "1.1.2"
179186
file:
180187
dependency: transitive
181188
description:
@@ -331,6 +338,13 @@ packages:
331338
url: "https://pub.dartlang.org"
332339
source: hosted
333340
version: "2.1.0"
341+
http:
342+
dependency: transitive
343+
description:
344+
name: http
345+
url: "https://pub.dartlang.org"
346+
source: hosted
347+
version: "0.13.4"
334348
http_multi_server:
335349
dependency: transitive
336350
description:
@@ -422,6 +436,48 @@ packages:
422436
url: "https://pub.dartlang.org"
423437
source: hosted
424438
version: "2.0.2"
439+
package_info_plus:
440+
dependency: transitive
441+
description:
442+
name: package_info_plus
443+
url: "https://pub.dartlang.org"
444+
source: hosted
445+
version: "1.3.0"
446+
package_info_plus_linux:
447+
dependency: transitive
448+
description:
449+
name: package_info_plus_linux
450+
url: "https://pub.dartlang.org"
451+
source: hosted
452+
version: "1.0.3"
453+
package_info_plus_macos:
454+
dependency: transitive
455+
description:
456+
name: package_info_plus_macos
457+
url: "https://pub.dartlang.org"
458+
source: hosted
459+
version: "1.3.0"
460+
package_info_plus_platform_interface:
461+
dependency: transitive
462+
description:
463+
name: package_info_plus_platform_interface
464+
url: "https://pub.dartlang.org"
465+
source: hosted
466+
version: "1.0.2"
467+
package_info_plus_web:
468+
dependency: transitive
469+
description:
470+
name: package_info_plus_web
471+
url: "https://pub.dartlang.org"
472+
source: hosted
473+
version: "1.0.4"
474+
package_info_plus_windows:
475+
dependency: transitive
476+
description:
477+
name: package_info_plus_windows
478+
url: "https://pub.dartlang.org"
479+
source: hosted
480+
version: "1.0.4"
425481
path:
426482
dependency: transitive
427483
description:
@@ -464,6 +520,20 @@ packages:
464520
url: "https://pub.dartlang.org"
465521
source: hosted
466522
version: "1.2.0"
523+
sentry:
524+
dependency: transitive
525+
description:
526+
name: sentry
527+
url: "https://pub.dartlang.org"
528+
source: hosted
529+
version: "6.2.2"
530+
sentry_flutter:
531+
dependency: "direct main"
532+
description:
533+
name: sentry_flutter
534+
url: "https://pub.dartlang.org"
535+
source: hosted
536+
version: "6.2.2"
467537
shelf:
468538
dependency: transitive
469539
description:
@@ -560,6 +630,13 @@ packages:
560630
url: "https://pub.dartlang.org"
561631
source: hosted
562632
version: "1.3.0"
633+
uuid:
634+
dependency: transitive
635+
description:
636+
name: uuid
637+
url: "https://pub.dartlang.org"
638+
source: hosted
639+
version: "3.0.5"
563640
vector_math:
564641
dependency: transitive
565642
description:
@@ -581,6 +658,13 @@ packages:
581658
url: "https://pub.dartlang.org"
582659
source: hosted
583660
version: "2.1.0"
661+
win32:
662+
dependency: transitive
663+
description:
664+
name: win32
665+
url: "https://pub.dartlang.org"
666+
source: hosted
667+
version: "2.3.3"
584668
yaml:
585669
dependency: transitive
586670
description:

pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ dependencies:
1818
flutter_bloc: ^8.0.1
1919
freezed_annotation: ^1.1.0
2020
json_annotation: ^4.3.0
21+
sentry_flutter: ^6.2.2
2122

2223
dev_dependencies:
2324
build_runner: ^2.1.7

0 commit comments

Comments
 (0)