ente/lib/bootstrap.dart

36 lines
944 B
Dart
Raw Normal View History

2022-11-01 06:13:06 +00:00
import "dart:async";
import "dart:developer";
import "package:bloc/bloc.dart";
import "package:flutter/widgets.dart";
class AppBlocObserver extends BlocObserver {
@override
void onChange(BlocBase bloc, Change change) {
super.onChange(bloc, change);
log("onChange(${bloc.runtimeType}, $change)");
}
@override
void onError(BlocBase bloc, Object error, StackTrace stackTrace) {
log("onError(${bloc.runtimeType}, $error, $stackTrace)");
super.onError(bloc, error, stackTrace);
}
}
Future<void> bootstrap(FutureOr<Widget> Function() builder) async {
FlutterError.onError = (details) {
log(details.exceptionAsString(), stackTrace: details.stack);
};
await runZonedGuarded(
() async {
await BlocOverrides.runZoned(
() async => runApp(await builder()),
blocObserver: AppBlocObserver(),
);
},
(error, stackTrace) => log(error.toString(), stackTrace: stackTrace),
);
}