@@ -2,32 +2,30 @@ import 'dart:async';
2
2
import 'dart:developer' ;
3
3
4
4
import 'package:bloc/bloc.dart' ;
5
+ import 'package:flutter/foundation.dart' ;
5
6
import 'package:flutter/widgets.dart' ;
7
+ import 'package:sudoku/app_bloc_observer.dart' ;
6
8
7
- class AppBlocObserver extends BlocObserver {
8
- const AppBlocObserver ();
9
-
10
- @override
11
- void onChange (BlocBase <dynamic > bloc, Change <dynamic > change) {
12
- super .onChange (bloc, change);
13
- log ('onChange(${bloc .runtimeType }, $change )' );
14
- }
15
-
16
- @override
17
- void onError (BlocBase <dynamic > bloc, Object error, StackTrace stackTrace) {
18
- log ('onError(${bloc .runtimeType }, $error , $stackTrace )' );
19
- super .onError (bloc, error, stackTrace);
20
- }
21
- }
22
-
9
+ /// Bootstrap is responsible for any common setup and calls
10
+ /// [runApp] with the widget returned by [builder] in an error zone.
23
11
Future <void > bootstrap (FutureOr <Widget > Function () builder) async {
12
+ // Log all uncaught build phase errors from the framework
24
13
FlutterError .onError = (details) {
25
14
log (details.exceptionAsString (), stackTrace: details.stack);
26
15
};
27
16
28
- Bloc .observer = const AppBlocObserver ();
29
-
30
- // Add cross-flavor configuration here
17
+ // Log all uncaught asynchronous errors that aren't handled
18
+ // by the Flutter framework.
19
+ PlatformDispatcher .instance.onError = (error, stack) {
20
+ log (error.toString (), stackTrace: stack);
21
+ return true ;
22
+ };
31
23
32
- runApp (await builder ());
24
+ await runZonedGuarded (
25
+ () async {
26
+ Bloc .observer = const AppBlocObserver ();
27
+ runApp (await builder ());
28
+ },
29
+ (error, stackTrace) => log (error.toString (), stackTrace: stackTrace),
30
+ );
33
31
}
0 commit comments