Dart
199 bites tagged Dart — interview questions with model answers, and 60-second explainers.
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.
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.
NavigatorObserver: Listening to Route Changes in Flutter
A NavigatorObserver acts like a flight traffic controller for your app's screens, letting you react to navigation events like `push` and `pop`. It's used for analytics or updating UI based on the current route.
Flutter's Draggable and DragTarget: The Drag-and-Drop Pair
Build drag-and-drop UI in Flutter with the Draggable and DragTarget widget pair. A Draggable carries data, and a DragTarget acts as a mailbox that accepts it. Use them for reordering lists. The footgun: drops fail silently if the data types don't match.
Find Flutter Memory Leaks with DevTools
Think of the DevTools Memory view as an MRI for your app's RAM. It helps you find objects that aren't being garbage collected, diagnose bloat, and fix crashes.
Profiling Flutter Apps with Dart DevTools
Dart DevTools is your app's diagnostic tool, letting you see exactly why frames drop or memory spikes. Use it to find the root cause of "jank" in lists or slow animations.
Flutter's Architectural Layers: UI and Data
Think of a Flutter app in two parts: the UI layer for what the user sees, and a data layer for fetching and managing information. This separation is crucial for apps with APIs or complex state.
Deferred Components: On-Demand Features in Flutter
Think of deferred components as downloadable content for your app. They reduce initial install size by letting you download features on demand. This is ideal for large, rarely-used functions on Android and web, but requires handling loading states and network…
Flutter Code Obfuscation: Hiding Your Logic
Obfuscation makes your compiled Dart code harder to reverse-engineer by renaming symbols to be unreadable. Use it in production builds to protect sensitive logic, but always save the symbol map file to decipher crash reports later.
flutter analyze: Your Code's First Line of Defense
Think of `flutter analyze` as a spell-checker for your Dart code. It catches errors, style issues, and potential bugs before you run the app. The footgun is ignoring its configuration; its real power is in a custom `analysis_options.yaml` file.
Flutter Build Modes: Debug, Profile, and Release
Flutter's build modes trade performance for developer features. Debug mode is for fast iteration with hot reload, while Release is for optimized user builds. You use Debug daily, Profile to hunt for bottlenecks, and Release to ship.
Testing Flutter Platform Channel Interactions
Mock platform channels to test your Dart code's interaction with native APIs without a real device. Use this for unit tests of features like camera or GPS access. Footgun: These tests only verify the Dart side, not that your native code is correct.
Golden File Testing: Visual Regression for Widgets
Golden file testing is a 'spot the difference' game for your UI, catching visual regressions by comparing a widget's rendering to a master image. Use it to lock down critical widget appearances.
WidgetTester: Programmatically Drive Your Flutter UI
WidgetTester is a robot user for your app, programmatically tapping, dragging, and entering text. Use it in `testWidgets` to simulate user flows and verify UI state. The footgun is forgetting `tester.pump()` after an action; you'll assert against a stale UI.
Get Dart bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.