Expert · Flutter careers and interviews · topic 48 of 50 · 35 min
Interview questions: Dart
Explanation
How to answer
Interviewers want understanding, not memorised lines. A strong structure: define it in one sentence, say why it exists, give a two-line example (ideally from your own project), and mention one pitfall. Practise aloud; clear explanation is a skill you can train.
Q1. final versus const?
Model answer: "Both create variables that cannot be reassigned. final is set once at run time, for example final now = DateTime.now(). const must be known at compile time and makes the value deeply immutable and canonical, so identical const objects are shared. In Flutter, const widgets are created once and can be skipped during rebuilds."
Q2. Explain null safety and its operators.
Model answer: "Since Dart 3, null safety is sound and always on: String cannot be null, String? can. I handle nullable values with ?. for safe access, ?? for defaults, ??= to assign if null, and flow analysis after a null check. ! asserts non-null and throws if wrong, so I avoid it. late defers initialisation, and required forces named parameters."
Q3. Future versus Stream?
Model answer: "A Future delivers one value or error later, such as an HTTP response. A Stream delivers many values over time, such as Firestore snapshots or live scores. I await Futures and listen to Streams or use await for; in Flutter I use FutureBuilder and StreamBuilder, and I cancel subscriptions in dispose."
Q4. How does async/await work if Dart is single-threaded?
Model answer: "Each isolate runs an event loop on one thread. await pauses only the current function and returns control to the event loop, which keeps processing other events like taps and frames. When the awaited Future completes, the function resumes. Waiting does not block, but heavy CPU work still does, so I use Isolate.run or compute for that."
Q5. What is an isolate?
Model answer: "An isolate is Dart's unit of concurrency: its own memory and event loop. Isolates do not share memory and communicate by messages, so there are no data races. I use Isolate.run for heavy work like parsing a huge JSON, so the UI isolate keeps rendering smoothly."
Q6. Mixin versus inheritance versus interface?
Model answer: "extends inherits code from one parent (is-a). implements promises the interface of a class without inheriting code, useful for fakes in tests. A mixin with with adds reusable behaviour to unrelated classes, and a class can use several mixins; SingleTickerProviderStateMixin is a Flutter example."
Q7. What are factory constructors and extension methods?
Model answer: "A factory constructor runs code before deciding what to return: it can validate input, return a cached instance or a subtype; fromJson constructors are often factories. Extension methods add methods to existing types like String or BuildContext without changing them; they are resolved statically."
Q8. Dart 3: records, patterns and sealed classes?
Model answer: "Records group a few values without a class, like returning (each, left) from splitBill. Patterns destructure values in switch, if-case and declarations, and can check JSON shapes safely. A sealed class has a fixed set of subtypes in its library, so a switch over it is exhaustive; I use it for UI states like Loading, Success and Error."
Common interview mistakes
- Saying async makes code run on another thread. It does not.
- Confusing final and const, especially for objects.
- Answering without an example.
- Claiming ! is fine "because the value is never null". Show a safe alternative.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
Interview questions: Dart · 1/6
Answer with a definition, the reason, a tiny example and one pitfall.
Prefer a video by a teacher? Find free videos on “dart interview questions flutter null safety future stream isolate mixin” on YouTube ↗
In real life: A typical output question
Interviewers often show a short snippet and ask what it prints. Talk through each step out loud. Here: a is null, so a?.length is null and ?? gives 0; b gets 5 because it was null; the list keeps only values greater than 1.
void main() {
String? a;
int? b;
b ??= 5;
final total = (a?.length ?? 0) + b;
final list = [1, 2, 3].where((n) => n > 1).toList();
print('$total $list'); // 5 [2, 3]
}Practice (0/3 done)
An interviewer asks: "Does async/await run code on a background thread?" Best answer?
What does this print? final r = (2, 'two'); final (n, w) = r; print('$w$n');
Record yourself answering Q1 to Q8 from this topic, each in under a minute, with an example from your own code. Listen back, mark weak answers, rewrite two of them and record again.
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Interview questions: FlutterFlutter careers and interviews · same module
- Portfolio and next stepsFlutter careers and interviews · same module
- Interview questions: KotlinKotlin and Android App Development · Android career path
- Interview questions: ownership, borrowing and lifetimesRust Programming · Rust careers and interviews
- Classes and constructorsNull safety and object-oriented Dart
- Interview questions: traits, errors, pointers and concurrencyRust Programming · Rust careers and interviews
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
Which keyword creates a compile-time constant?
Answer: const
const values are known at compile time.
What does an isolate NOT share with other isolates?
Answer: Memory
Isolates communicate by messages.
Which Dart 3 feature makes a switch over UI states exhaustive?
Answer: Sealed classes
All subtypes are known.
Which constructor type can return a cached instance?
Answer: factory
Factories decide what to return.
When is a sealed interface better than an enum?Related
Answer: When cases carry different data
Subtypes can hold their own data.
How many classes can a Dart class extend?Related
Answer: One
Single inheritance; many interfaces and mixins.
Why does thread::spawn require 'static data?Related
Answer: The thread may outlive any borrowed local data
Spawned threads can run after the caller returns.
From Interview questions: ownership, borrowing and lifetimes
Does await block the whole Dart program?Related
Answer: No, it pauses only the current function while the event loop keeps working
Other events continue.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 2 more topics in “Flutter careers and interviews” before its exam: Interview questions: Flutter, Portfolio and next steps.
- Module 12 exam: Flutter careers and interviews · 10 questions · 20 min, without help. 4 topics of this module still to finish first.
- 50 topics left in the course before the final exam.