Skip to content
tezvyn:

All bites

The whole library, newest first. Filter by what you are here for, or pick a topic if you already know.

4330 bites

Page 8

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.

Explain Dart's event loop, microtask queue, event queue, and await behavior
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

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

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

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

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

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.

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

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

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

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.

Describe the Dart event loop and queue execution order
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

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

Fetch user profiles concurrently and handle individual failures

Tests Future.wait concurrency and per-future error isolation. Answer: map IDs to fetchProfile, pass to Future.wait. For partial failures, attach catchError per future to return null, then filter. Red flag: try-catch around Future.wait or sequential awaits.

Flutter & Dart2 min read

Explain StreamController, write a broadcast stream example, and why close it?

This tests Dart stream lifecycle and memory safety. A strong answer uses StreamController.broadcast(), adds data and errors, closes it, and explains unclosed controllers leak memory.

Flutter & Dart2 min read

Explain StatelessWidget vs StatefulWidget and when to choose each

This tests immutable UI versus persistent state. StatelessWidget rebuilds when config changes; StatefulWidget owns State surviving rebuilds. Use StatelessWidget for static UI and StatefulWidget for interactive elements.

Flutter & Dart2 min read

What is the build method's purpose and key constraints?

It returns a Widget tree, can run every frame, must avoid side effects, and uses BuildContext for inherited data.

Flutter & Dart2 min read

Relationship between Widget, Element, and RenderObject trees and their benefits

Widget configures, Element owns state, RenderObject paints; Element.update reuses the RenderObject, so rebuilds stay cheap.

Flutter & Dart2 min read

What is BuildContext? Give two tree-interaction examples.

Tests if you know BuildContext is an Element handle to a widget's tree location. Strong answers cite Theme.of and Scaffold.of as ancestor lookups, explain the own-context trap, and warn against caching across async gaps. Red flag: calling it the widget itself.

Flutter & Dart2 min read

How can you prevent unnecessary child rebuilds in Flutter?

Tests your grasp of Flutter build-boundary isolation. Strong answers hit const constructors, extracting the child into its own widget, and granular state selectors. Red flag: saying Keys alone stop rebuilds or recommending RepaintBoundary to skip builds.