From 1752ebad56bb5b1787cc44e5a52d177fb4cbfd3f Mon Sep 17 00:00:00 2001 From: Michael Joseph Rosenthal Date: Fri, 26 Nov 2021 09:47:05 -0600 Subject: [PATCH] Enable async runAppFunction callbacks Use FutureOr for runAppFunction and _runZonedGuarded callback return type, and pass runAppFunction! directly to _runZonedGuarded. --- lib/core/catcher.dart | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/core/catcher.dart b/lib/core/catcher.dart index 973b4758..95632aa6 100644 --- a/lib/core/catcher.dart +++ b/lib/core/catcher.dart @@ -27,7 +27,7 @@ class Catcher with ReportModeAction { final Widget? rootWidget; ///Run app function which will be ran - final void Function()? runAppFunction; + final FutureOr Function()? runAppFunction; /// Instance of catcher config used in release mode CatcherOptions? releaseConfig; @@ -206,20 +206,18 @@ class Catcher with ReportModeAction { runApp(rootWidget!); }); } else if (runAppFunction != null) { - _runZonedGuarded(() { - runAppFunction!(); - }); + _runZonedGuarded(runAppFunction!); } else { throw ArgumentError("Provide rootWidget or runAppFunction to Catcher."); } } - void _runZonedGuarded(void Function() callback) { + void _runZonedGuarded(FutureOr Function() callback) { runZonedGuarded>(() async { if (ensureInitialized) { WidgetsFlutterBinding.ensureInitialized(); } - callback(); + await callback(); }, (dynamic error, StackTrace stackTrace) { _reportError(error, stackTrace); });