errorHandler method Null safety
- FlutterErrorDetails details
Intercepts Flutter-level errors and reports them to the controller.
Warning: Does not report obfuscated apps crash reports (WIP).
import 'package:flutter/material.dart';
import 'package:appdynamics_agent/appdynamics_agent.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
FlutterError.onError = Instrumentation.errorHandler;
runApp(MyApp());
For capturing all hybrid-level errors (Flutter & non-Flutter), use zones:
void main() {
runZonedGuarded(() {
WidgetsFlutterBinding.ensureInitialized();
FlutterError.onError = Instrumentation.errorHandler;
runApp(MyApp());
}, (Object error, StackTrace stack) async {
final details = FlutterErrorDetails(
exception: error.toString(),
stack: stack);
});
}
Implementation
// }
/// ```
///
/// For capturing all hybrid-level errors (Flutter & non-Flutter), use zones:
///
/// ```dart
/// void main() {
/// runZonedGuarded(() {
/// WidgetsFlutterBinding.ensureInitialized();
/// FlutterError.onError = Instrumentation.errorHandler;
/// runApp(MyApp());
/// }, (Object error, StackTrace stack) async {
/// final details = FlutterErrorDetails(
/// exception: error.toString(),
/// stack: stack);
// await Instrumentation.errorHandler(details);
/// });
/// }
/// ```
static Future<void> errorHandler(FlutterErrorDetails details) async {
FlutterError.presentError(details);
final crashReport = CrashReport(
message: details.exceptionAsString(), stackTrace: details.stack);
final arguments = {
"crashDump": crashReport.toString(),
};
return await channel.invokeMethod<void>('createCrashReport', arguments);
}