More in Flutter & Dart — page 8
Tree Shaking Removes Unused Flutter Code
Tree shaking is the compiler deleting code your app never calls, so importing a massive package only costs the pieces you use. It runs automatically in release builds. Relying on dynamic dispatch or dart:mirrors silently disables it and brings back the bloat.
Legacy Integration Testing with flutter_driver
flutter_driver remotely pilots your app from a host via Dart VM service, common in legacy codebases with host-side scripts. Do not treat it as an in-process widget test because it runs outside the app; you cannot inspect state or use flutter_test matchers.
Repository Pattern: Hide Your Data Sources
A repository is a contract that hides where your data lives. Your Flutter app should not care if a user profile comes from Firebase, SQLite, or a mock. Engineers often leak HTTP clients or database models into UI instead of returning domain models.
Flutter Network Errors: Fail Gracefully
Treat every network call as a promise that might break. In Flutter, catch exceptions at the HTTP boundary and map them to UI states like retry widgets. The footgun is letting Dio or http exceptions bubble up, crashing the app instead of degrading gracefully.
Full-Text Search in Local Flutter Databases
SQLite FTS5 is an inverted index in your app: words map to row IDs, skipping brute-force scans. Use it when local tables exceed thousands of rows and LIKE lags. The footgun is that FTS virtual tables never auto-sync, so stale indexes return wrong rows.
Passing Arguments to Flutter Named Routes
Flutter named routes pass data through an arguments field instead of global variables. Use this when navigating to a route that needs an ID or configuration object. Arguments are untyped by default, so unsafe casts crash at runtime.
Performance Profiling in Tests
Performance profiling in tests means capturing frame build and raster times during a scripted, automated run instead of eyeballing smoothness, so jank regressions get caught in CI before they ever reach a real device.
Flutter Nested Navigation: Routers Within Routers
Nested Navigation is like having a mini-app with its own back button inside a single screen. It's used for UIs like a BottomNavigationBar where each tab needs its own navigation history. The footgun is calling the wrong Navigator's context.
Flutter's `compute`: Offload Heavy Work from the UI Thread
Flutter's `compute` function runs heavy calculations in the background to prevent your app's UI from freezing. Use it for tasks like parsing large JSON or complex math. The footgun: on the web, it runs on the same event loop, not in a true parallel thread.
Flutter for Web: Build and Deploy
Flutter for Web compiles your Dart code into a web app. Use `flutter build web` and choose a renderer: HTML for smaller size or CanvasKit for performance. The footgun is the initial download size, which can be large and slow down first-page load.
Generating Code Coverage Reports in Dart
Code coverage shows which lines your tests execute. It's a health check for your test suite's reach, not a measure of code quality. Use the `coverage` package to generate reports for CI/CD. The footgun is that high coverage doesn't prove correctness.
Mocking Dependencies in Flutter with Mockito
Mockito creates fake, controllable versions of your app's dependencies, like an API client. This is crucial for unit tests, letting you isolate code from external systems to make tests fast, reliable, and independent of network or database availability.
Flutter Widget Testing: Verifying UI in Isolation
Widget testing is like testing a single actor's performance without the full play. It lets you build, interact with, and verify a single UI component in isolation, making it faster than a full app test and more comprehensive than a unit test.
EventChannel: Streaming Data from Native to Flutter
EventChannel is a one-way radio from native code to your Flutter app, designed for continuous event streams, not single method calls. Use it to listen for ongoing platform events like sensor data, GPS location updates, or battery state changes.
Flutter Shaders: GPU Power for Custom Graphics
Shaders are small programs running on the GPU to create custom visual effects. Use them for high-performance graphics like frosted glass or animated gradients that standard widgets can't handle.
Choosing a Flutter Local Persistence Strategy
Flutter offers three main ways to persist data locally. Your options are simple key-value pairs for settings, direct file I/O for blobs like images, or a full SQLite database for complex, structured data. The main footgun is picking the wrong tool for the job.

StateNotifierProvider: Manage Immutable State
StateNotifierProvider bundles immutable state with the logic to change it. It's ideal for managing complex objects like a todo list by exposing methods like `addTodo`.

BLoC Pattern: Separating UI from Business Logic
The BLoC pattern treats app state as a stream: events go in, states come out. Use it in Flutter for complex state like user auth or data fetching. The footgun is overusing it for simple UI state, which creates unnecessary boilerplate.
Flutter's onGenerateRoute for Dynamic Routes
onGenerateRoute is Flutter's central switchboard for creating routes on the fly, especially when they need data. Use it to pass arguments to new screens or handle routes not statically defined in the `routes` map.
Deep Linking: URLs for Your App's Screens
Deep linking gives your app screens their own URLs, letting users jump directly to specific content from outside the app. Use it for email marketing, sharing content, or push notifications.