Flutter
294 bites tagged Flutter — interview questions with model answers, and 60-second explainers.
Why are stale search requests problematic and how do you cancel them?
This tests race conditions and resource waste in async UI. Strong answers note stale requests waste bandwidth and overwrite newer results; cancel the previous call with a CancelToken before issuing the next.
Implement an API caching layer with offline support and storage trade-offs
Use in-memory for hot data and disk for offline, pick Hive or SQLite by shape, and use TTL with a sync queue. Designing a tiered cache for speed and resilience. Ignoring invalidation or treating all data identically.
Explain Dio interceptors and automatic token refresh
Define interceptors as hooks; queue concurrent 401s during refresh; retry with Bearer header via token manager. Stateful middleware and async orchestration. Synchronous refresh or refresh storms.
How would you manage network request state in a Flutter widget?
This tests whether you separate ephemeral widget state from business logic. A good answer defines a state class, uses setState in initState, then shows how a library moves logic out for testing and reuse. Red flag: fetch inside build or using boolean flags.
Compare manual JSON serialization versus json_serializable
It tests build automation versus manual control in Dart serialization. Manual methods avoid build steps but risk drift; code generation cuts boilerplate but adds compile latency. Claiming code gen slows runtime or that manual is always simpler.
Describe a robust error handling strategy for network requests
Tests whether you classify failures by layer rather than catching everything generically. Inspect DioExceptionType for connectivity, check HTTP status before parsing, and isolate JSON decode errors. Never show the same message for timeouts and 500s.
Purpose of factory fromJson constructor in Dart models
Factory fromJson centralizes deserialization, preprocesses Map values before instantiation, and keeps the primary constructor clean. Why factory constructors separate parsing from creation.
Explain FutureBuilder and how it manages async UI states
This tests declarative async UI state management. Obtain the Future before build, pass it to FutureBuilder, and branch on snapshot.connectionState and hasError to render loading, data, or error states.
Make a GET request with http and parse JSON in Dart
Practical Dart async networking with package:http and dart:convert. Import http, await get(Uri.parse(url)), verify statusCode is 200, then jsonDecode(response.body) as List<Map<String, dynamic>>. Skipping status checks or decoding without a cast.
Explain lifting state up in Flutter and how Provider simplifies it
Tests declarative state ownership and prop-drilling cost. A strong answer names the lowest common ancestor, contrasts callback threading with Provider lookup, and avoids root-level state.
How do you manage product list and favorite state without full rebuilds?
This tests granular rebuild control in Flutter lists. A strong answer isolates item state with ValueNotifier or ChangeNotifier per item plus const constructors with keys. Red flag: calling setState on the parent list rebuilds every ListTile on each tap.
Difference between context.watch, context.read, and Selector in Provider and Riverpod
Tests rebuild granularity in Flutter. A strong answer distinguishes listening versus one-time lookup, explains that Selector filters rebuilds by comparing sub-values, and warns that context.read inside build causes missed updates.
Explain ephemeral vs app state and when to use setState
This tests state scoping judgment. Ephemeral state is local to one widget, like a page index or checkbox value, and setState fits perfectly. App state is shared, like a user profile or cart, and needs a state management solution.
Custom fade-and-scale transition with PageRouteBuilder and GoRoute
Tests bridging imperative transitions to declarative routers. Use PageRouteBuilder with FadeTransition and ScaleTransition, set globally in theme or per route via GoRoute pageBuilder with CustomTransitionPage. Red flag: omitting child rebuilds the page.
Implement a GoRouter path parameter route and access userId in a widget
This tests GoRouter declarative routing and GoRouterState. Define a GoRoute with path '/users/:userId', read state.params['userId'] in the builder, and handle null-safety. A red flag is parsing the URI manually or using ModalRoute.of instead of state.params.
Explain the core responsibilities of RouterDelegate, RouteInformationParser, and Router in Flutter
Tests Navigator 2.0 architecture split. RouteInformationParser converts URLs to typed config; RouterDelegate owns state and builds the Navigator; Router wires them together and handles engine intents. Red flag: conflating parsing and state or omitting Router.
Navigator.push vs Navigator.pushNamed in Flutter
Tests Flutter navigation patterns and scalability. A strong answer contrasts inline widget construction with centralized route tables, noting pushNamed centralizes routes but complicates type-safe data. Red flag: named routes are always better for large apps.
How do you pass data with Navigator.push and return data with Navigator.pop?
Tests imperative navigation and async result patterns. Strong answer: push via MaterialPageRoute with constructor args; await the Future from Navigator.push; pop with Navigator.pop(context, result). Red flag: using global state instead of the Future result.
Explain Flutter's GestureArena and overlapping detector scenario
The arena opens on pointer down; recognizers accept or reject; the last accepted member wins. Your grasp of Flutter gesture disambiguation beyond widgets. Claiming depth or z-order alone decides the winner.
Implement efficient async username validation in Flutter
Tests async field hygiene in Flutter. Outline: debounce 300ms, cancel inflight requests, decouple loading UI from errors, use reactive_forms async validators or manual streams. Red flag: API calls per keystroke without cancellation, loading treated as errors.
What gesture conflict exists in a scrollable list with horizontal swipes?
Tests Flutter's gesture arena and slop disambiguation. Diagonal motion triggers both vertical scroll and horizontal swipe; the axis whose delta exceeds touch slop first wins the arena. Red flag: claiming Flutter blocks inner gestures or fires both at once.
What is a FocusNode and why is it useful in forms?
This tests your understanding of Flutter's imperative focus tree. A strong answer defines FocusNode as a persistent focus target, explains programmatic form navigation, and stresses initState creation and dispose.
Build and validate a login form with Form and GlobalKey
This tests Flutter's declarative form validation. A strong answer covers wrapping fields in a Form, using a GlobalKey<FormState>, calling validate on submit, and acting only on true.
Explain the validator property in TextFormField and what triggers error display
Tests Form validation lifecycle knowledge. Strong answer: validator returns String? error or null; formKey.currentState.validate() triggers all fields; returned string renders as inline error.
Get Flutter bites daily.
Five a day, five minutes, offline. With quizzes so it sticks.
Open testing — you’ll join as an early tester.