File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
1
+ import 'dart:async' ;
2
+
3
+ import 'package:dcc_toolkit/logger/bolt_logger.dart' ;
4
+ import 'package:flutter/widgets.dart' ;
5
+
6
+ /// A function that handles errors.
7
+ typedef OnError = void Function (Object error, StackTrace ? stackTrace);
8
+
9
+ /// Run a Flutter app with a bootstrap that catches errors.
10
+ /// By default [onError] will use BoltLogger to log the error.
11
+ Future <void > runAppBootstrap (
12
+ Future <Widget > Function () builder, {
13
+ OnError ? onError,
14
+ }) async {
15
+ final errorLogger = onError ??
16
+ (exception, stackTrace) {
17
+ BoltLogger .shock ([exception, stackTrace]);
18
+ };
19
+
20
+ await runZonedGuarded (
21
+ () async {
22
+ WidgetsFlutterBinding .ensureInitialized ();
23
+ FlutterError .onError =
24
+ (details) => errorLogger (details.exception, details.stack);
25
+
26
+ runApp (await builder ());
27
+ },
28
+ errorLogger,
29
+ );
30
+ }
You can’t perform that action at this time.
0 commit comments