From 94f43ded6f5f5d27b25ec985cb1760e165dba526 Mon Sep 17 00:00:00 2001 From: estevez Date: Mon, 24 Sep 2018 20:07:22 +0300 Subject: [PATCH] Fix: #75 Hadle any exception and show it in log view --- lib/main.dart | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 5a46eed..e6af2e4 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -26,7 +26,7 @@ class TheLogger { static String getLog() { String res = ''; _log.forEach((line) { - res += "$line\n\n"; + res += "$line\n"; }); return res; } @@ -40,7 +40,9 @@ class TheLogger { } static void log(String level, String message) { - debugPrint('$message'); + if (isInDebugMode) { + debugPrint('$message'); + } _log.add("[$level] : $message"); if (_log.length > 50) { _log.removeAt(0); @@ -49,7 +51,23 @@ class TheLogger { } -void main() => runApp(new HassClientApp()); +void main() { + FlutterError.onError = (errorDetails) { + TheLogger.log("Error", "${errorDetails.exception}"); + if (TheLogger.isInDebugMode) { + FlutterError.dumpErrorToConsole(errorDetails); + } + }; + + runZoned(() { + runApp(new HassClientApp()); + }, onError: (error, stack) { + TheLogger.log("Global error", "$error"); + }); + + + +} class HassClientApp extends StatelessWidget { // This widget is the root of your application.