← All notes·4 min read

Your Flutter app crashes in production and never on your phone

The crash reports keep coming and you can't reproduce a single one. That gap is almost always the same handful of differences between your phone and your users' phones.

The crash rate in the console is climbing. You open the app on your phone, try every screen, and nothing happens. You try again on the simulator. Nothing.

This is not bad luck. Your phone is the least representative device your app will ever run on: recent, fast, plenty of memory, good connection, a debug build, and a user who knows exactly where to tap. Production is everything else.

Here's where the gap usually is.

You're testing a different app

Debug and release Flutter builds are not the same program. Debug compiles just in time, runs asserts and is slower in ways that hide timing problems. Release is compiled ahead of time, strips asserts and runs fast enough to expose race conditions that debug never hit.

If you only ever run debug, you are testing something your users never install. Use flutter run --release (or --profile, if you want DevTools) on a physical device as part of your routine, not only before a launch.

You've never seen your app come back from the background

On your phone, the app stays in memory. On a low-end Android phone with 3 GB of RAM and twenty other apps open, the system kills your process as soon as the user switches away. When they come back, Android recreates the app, and whatever state you kept only in memory is gone.

That's where you see null errors on screens that "can't" have null data, or controllers used after they were disposed.

Two ways to see it yourself:

  • Turn on Don't keep activities in Android's developer options. Every time you leave the app, it's destroyed.
  • Listen to AppLifecycleState and make sure anything tied to the hardware is released and rebuilt properly when the app is paused and resumed.

The hardware part matters more than it sounds. In the Nydus Systems kiosk, four separate freezes turned out to have one cause: the camera was being torn down and recreated on every screen entry and exit. On a fast phone in a quick test, that looks fine. On a tablet clocking people in all day, it doesn't.

Async code finishing after the screen is gone

A request starts, the user taps back, the response arrives and the code calls setState on a widget that no longer exists. Or it uses a BuildContext that belonged to the screen they just left.

On your phone, the request returns in 200 ms and you never tap back that fast. On a 3G connection it takes eight seconds, and people leave.

The fixes are boring and they work: check mounted after every await before touching the widget or its context, cancel subscriptions and timers in dispose, and don't fire futures you never await unless you've decided what happens when they fail.

Data you didn't expect

Your test account has a name, a photo and a complete profile. Some real user doesn't. The API returns null for a field that has always had a value, and json['name'] as String throws.

AI-generated parsing code is especially prone to this: it's written against the example response, and the example response is always complete. Parse defensively at the boundary, decide what the app shows when a field is missing, and make the backend contract explicit about what is optional.

Devices you don't own

  • Memory. Loading full-resolution images into a list is fine on a flagship and fatal on a budget phone. Use cacheWidth and cacheHeight on images so the decoded bitmap matches what's on screen.
  • Manufacturer battery savers. Some Android brands kill background work far more aggressively than stock Android. If something must run in the background, test it on those brands.
  • Permissions denied. You granted everything once, months ago. Some users tap "Don't allow". Every path that needs a permission needs a path for when it's refused.

You can't fix what you can't see

None of the above helps if the crash report says "something went wrong" with an unreadable stack trace. Before chasing any single bug:

  1. Report every error, not just the crashes. Set FlutterError.onError for framework errors and PlatformDispatcher.instance.onError for errors outside Flutter's callbacks, and send both to Crashlytics, Sentry or whatever you use.
  2. Upload your symbols. If you build with --obfuscate --split-debug-info, the stack traces are useless until the symbol files are uploaded. On iOS, the same goes for dSYM files.
  3. Attach context. The app version, the screen, the last few actions. A crash with a breadcrumb trail is an afternoon's work. A crash without one is a week.

Then work through the list one crash signature at a time, starting with the one affecting the most users. That's how the Nydus crash hunt went: item by item through Crashlytics, CameraController first.

When the list doesn't get shorter

If you fix crashes every week and the rate doesn't move, the problem is probably the structure, not the individual bugs: state that lives in the wrong place, a lifecycle nobody owns, dependencies two major versions behind.

Our app rescue starts with a fixed-price audit that finds which of these you have, and ends with a written plan to fix it, by us or by your team.

Tell us what you're building.

You'll speak to an engineer, not a salesperson — and you'll get a straight answer about whether we're the right team for it.

Talk to an engineer