Flutter Sentry Example

5/9/2022

So you released your Flutter app into the wild and you have no idea what’s going on. People are using it but are they enjoying it? Sentry, and products like it, are probably essential in any Flutter app given the price and the effort to install. You never know what errors the user experiences if your not looking. One simple bug fix may be causing users to abandon the application early.

I won’t go through the setup, the Sentry website does a good job and it’s very simple. Here’s a really simple example of Sentry output when using Flutter. When you run it with your API key you will get an email as follows.

As well as it will show on the dashboard, mine took about a minute to show up.

Here’s the

sample Flutter code

with a minimum example.

As you can see it’s possible to include custom attributes to filter alerts.

    final additionalData = {
      'developer': 'Brad',
      'channel': 'Alpha',
      'server': 'dev',
    };
    Sentry.configureScope((scope) => scope.setContexts('environment', additionalData));

This makes Sentry very convenient if you have multiple release channels or server configurations.

Sentry Best Practices

These are the top things you will need to get the best value from Sentry.

  • Turn on email notifications. You won’t be getting that many errors and it’s best to get them ASAP

  • Don’t log things as errors that are not errors, it will clog up and hide real errors.

  • Make sure you update your Sentry package regularly, they are always adding new features.

  • Make sure you app meta data is up to date. It helps when reading error messages.

  • Include the stack trace in any error, make sure your code is not clearing it out.

  • Make sure messages are specific so you can find the area of code easily.

There is also a

Flutter Feedback add in

.