TF-4268 Refactor app runner: split web/mobile runners, add platform error handlers

This commit is contained in:
dab246
2026-04-07 16:09:49 +07:00
committed by Dat H. Pham
parent 78e76b5aac
commit 2a666056c2
8 changed files with 78 additions and 54 deletions
+30
View File
@@ -0,0 +1,30 @@
import 'dart:ui';
import 'package:core/utils/app_logger.dart';
import 'package:core/utils/build_utils.dart';
import 'package:flutter/material.dart';
/// Configures global error handlers for both Flutter framework and Platform dispatcher.
void setupErrorHooks() {
// Handle Flutter Framework Errors (Rendering, Build, Layout, etc.)
FlutterError.onError = (details) {
logError(
'FlutterError: ${details.exception}',
exception: details.exception,
stackTrace: details.stack,
);
// Show the "Red Screen of Death" in debug mode.
FlutterError.presentError(details);
};
// Handle Asynchronous Errors (Futures, Streams, Platform Channels)
PlatformDispatcher.instance.onError = (error, stack) {
logError(
'PlatformDispatcherError: $error',
exception: error,
stackTrace: stack,
);
// Return true in release to prevent crashes; false in debug to surface errors.
return BuildUtils.isReleaseMode;
};
}