Skip to content
tezvyn:

Dart

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

Flutter & Dart1 min read

Dart reduce versus fold on collections

Reduce combines same-type elements and throws on empty; fold takes an initial value and accumulator of any type, safe on empty. choosing the right aggregation. using reduce when the result type differs from the elements.

Flutter & Dart2 min read

Classic BLoC with Streams and Sinks

Classic BLoC separates UI from business logic by exposing inputs as Sinks and outputs as Streams. The widget pushes events into sinks, the BLoC processes them, and emits new state on streams that the UI rebuilds from, keeping logic testable and…

Flutter & Dart2 min read

Propose a Dart FFI approach to share camera frames and its risks

Tests zero-copy frame sharing via Dart FFI plus ownership and thread hazards. Propose native allocation, pass pointer to Dart as external TypedData, use ring buffer, then free; cite use-after-free and races.

Flutter & Dart2 min read

Structure a POST request to send a Dart object as JSON

Set Content-Type application/json, serialize to Map via toJson, encode with dart:convert jsonEncode, and pass the string as body. Your grasp of HTTP semantics and Dart serialization.

Flutter & Dart2 min read

Riverpod providers are objects, not widgets. What are the practical advantages?

Tests architectural decoupling of state and UI in Flutter. Strong answers hit compile-time safety, unit testing without widget trees, and logic that survives outside BuildContext. Red flag: praising syntax sugar without explaining the coupling problem.

Flutter & Dart2 min read

Design an immutable UserSettings class with copyWith for Flutter state

Tests immutability as Flutter's state foundation. A great answer shows final fields, a const constructor, copyWith with nullable named params and null-aware fallback, and explains how immutability prevents accidental shared mutations during rebuilds.

Flutter & Dart2 min read

Explain map() vs where() on a List and chain them

This tests Dart Iterable laziness and correct chaining. A strong answer states where filters and map transforms, both return Iterables, then chains where before map and converts with toList. A red flag is claiming the original list mutates or omitting toList.

Flutter & Dart2 min read

Explain the difference between tester.pump and tester.pumpAndSettle

This tests your grasp of Flutter frame scheduling. pump draws one frame; pumpAndSettle loops until idle, failing on infinite animations. A red flag is treating pumpAndSettle as universally safe or missing why a loading spinner causes timeouts.

Flutter & Dart2 min read

Persist a custom Dart object using shared_preferences

Tests JSON serialization bridging custom objects to primitive-only key-value storage. Strong answer: add toJson/fromJson on User, jsonEncode into SharedPreferences as String, jsonDecode on read. Red flag: proposing direct storage or toString hacks.

Flutter & Dart2 min read

How do you synchronize app state with GoRouter navigation?

Read auth state in top-level redirect; rebuild GoRouter via refreshListenable on changes; handle deep links in page builders. declarative routing and state-driven redirects.

Flutter & Dart2 min read

How do you handle CPU-bound tasks without freezing the Flutter UI?

Tests whether you know async/await yields for I/O but cannot parallelize CPU work. A strong answer defines Isolates as isolated heaps with message-passing, contrasts them with threads, and shows how compute() wraps Isolate.spawn.

Flutter & Dart2 min read

How do you test Flutter platform channels and mock native responses?

Tests MethodChannel mocking in widget tests. Strong answers intercept calls via TestDefaultBinaryMessengerBinding, encode replies with StandardMessageCodec, pump the widget, and assert UI state.

Flutter & Dart2 min read

Compare sqflite and Drift: trade-offs and when to choose Drift

This tests Flutter persistence trade-offs. Contrast sqflite's raw maps and raw SQL with Drift's typed code, streams, and migrations; choose Drift for complex schemas or web targets. Red flag: calling Drift bloat or claiming raw sqflite is always faster.

Flutter & Dart2 min read

Fix UI jank from file reads and SQLite inserts using Isolates

This tests whether you know heavy synchronous work blocks Dart's UI event loop past the 16ms frame budget. A strong answer offloads parsing and SQLite inserts to a worker isolate via compute, returning results.

Flutter & Dart2 min read

Describe the BLoC pattern: Events, States, and widget connection

Tests UI-business separation. Strong answers cast Events as user intents, States as immutable snapshots, and BLoC as a pure reducer. Widgets listen via BlocBuilder and dispatch via context.read. Red flag: mutating state directly or using setState inside BLoC.

Flutter & Dart2 min read

What is a Dart Completer and when should you use it?

This tests bridging callback APIs into Dart's Future ecosystem. An answer defines Completer as a manual Future producer, explains completing with value or error from callbacks, preferring Future() when possible. A red flag is using Completer for simple async.

Flutter & Dart2 min read

How would you implement debounce for a search input using Streams?

This tests Stream transformation and event throttling. A strong answer outlines a resetting timer that only emits after 300ms of silence, referencing debounceTime or DebounceStreamTransformer. Red flag: manual Timer juggling without Stream composition.

Flutter & Dart2 min read

What is Flutter tree shaking and how does it reduce app size?

Tests Dart AOT dead code elimination. Covers compile-time dead code removal, smaller binaries, faster startup, and practices like avoiding dart:mirrors and using const constructors. Red flag: confusing it with minification or runtime stripping.

Flutter & Dart2 min read

What is a Dart Isolate and how does it differ from threads?

Tests Dart's shared-nothing concurrency model. Define an isolate as an independent heap plus event loop, contrast it with shared-memory threads, and explain UI isolate communication via async message ports.

Flutter & Dart2 min read

Why use const for Flutter widgets and how does it improve performance?

Tests widget canonicalization and rebuild short-circuiting. Strong answer: const enables instance reuse and skips subtree rebuilds on parent updates, reducing allocations.

Flutter & Dart2 min read

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.

Flutter & Dart2 min read

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.

Flutter & Dart2 min read

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.

Flutter & Dart2 min read

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.

Get Dart bites daily.

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

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