Migrating a Flutter App to Null Safety: Lessons Learned
Migrating an existing Flutter codebase to null safety is mostly mechanical — but a few patterns require real thinking. Here's a practical playbook.
If you are still on a pre-null-safety Flutter codebase, the migration is overdue but not scary. Most of it is mechanical. The interesting part is the pattern decisions you cannot automate, and those are worth thinking through before you run dart migrate.
Run the migration tool first
dart migrate gives you an interactive web UI showing what will change. It is conservative — it adds ? everywhere it cannot prove non-null. The result compiles but has way too many nullable types. Use it to understand the surface area, then refine manually.
Decide on Late vs ?
Variables that are non-null but assigned after construction (controllers, late state) should be late, not ?. Using ? everywhere means every read site has to handle null even when you know it cannot be.
Use ? for genuinely optional fields (an age that might be missing). Use late for fields that will be set before any read but cannot be set in the constructor.
Handle the API boundary
JSON from APIs lies. Even when the spec says a field is required, real responses sometimes omit it. Wrap fromJson() in defensive parsing — provide defaults for missing fields, throw a clear error when something truly required is missing. Do not let a bad response crash your app at a random later read.
Tests after migration
Once the migration compiles, run the full test suite. Most failures will be real null mismatches that were latent before — places where the old code accepted null and silently misbehaved. Each failure is the migration paying for itself.
About the author

Richard Gamora
Fullstack developer based in the Philippines, working mostly with Laravel and Vue.js, with eight years of production experience across web and mobile.
More on Flutter
November 19, 2025
Flutter State Management in 2026: Honest Comparison
Provider, Riverpod, BLoC, GetX — Flutter has many state management options. Here's how I actually pick between them for real apps.
November 12, 2025
Flutter Riverpod 2: Practical Patterns for Real Apps
Riverpod 2 with code generation is the most ergonomic way to manage state in Flutter today. Here are the patterns that hold up in production apps.
October 29, 2025
Flutter for Web — When It Makes Sense (And When It Doesn't)
Flutter Web has real strengths and real costs. Here's how to evaluate whether it fits your project, based on bundle size, SEO, and team needs.