nativeErrorHandler static method

Future<void> nativeErrorHandler(
  1. 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 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> nativeErrorHandler(FlutterErrorDetails details) async {
  Instrumentation._();

  final crashReport =
      NativeCrashReport(errorDetails: details, stackTrace: details.stack);
  final arguments = {
    "crashData": crashReport.toString(),
  };

  return await channel.invokeMethod<void>(
      'createNativeCrashReport', arguments);
}