Error Handling in Flutter

Greg Perry
Flutter Community
Published in
16 min readFeb 7, 2020

--

How to handle errors in Flutter

Handle your errors! Your app will have errors. You’ve got to handle them. Who wants to see the ‘Red Screen of Death?’ Certainly not your users. (Actually, it’s gray when in production, but regardless) That’s bad. If it’s going to fail with an unrecoverable error, your app should be proactive about it. If it must crash, your app should make the effort to do so gracefully. It should even demonstrate some resilience and not crash too badly — not lose any data, etc. Your app should also be accountable — telling the user what just happened, and not just leaving them starring at a red screen (a gray screen actually. Regardless!). Like documentation, error handling seems to be the last thing we developers think about when developing software. That’s not good.

Exceptions are considered conditions that you can plan ahead for and catch. Errors are conditions that you don’t expect or plan for.

A tour of the core libraries

This article will cover Flutter’s error handling. We’ll walk through errors you will likely encounter when developing, and what Flutter does in response. Finally, we’ll cover how to incorporate your own error handling.

I Like Screenshots. Tap Caption For Gists.

As always, I prefer using screenshots in my articles over gists to show concepts rather than just show code. I find them easier to work with frankly. However, you can click or tap on their captions to see the code…

--

--