All bites
The whole library, newest first. Filter by what you are here for, or pick a topic if you already know.
8664 bites
Page 14
Dart's Cascade Notation: Chain Calls on One Object
Cascade notation (..) lets you perform a sequence of operations on the same object without repeating its name. It's ideal for configuring new instances in one block.
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.
Dart's async/await: Non-Blocking Code That Reads Synchronously
Dart's async/await makes non-blocking code read like a simple script. Use it for network requests or file I/O to keep your UI from freezing. The biggest footgun is calling an async function but forgetting to await its Future result.
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.
Dart Generics: Type-Safe Containers and Reusable Code
Generics let you define code that works with multiple types without sacrificing type safety. A List<String> is a list that only accepts strings. This is essential for collections.
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.
Dart Streams: Asynchronous Data Sequences
A Dart Stream is like a conveyor belt for asynchronous data, delivering events or file chunks as they arrive. Use them for continuous data flows like button clicks or reading large files.
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.
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.
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.
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.
Static Members: Belong to the Class, Not the Instance
A static member is shared across all instances of a class, belonging to the class itself. Use it for constants or utility functions that don't depend on an instance's state, like a global counter. The footgun: you cannot use this inside a static context.
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.
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.
Dart's Lazy Iterable Methods: map() and where()
Think of map() or where() not as instant transformations, but as recipes for a new list. They're lazy, only doing work when you iterate. Use them to chain operations without creating intermediate lists.

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.
Dart's Specialized Constructors: Named, Factory, and Constant
Dart constructors offer more than one way to create an object. Use named constructors for clarity (e.g., fromJSON), factory for caching or returning subtypes, and const for compile-time constant objects.
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.
Dart: Abstract Classes & Implicit Interfaces
An abstract class is a blueprint that other classes must follow, but it can't be instantiated itself. Dart also lets any class act as an 'implicit interface,' forcing other classes to implement its public API without inheritance.
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.