runAppWithFConsole function
void
runAppWithFConsole(
- Widget app, {
- Future beforeRun()?,
- FConsoleCardDelegate? delegate,
- ErrHandler? errHandler,
Note: beforeRun will be called before runApp() if some code run ouside runAppWithConsole, the log will not cache by fconsole.
Implementation
void runAppWithFConsole(
Widget app, {
Future Function()? beforeRun,
FConsoleCardDelegate? delegate,
ErrHandler? errHandler,
}) async {
FlutterError.onError = (details) {
Zone.current.handleUncaughtError(
details.exception,
details.stack ?? StackTrace.current,
);
};
FConsole.instance.delegate = delegate ?? DefaultCardDelegate();
var zoneSpecification = ZoneSpecification(
print: (
Zone self,
ZoneDelegate parent,
Zone zone,
String line,
) {
FConsole.log(line, noPrint: true);
Zone.root.print(line);
},
handleUncaughtError: (
Zone self,
ZoneDelegate parent,
Zone zone,
Object error,
StackTrace stackTrace,
) {
FConsole.error(error, noPrint: true);
Zone.root.print('$error');
errHandler?.call(self, parent, zone, error, stackTrace);
},
);
runZoned(
() async {
await beforeRun?.call();
runApp(
ConsoleWidget(
options: ConsoleOptions(
displayMode: ConsoleDisplayMode.Always,
),
child: app,
),
);
},
zoneSpecification: zoneSpecification,
);
}