errorHandler static method
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 PlatformDispatcher:
void main() {
WidgetsFlutterBinding.ensureInitialized();
FlutterError.onError = Instrumentation.errorHandler;
PlatformDispatcher.instance.onError = (error, stack) {
final details = FlutterErrorDetails(exception: error, stack: stack);
Instrumentation.errorHandler(details);
return true;
};
runApp(MyApp());
}
Implementation
// }
/// ```
///
/// For capturing all hybrid-level errors (Flutter & non-Flutter), use
/// PlatformDispatcher:
///
/// ```dart
/// void main() {
/// WidgetsFlutterBinding.ensureInitialized();
/// FlutterError.onError = Instrumentation.errorHandler;
/// PlatformDispatcher.instance.onError = (error, stack) {
/// final details = FlutterErrorDetails(exception: error, stack: stack);
/// Instrumentation.errorHandler(details);
/// return true;
/// };
/// runApp(MyApp());
/// }
/// ```
static Future<void> errorHandler(FlutterErrorDetails details) async {
// Call private constructor for coverage. Doesn't have any other effect.
// TODO: Remove when you can test private constructor some other way.
Instrumentation._();
final crashReport =
CrashReport(errorDetails: details, stackTrace: details.stack);
final arguments = {
"crashDump": crashReport.toString(),
};
return await channel.invokeMethod<void>('createCrashReport', arguments);
}