More in Flutter & Dart — page 5
Purpose of factory fromJson constructor in Dart models
WHAT IT TESTS: Why factory constructors separate parsing from creation. ANSWER OUTLINE: Factory fromJson centralizes deserialization, preprocesses Map values before instantiation, and keeps the primary constructor clean.
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
WHAT IT TESTS: Your grasp of Flutter gesture disambiguation beyond widgets. A GOOD ANSWER OUTLINES: the arena opens on pointer down; recognizers accept or reject; the last accepted member wins. RED FLAG: 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.
How do you retrieve and listen to TextField changes in Flutter?
WHAT IT TESTS: Flutter input state and lifecycle hygiene. ANSWER OUTLINE: Use TextEditingController, attach to TextField, listen with addListener, read controller.text, dispose in State.dispose. RED FLAG: Citing onChanged as standard or forgetting disposal.
Handle taps on a non-button Container: GestureDetector vs InkWell
This tests gesture propagation and Material feedback. Use GestureDetector for raw taps, drags, or scales; InkWell for Material ripples, which needs a Material ancestor. Red flag: InkWell without Material or ignoring GestureDetector drag support.