How to get an error log from a physical device/productive app

Viewed 674

I have an app that seems to throw a NullPointerException on very rare occasions. We have not been able to reproduce this in any development environment.

Is there an internal log file or other way to read the error message when it occurs? For example, if a normal user who installed the app from the PlayStore/App Store gets the problem - is there a file or something the user could send us?

Or what is the best practice with Flutter to handle such errors?

1 Answers

As mentioned in the cookbook of Flutter, you can report errors to a service. Of course, you need to know which part of your code is throwing exceptions. You can print errors to the developer console in debug mode and send them to an API in production mode.

FlutterError.onError = (FlutterErrorDetails details) {
  if (isInDebugMode) {
    // In development mode, simply print to console.
    FlutterError.dumpErrorToConsole(details);
  } else {
    // In production mode, report to the application zone to report to
    // Sentry.
    Zone.current.handleUncaughtError(details.exception, details.stack);
  }
};

Related