handleError method

void handleError(
  1. FlutterErrorDetails details
)

Handles a Flutter error by logging details to the console.

Extracts the class/file name from the stack trace and provides a Google search link for the error message.

Implementation

void handleError(FlutterErrorDetails details) {
  String stack = details.stack.toString();
  String? className = _extractClassName(stack);

  if (kDebugMode) {
    print('ð–¢¥ == Error Details == ð–¢¥');
    String exceptionAsString = details.exceptionAsString();
    if (exceptionAsString.isNotEmpty) {
      print(exceptionAsString);
    }

    if ((className ?? "").isNotEmpty) {
      print('File: $className');
    }

    String exception = "${details.exceptionAsString()} flutter";
    String encodedQuery = Uri.encodeQueryComponent(exception);
    print('Google: (https://www.google.com/search?q=$encodedQuery)');

    if (config.level == ErrorStackLogLevel.verbose) {
      print("Stack: $stack");
    }
  }
}