Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit c6a5aa0

Browse files
author
hffmnn
committed
update the example
1 parent 3db09d7 commit c6a5aa0

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

  • packages/firebase_crashlytics/example/lib

packages/firebase_crashlytics/example/lib/main.dart

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'dart:async';
2+
13
import 'package:flutter/material.dart';
24

35
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
@@ -13,7 +15,12 @@ void main() {
1315
FlutterError.onError = (FlutterErrorDetails details) {
1416
Crashlytics.instance.onError(details);
1517
};
16-
runApp(MyApp());
18+
19+
runZoned<Future<void>>(() async {
20+
runApp(MyApp());
21+
}, onError: (dynamic error, dynamic stack) async {
22+
await Crashlytics.instance.onRuntimeException(error, stack);
23+
});
1724
}
1825

1926
class MyApp extends StatefulWidget {
@@ -61,6 +68,17 @@ class _MyAppState extends State<MyApp> {
6168
// Crashlytics.
6269
throw StateError('Uncaught error thrown by app.');
6370
}),
71+
FlatButton(
72+
child: const Text('Async out of bounds'),
73+
onPressed: () {
74+
// Example of an exception that does not get catched
75+
// by `Flutter.onError` but the `onError` handler of
76+
// `runZoned`.
77+
Future<void>.delayed(Duration(seconds: 2), () {
78+
final List<int> list = <int>[];
79+
print(list[100]);
80+
});
81+
}),
6482
],
6583
),
6684
),

0 commit comments

Comments
 (0)