@@ -42,52 +42,58 @@ final GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
42
42
43
43
Future <void > main () async {
44
44
await setupSentry (
45
- () => runApp (
46
- SentryWidget (
47
- child: DefaultAssetBundle (
48
- bundle: SentryAssetBundle (),
49
- child: const MyApp (),
50
- ),
51
- ),
52
- ),
53
- exampleDsn);
45
+ () => runApp (
46
+ SentryWidget (
47
+ child: DefaultAssetBundle (
48
+ bundle: SentryAssetBundle (),
49
+ child: const MyApp (),
50
+ ),
51
+ ),
52
+ ),
53
+ exampleDsn,
54
+ );
54
55
}
55
56
56
- Future <void > setupSentry (AppRunner appRunner, String dsn,
57
- {bool isIntegrationTest = false ,
58
- BeforeSendCallback ? beforeSendCallback}) async {
59
- await SentryFlutter .init ((options) {
60
- options.dsn = exampleDsn;
61
- options.tracesSampleRate = 1.0 ;
62
- options.profilesSampleRate = 1.0 ;
63
- options.reportPackages = false ;
64
- options.addInAppInclude ('sentry_flutter_example' );
65
- options.considerInAppFramesByDefault = false ;
66
- options.attachThreads = true ;
67
- options.enableWindowMetricBreadcrumbs = true ;
68
- options.addIntegration (LoggingIntegration (minEventLevel: Level .INFO ));
69
- options.sendDefaultPii = true ;
70
- options.reportSilentFlutterErrors = true ;
71
- options.attachScreenshot = true ;
72
- options.screenshotQuality = SentryScreenshotQuality .low;
73
- options.attachViewHierarchy = true ;
74
- // We can enable Sentry debug logging during development. This is likely
75
- // going to log too much for your app, but can be useful when figuring out
76
- // configuration issues, e.g. finding out why your events are not uploaded.
77
- options.debug = true ;
78
-
79
- options.maxRequestBodySize = MaxRequestBodySize .always;
80
- options.maxResponseBodySize = MaxResponseBodySize .always;
81
-
82
- _isIntegrationTest = isIntegrationTest;
83
- if (_isIntegrationTest) {
84
- options.dist = '1' ;
85
- options.environment = 'integration' ;
86
- options.beforeSend = beforeSendCallback;
87
- }
88
- },
89
- // Init your App.
90
- appRunner: appRunner);
57
+ Future <void > setupSentry (
58
+ AppRunner appRunner,
59
+ String dsn, {
60
+ bool isIntegrationTest = false ,
61
+ BeforeSendCallback ? beforeSendCallback,
62
+ }) async {
63
+ await SentryFlutter .init (
64
+ (options) {
65
+ options.dsn = exampleDsn;
66
+ options.tracesSampleRate = 1.0 ;
67
+ options.profilesSampleRate = 1.0 ;
68
+ options.reportPackages = false ;
69
+ options.addInAppInclude ('sentry_flutter_example' );
70
+ options.considerInAppFramesByDefault = false ;
71
+ options.attachThreads = true ;
72
+ options.enableWindowMetricBreadcrumbs = true ;
73
+ options.addIntegration (LoggingIntegration (minEventLevel: Level .INFO ));
74
+ options.sendDefaultPii = true ;
75
+ options.reportSilentFlutterErrors = true ;
76
+ options.attachScreenshot = true ;
77
+ options.screenshotQuality = SentryScreenshotQuality .low;
78
+ options.attachViewHierarchy = true ;
79
+ // We can enable Sentry debug logging during development. This is likely
80
+ // going to log too much for your app, but can be useful when figuring out
81
+ // configuration issues, e.g. finding out why your events are not uploaded.
82
+ options.debug = true ;
83
+
84
+ options.maxRequestBodySize = MaxRequestBodySize .always;
85
+ options.maxResponseBodySize = MaxResponseBodySize .always;
86
+
87
+ _isIntegrationTest = isIntegrationTest;
88
+ if (_isIntegrationTest) {
89
+ options.dist = '1' ;
90
+ options.environment = 'integration' ;
91
+ options.beforeSend = beforeSendCallback;
92
+ }
93
+ },
94
+ // Init your App.
95
+ appRunner: appRunner,
96
+ );
91
97
}
92
98
93
99
class MyApp extends StatefulWidget {
@@ -123,22 +129,23 @@ class TooltipButton extends StatelessWidget {
123
129
final String buttonTitle;
124
130
final void Function ()? onPressed;
125
131
126
- const TooltipButton (
127
- { required this .onPressed,
128
- required this .buttonTitle,
129
- required this .text,
130
- Key ? key})
131
- : super (key: key);
132
+ const TooltipButton ({
133
+ required this .onPressed,
134
+ required this .buttonTitle,
135
+ required this .text,
136
+ Key ? key,
137
+ }) : super (key: key);
132
138
133
139
@override
134
140
Widget build (BuildContext context) {
135
141
return Tooltip (
136
- message: text,
137
- child: ElevatedButton (
138
- onPressed: onPressed,
139
- key: key,
140
- child: Text (buttonTitle),
141
- ));
142
+ message: text,
143
+ child: ElevatedButton (
144
+ onPressed: onPressed,
145
+ key: key,
146
+ child: Text (buttonTitle),
147
+ ),
148
+ );
142
149
}
143
150
}
144
151
@@ -188,8 +195,9 @@ class MainScaffold extends StatelessWidget {
188
195
const Padding (
189
196
padding: EdgeInsets .all (15 ), //apply padding to all four sides
190
197
child: Center (
191
- child: Text (
192
- 'Long press a button to see more information. (hover on web)' )),
198
+ child: Text (
199
+ 'Long press a button to see more information. (hover on web)' ),
200
+ ),
193
201
),
194
202
TooltipButton (
195
203
onPressed: () => navigateToAutoCloseScreen (context),
@@ -301,20 +309,23 @@ class MainScaffold extends StatelessWidget {
301
309
TooltipButton (
302
310
onPressed: () {
303
311
// modeled after a real exception
304
- FlutterError .onError? .call (FlutterErrorDetails (
305
- exception: Exception ('A really bad exception' ),
306
- silent: false ,
307
- context: DiagnosticsNode .message ('while handling a gesture' ),
308
- library: 'gesture' ,
309
- informationCollector: () => [
310
- DiagnosticsNode .message (
311
- 'Handler: "onTap" Recognizer: TapGestureRecognizer' ),
312
- DiagnosticsNode .message (
313
- 'Handler: "onTap" Recognizer: TapGestureRecognizer' ),
314
- DiagnosticsNode .message (
315
- 'Handler: "onTap" Recognizer: TapGestureRecognizer' ),
316
- ],
317
- ));
312
+ FlutterError .onError? .call (
313
+ FlutterErrorDetails (
314
+ exception: Exception ('A really bad exception' ),
315
+ silent: false ,
316
+ context:
317
+ DiagnosticsNode .message ('while handling a gesture' ),
318
+ library: 'gesture' ,
319
+ informationCollector: () => [
320
+ DiagnosticsNode .message (
321
+ 'Handler: "onTap" Recognizer: TapGestureRecognizer' ),
322
+ DiagnosticsNode .message (
323
+ 'Handler: "onTap" Recognizer: TapGestureRecognizer' ),
324
+ DiagnosticsNode .message (
325
+ 'Handler: "onTap" Recognizer: TapGestureRecognizer' ),
326
+ ],
327
+ ),
328
+ );
318
329
},
319
330
text:
320
331
'Creates a FlutterError and passes it to FlutterError.onError callback. This demonstrates how our flutter error integration catches unhandled exceptions.' ,
@@ -449,27 +460,28 @@ class MainScaffold extends StatelessWidget {
449
460
),
450
461
TooltipButton (
451
462
onPressed: () {
452
- feedback.BetterFeedback .of (context)
453
- .show ((feedback.UserFeedback feedback) {
454
- Sentry .captureMessage (
455
- feedback.text,
456
- withScope: (scope) {
457
- final entries = feedback.extra? .entries;
458
- if (entries != null ) {
459
- for (final extra in entries) {
460
- scope.setExtra (extra.key, extra.value);
463
+ feedback.BetterFeedback .of (context).show (
464
+ (feedback.UserFeedback feedback) {
465
+ Sentry .captureMessage (
466
+ feedback.text,
467
+ withScope: (scope) {
468
+ final entries = feedback.extra? .entries;
469
+ if (entries != null ) {
470
+ for (final extra in entries) {
471
+ scope.setExtra (extra.key, extra.value);
472
+ }
461
473
}
462
- }
463
- scope. addAttachment (
464
- SentryAttachment . fromUint8List (
465
- feedback.screenshot ,
466
- 'feedback. png' ,
467
- contentType : 'image/png' ,
468
- ),
469
- );
470
- },
471
- );
472
- } );
474
+ scope. addAttachment (
475
+ SentryAttachment . fromUint8List (
476
+ feedback.screenshot,
477
+ ' feedback.png' ,
478
+ contentType : 'image/ png' ,
479
+ ) ,
480
+ );
481
+ },
482
+ );
483
+ },
484
+ );
473
485
},
474
486
text:
475
487
'Sends the capture message with an image attachment to Sentry.' ,
@@ -754,18 +766,20 @@ class _IntegrationTestWidgetState extends State<IntegrationTestWidget> {
754
766
755
767
@override
756
768
Widget build (BuildContext context) {
757
- return Column (children: [
758
- Text (
759
- _output,
760
- key: const Key ('output' ),
761
- ),
762
- _isLoading
763
- ? const CircularProgressIndicator ()
764
- : ElevatedButton (
765
- onPressed: () async => await _captureException (),
766
- child: const Text ('captureException' ),
767
- )
768
- ]);
769
+ return Column (
770
+ children: [
771
+ Text (
772
+ _output,
773
+ key: const Key ('output' ),
774
+ ),
775
+ _isLoading
776
+ ? const CircularProgressIndicator ()
777
+ : ElevatedButton (
778
+ onPressed: () async => await _captureException (),
779
+ child: const Text ('captureException' ),
780
+ )
781
+ ],
782
+ );
769
783
}
770
784
771
785
Future <void > _captureException () async {
0 commit comments