Skip to content
tezvyn:

Dart

199 bites tagged Dart — interview questions with model answers, and 60-second explainers.

Flutter & Dart2 min read

Explain single-subscription vs broadcast Streams in Dart

Tests dart:async stream lifecycle. Outline: single-subscription allows one listener and emits on listen; broadcast supports many but drops events for late arrivals. Red flag: saying single-subscription allows multiple listeners or buffers events.

Flutter & Dart2 min read

Describe the Dart event loop and queue execution order

Tests your grasp of Dart's single-threaded event loop priority. Great answers state: microtasks drain fully before the next event processes, cycling forever. Red flag: saying Future and scheduleMicrotask interleave in call order.

Flutter & Dart2 min read

Difference between Future<void> and void from an async function

Future<void> lets callers await and catch errors; void hides the Future, preventing await and leaving exceptions uncaught. Knowledge that async always produces a Future. Believing void async returns are awaitable.

Flutter & Dart2 min read

Define a Dart Future, return Future<String>, and handle errors with both patterns.

Tests Dart async primitives and error handling. A strong answer defines Future as a pending async result, writes a delayed Future<String>, consumes it with then/catchError, and mirrors with async/await try/catch.

Flutter & Dart2 min read

How does Dart resolve mixin method conflicts and application order?

Tests understanding of Dart's mixin linearization. Answer: Dart applies mixins left-to-right, building a superclass chain where the last mixin wins conflicts. Red flag: claiming first mixin wins or confusing with multiple inheritance.

Flutter & Dart2 min read

How do you model Product and safely parse JSON into List<Product>?

Tests bridging dynamic JSON to Dart's type system. A strong answer uses an immutable Product with a factory constructor that validates fields and converts types, mapping over the list. Red flag: leaving everything dynamic or assuming perfect API data.

Flutter & Dart2 min read

What is a Dart factory constructor and common use cases?

Explain a factory need not create new instances and can return cached objects or subtypes; contrast with generative ones; give JSON or singleton examples. When Dart factories beat generative constructors.

Flutter & Dart2 min read

What are the key differences between Dart extends, implements, and with?

This tests your grasp of Dart's inheritance, interface, and mixin models. extends gives single inheritance; implements forces full reimplementation; with injects shared behavior.

Flutter & Dart2 min read

Deduplicate a List of emails in Dart

Tests knowledge of Dart's Set semantics and LinkedHashSet insertion order. The idiomatic solution is emails.toSet().toList(), which deduplicates in O(n) time while preserving order. Avoid manual loops with contains, which are O(n^2) and unidiomatic.

Flutter & Dart2 min read

Difference between final and const Dart class properties?

This tests your grasp of Dart's compile-time versus runtime constant model. A strong answer contrasts final variables set once with static const compile-time values, notes const is implicitly final, gives examples. Red flag: const as non-static instance field.

Flutter & Dart2 min read

Convert List<User> to Map<String, User> keyed by user id

Tests Dart collection-to-map idioms. A strong answer picks the for-element literal {for (var u in users) u.id: u}, mentions Map.fromIterable as a verbose alternative, and flags duplicate-key overwrites. Red flag: manually looping to populate an empty map.

Flutter & Dart2 min read

Explain Dart's event loop, microtask queue, event queue, and await behavior

Tests Dart single-threaded event loop model. Strong answer: microtasks drain before event queue tasks; await suspends the function and schedules its resumption via the event loop when the Future completes. Red flag: claiming await blocks the thread.

Flutter & Dart2 min read

Explain Dart switch exhaustiveness for enums versus sealed classes

This tests Dart 3 exhaustiveness. A strong answer notes that enums and sealed classes both require exhaustive switches, but sealed classes allow distinct payloads because subclasses stay in the same library. A red flag is calling them just enums with methods.

Flutter & Dart2 min read

What are Dart extension methods? Implement toIntOrDefault on String.

Tests Dart extension syntax and static resolution. A strong answer defines an extension on String, uses int.tryParse with a fallback, and notes extensions do not mutate the original type. Red flag: using try-catch over tryParse or claiming dynamic dispatch.

Flutter & Dart2 min read

What is a Dart closure? Write a function that returns a function.

Tests lexical scoping: define a closure as a function plus its captured environment, show a makeAdder where the inner function uses a parent variable after the parent returns.

Flutter & Dart2 min read

How do you use collection-if and collection-for to declaratively build a list?

Tests Dart's declarative collection control-flow features. Answer: show collection-for to filter inside a literal, collection-if for conditional items, and combine both in one expression. Red flag: imperative loops and add() instead of literal syntax.

Flutter & Dart2 min read

What problem does late solve in Dart?

Tests definite assignment and lazy init in null-safe Dart. Strong answers cover: deferred non-nullable field init, lazy final evaluation, and LateInitializationError on early access. Red flag: treating late as nullable or saying it bypasses null safety.

Flutter & Dart2 min read

Describe Dart's null-aware ?. and null assertion ! operators

Tests Dart null safety mechanics: ?. short-circuits member access on null, while ! casts away nullability. A strong answer notes ?. avoids NPEs and ! is a risky opt-out. Red flag: claiming ! is safe or that ?. provides a default value.

Flutter & Dart2 min read

Explain Dart positional vs named parameters and write one signature

Tests Dart parameter syntax. A strong answer covers required positional args, optional positional args in square brackets, and named args in curly braces with defaults. Red flag: claiming named parameters are always optional or confusing bracket types.

Flutter & Dart2 min read

What is the difference between final and const in Dart?

Tests compile-time versus runtime immutability in Dart. A strong answer: final allows single assignment at runtime, but const requires a compile-time constant and deep immutability.

Flutter & Dart2 min read

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.

Flutter & Dart2 min read

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.

Flutter & Dart2 min read

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 & Dart2 min read

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.

Get Dart bites daily.

Five a day, five minutes, offline. With quizzes so it sticks.

Open testing — you’ll join as an early tester.