Flutter
294 bites tagged Flutter — interview questions with model answers, and 60-second explainers.
Unit test a BLoC handling an AddItem event and emitting state
Use blocTest with build, act, expect; mention seed, skip, and mocktail for dependencies. Whether you know BLoC testing idioms and why bloc_test beats manual assertions.
How do you widget-test states without real network calls?
This tests UI isolation from I/O. Mock the repository with Mockito, stub methods to yield loading, success, and error, and inject it via constructor or provider. Avoid real HTTP calls or unmocked clients in widget tests.
How do you verify a Text widget with 'Hello' is present?
Find.text('Hello') locates the widget; expect(finder, findsOneWidget) asserts exactly one exists. Flutter finder vs matcher API fluency.
Unit, widget, and integration test differences in Flutter
Tests your grasp of Flutter's test pyramid and isolation levels. Unit tests check pure Dart logic; widget tests verify UI in a headless environment; integration tests exercise the full app on a device. Red flag: saying widget tests require an emulator.
What is Pigeon and how does it improve platform channels?
This tests type-safe platform channels versus manual MethodChannel boilerplate. Answer: Pigeon is a dev-time code generator that creates typed host stubs from a Dart contract, removing string keys and encoding. Red flag: calling it a runtime library.
Present full-screen native SDK UI from Flutter and return a result
This tests platform channel architecture for full-screen native UI delegation. Use MethodChannel to launch the native controller, retain the async result callback, serialize the dismissal payload back to Dart, and avoid PlatformView for modal flows.
Safely gating native OS version APIs in a custom Flutter plugin
Tests platform channel contracts and defensive native coding. Gate native calls with OS version checks, return result.error with an UNSUPPORTED code, handle PlatformException in Dart, and avoid Dart-only checks.
What is a Platform View and why is it crucial?
Tests embedding native UI when Flutter widgets fall short. Strong answers define Platform Views as native embeddings, cite maps or WebView, and contrast Hybrid Composition's native hierarchy with Virtual Display's texture rasterization.
When to choose EventChannel over MethodChannel and native setup
It tests streaming versus one-shot platform communication. Pick EventChannel for ongoing native events like sensor data; register a StreamHandler on Android or iOS that feeds an event sink, then consume in Dart via receiveBroadcastStream.
Explain the purpose of MethodChannel and how it enables Dart-to-native calls
MethodChannel lets Dart encode a method call; the platform host decodes it on the main thread, runs native code, and returns an async result. Your grasp of the async bridge. Calling it synchronous or direct binding.
What native iOS and Android config does the Flutter camera plugin need?
Tests native platform knowledge beyond Dart. iOS requires NSCameraUsageDescription and NSMicrophoneUsageDescription in Info.plist. Android needs minSdk 24 and choosing between CameraX or Camera2 implementations.
Implement staggered animations using a single AnimationController and Interval
This tests multiplexing one ticker into sequential animations. Use one AnimationController, map each Tween to an Interval on distinct 0-to-1 sub-ranges, and rebuild with AnimatedBuilder. Red flag: multiple controllers or manual forward chaining.
How would you draw a line graph using Canvas and Path?
Use moveTo for the first point, lineTo for the rest, then Canvas.drawPath with a stroke Paint. Fluency with Flutter's imperative drawing model and Path construction.
In a CustomPainter, what is the purpose of the shouldRepaint method?
This tests Flutter repaint optimization. Answer: shouldRepaint compares old and new delegates, returning true only when visual properties differ so the framework skips paint calls. A red flag is returning true unconditionally, forcing useless repaints.
How does Tween work and how do you use ColorTween with Curves?
This tests value interpolation versus time remapping. A strong answer: Tween maps 0-1 to typed values; ColorTween lerps 2 colors; Curves.easeInOut warps input time before interpolation. Red flag: claiming the curve alters the color output instead of timing.
Compare AnimatedBuilder and Transition widgets for explicit animations
Tests whether you know how explicit animations rebuild the widget tree and where to isolate animation effects. AnimatedBuilder rebuilds only its builder subtree, while Transition widgets rebuild their child when the animation ticks.
How do AnimationController and TickerProvider work together to drive animations?
Tests your grasp of Flutter's imperative animation engine. AnimationController stores value and direction; TickerProvider (via vsync) schedules frame callbacks; paired they emit 60–120 ticks per second.
Describe CustomPaint and CustomPainter and implement a circle
This tests Flutter's render delegation. Separate CustomPaint, the canvas widget, from CustomPainter, the drawing logic; cover canvas.drawCircle and shouldRepaint returning false. Red flags: calling setState in paint or ignoring shouldRepaint.
Implicit vs explicit animations: AnimatedContainer or AnimationController?
Knowledge of Flutter's implicit versus explicit animation paradigms. Implicit widgets auto-animate property changes on rebuild; explicit controllers manage playback manually. Red flag: saying explicit is always superior or that implicit animations cannot stop.
How do you safely add a non-nullable column in sqflite?
Tests onCreate for fresh installs vs onUpgrade for existing data. Outline: bump version; in onUpgrade use ALTER TABLE ADD COLUMN NOT NULL DEFAULT for existing rows; keep onCreate as latest schema. Red flag: only changing onCreate so old users crash.
What is an sqflite transaction? Provide a practical example.
Tests atomicity in SQLite and isolate safety. A strong answer defines all-or-nothing execution, gives a fund-transfer example updating both, and warns sqflite transactions are not cross-isolate safe. Red flag: omitting rollback or multi-isolate writes.
Key difference between shared_preferences and flutter_secure_storage for tokens
Tests at-rest encryption: shared_preferences stores plain text XML/plist, while secure storage uses iOS Keychain and Keystore with RSA OAEP plus AES-GCM. Answers cite backup risks and hardware keys. Red flag: calling prefs safe or relying on obfuscation.
Why is Flutter local storage async and how do you use shared_preferences?
Tests why disk I/O must avoid blocking Dart's UI thread. A strong answer shows async/await with getInstance and setters, notes legacy getters are sync-after-cache, and warns writes may not persist instantly.
When to use SQLite over key-value storage?
Tests structured-vs-flat storage judgment. Good answers cite relational data, complex queries, or multi-table schemas, then list adding the dependency, getting a path, opening with onCreate, and keeping a singleton.
Get Flutter bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.