Flutter MCQ
Test your Flutter & Dart knowledge with 100 multiple choice questions covering widgets, state management, navigation, async patterns, animations, testing, and platform channels.
How This Practice Test Works
Every question below expands right on this page — click a question to reveal its four options, pick the one you think is correct, and you'll get instant feedback along with the correct answer and a short explanation of the reasoning. Questions are grouped by difficulty, so start with the 41 beginner questions to confirm your fundamentals, work through the 39 intermediate ones, and finish with the 20 advanced questions that mirror what exams and technical screenings actually ask. There's no sign-up, no timer, and no limit — retake the test as often as you like.
Curated by Tech Baithak Editorial Team · Last updated: June 2026
1
What is Flutter?
Correct Answer
Google's open-source UI toolkit for building natively compiled applications for mobile, web, and desktop from a single codebase
Explanation
Flutter is Google's open-source UI toolkit that allows developers to build natively compiled applications for mobile, web, and desktop from a single Dart codebase. It uses its own rendering engine (Skia/Impeller) to draw widgets.
2
Which programming language is used to write Flutter applications?
Correct Answer
Dart
Explanation
Flutter applications are written in Dart, a language developed by Google. Dart is strongly typed, supports both AOT and JIT compilation, and has a syntax familiar to Java and JavaScript developers.
3
What is the basic building block of a Flutter UI?
Correct Answer
Widget
Explanation
In Flutter, everything is a Widget. Widgets are the basic building blocks of the Flutter UI — from layout elements like Row and Column to interactive elements like Button and TextField.
4
What is the key difference between StatelessWidget and StatefulWidget?
Correct Answer
StatelessWidget has no mutable state; StatefulWidget has a mutable State object that can trigger rebuilds
Explanation
StatelessWidget describes a part of the UI that does not depend on any mutable state. StatefulWidget is paired with a State object that holds mutable data and can trigger rebuilds by calling setState().
5
What does setState() do in a StatefulWidget?
Correct Answer
It notifies Flutter that internal state has changed and schedules a rebuild of the widget
Explanation
Calling setState() inside a StatefulWidget tells the Flutter framework that the internal state of this object has changed. Flutter will then schedule a call to the build() method to update the UI with the new state.
6
What is pubspec.yaml in a Flutter project?
Correct Answer
The configuration file that defines project metadata, dependencies, and assets
Explanation
pubspec.yaml is the project configuration file for a Flutter/Dart project. It defines the project name, version, dependencies (packages), dev_dependencies, and asset paths (images, fonts, etc.).
7
What widget is typically the root of a Flutter Material Design app?
Correct Answer
MaterialApp
Explanation
MaterialApp is typically the root widget of a Flutter Material Design application. It configures the top-level Navigator, theme, routes, and locale settings for the entire app.
8
What does the Scaffold widget provide in Flutter?
Correct Answer
A basic Material Design visual layout structure with AppBar, body, FAB, drawer, and bottom navigation
Explanation
Scaffold implements the basic Material Design visual layout structure. It provides slots for AppBar, body, floatingActionButton, drawer, bottomNavigationBar, snackBar, and more.
9
What is the difference between Hot Reload and Hot Restart in Flutter?
Correct Answer
Hot Reload injects updated code and preserves app state; Hot Restart restarts the Dart VM and loses state
Explanation
Hot Reload injects updated source code into the running Dart VM and rebuilds the widget tree while preserving state. Hot Restart fully restarts the Dart VM, losing all current state but picking up new initializations like changed global variables.
10
What is BuildContext in Flutter?
Correct Answer
A handle to the location of a widget in the widget tree, used to find themes, navigate, and access inherited data
Explanation
BuildContext is a handle to the location of a widget in the widget tree. It is used to look up inherited widgets (like Theme), show dialogs, navigate, and access data that is propagated down the widget tree.
11
Which widget arranges its children in a vertical direction?
Correct Answer
Column
Explanation
The Column widget arranges its children along the vertical axis (top to bottom). Its counterpart, Row, arranges children along the horizontal axis. Both use MainAxisAlignment and CrossAxisAlignment properties.
12
Which widget arranges its children in a horizontal direction?
Correct Answer
Row
Explanation
The Row widget lays out its children in a horizontal array. You can control spacing and alignment using mainAxisAlignment and crossAxisAlignment properties on the Row.
13
What does the Container widget do in Flutter?
Correct Answer
A convenience widget that combines painting, positioning, and sizing of its child
Explanation
Container is a convenience widget that combines common painting, positioning, and sizing widgets. It can apply padding, margins, colors, borders, and box shadows, and can also constrain or size its child widget.
14
How do you display text in Flutter?
Correct Answer
Text widget
Explanation
The Text widget displays a string of text with a single style. You can customize the font, size, color, alignment, and overflow behavior using TextStyle and other properties of the Text widget.
15
Which widget is used to add space/padding inside another widget's boundaries?
Correct Answer
Padding
Explanation
The Padding widget insets its child by the given padding specified via EdgeInsets (e.g., EdgeInsets.all(8.0) or EdgeInsets.symmetric(horizontal: 16)). Container can also apply padding via its padding property.
16
What does the Center widget do in Flutter?
Correct Answer
Centers its child both horizontally and vertically within the available space
Explanation
The Center widget centers its child both horizontally and vertically within itself. It expands to fill the available space from its parent and places its child in the middle.
17
What does the Expanded widget do inside a Row or Column?
Correct Answer
It makes the child widget take up all remaining available space along the main axis
Explanation
Expanded expands a child of a Row, Column, or Flex to fill the available space along the main axis. If multiple children are expanded, the space is divided proportionally according to their flex factors.
18
Which class is used to navigate between screens in Flutter?
Correct Answer
Navigator
Explanation
Navigator manages a stack of Route objects and provides methods for navigating between screens. Navigator.push() adds a route to the stack and Navigator.pop() removes the top route to go back to the previous screen.
19
How do you navigate to a new screen in Flutter using the imperative API?
Correct Answer
Navigator.push(context, MaterialPageRoute(builder: (ctx) => NewScreen()))
Explanation
To navigate to a new screen in Flutter, you use Navigator.push() with a MaterialPageRoute. The builder callback returns the widget to display on the new screen. Navigator.pop() takes you back.
20
What is a Future in Dart?
Correct Answer
An object representing a value or error that will be available at some point in the future
Explanation
A Future in Dart represents a potential value or error that will be available at some time in the future. It is the basis of asynchronous programming in Dart — similar to a Promise in JavaScript.
21
What keyword pauses execution inside an async function until a Future completes?
Correct Answer
await
Explanation
The await keyword pauses the execution of an async function until the Future it is waiting on completes, then resumes with the result. The function must be marked with the async keyword to use await.
22
What widget provides a scrollable list of items in Flutter?
Correct Answer
ListView
Explanation
ListView is a scrollable, linear list of widgets. For large or infinite lists, use ListView.builder() which lazily builds items on demand rather than building all items upfront into memory.
23
Which widget detects touch gestures like tap, double tap, and long press?
Correct Answer
GestureDetector
Explanation
GestureDetector is a widget that detects gestures without any visual feedback. It has callbacks for tap, double tap, long press, pan, scale, and more. For Material ink ripple feedback, use InkWell instead.
24
What is a FloatingActionButton (FAB) in Flutter?
Correct Answer
A circular button that floats above content, typically used for the primary action on a screen
Explanation
FloatingActionButton is a circular icon button that hovers over content. Per Material Design guidelines, it represents the primary action of a screen and is placed in Scaffold via the floatingActionButton parameter.
25
What does the AppBar widget display in Flutter?
Correct Answer
A toolbar at the top of the screen with a title, leading icon, and action icons
Explanation
AppBar displays a Material Design app bar — a toolbar at the top of the screen. It typically shows the page title, a leading icon (back button or hamburger menu), and trailing action icons on the right.
26
What widget displays a row of tabs at the bottom for navigation between views?
Correct Answer
BottomNavigationBar
Explanation
BottomNavigationBar is a Material Design widget that displays a row of small widgets at the bottom for selecting among a small number of views (2-5 tabs). It is set in the Scaffold's bottomNavigationBar parameter.
27
What is a Drawer in Flutter?
Correct Answer
A panel that slides in from the side of the screen for navigation links
Explanation
A Drawer in Flutter is a Material Design panel that slides in from the edge of the screen. It is typically used for navigation — containing a header and a list of navigation items. Added to the Scaffold via the drawer parameter.
28
What widget is used to capture text input from the user?
Correct Answer
TextField
Explanation
TextField is the standard widget for accepting text input in Flutter. It can be configured with a TextEditingController, InputDecoration, keyboard type, validation, and focus handling via FocusNode.
29
What is the purpose of the Form widget in Flutter?
Correct Answer
To group multiple FormField widgets together for validation and save operations via a GlobalKey<FormState>
Explanation
The Form widget is a container for grouping FormField widgets (like TextFormField). It provides a GlobalKey<FormState> that allows calling validate(), save(), and reset() on all form fields at once.
30
What does the Card widget provide in Flutter?
Correct Answer
A Material Design card with rounded corners, elevation shadow, and a single child
Explanation
Card is a Material Design sheet with slightly rounded corners and an elevation shadow. It is used to display related information in a contained, visually distinct panel. It takes a single child, typically a Column or ListTile.
31
What does the Stack widget do in Flutter?
Correct Answer
Lays out its children on top of each other along the z-axis
Explanation
Stack allows you to overlay widgets on top of each other. Children can be positioned using Positioned widget. The last child in the children list appears on top. Useful for overlays, badges, and floating elements.
32
What is SizedBox primarily used for?
Correct Answer
To create a fixed-size box, commonly used as a spacing/gap widget
Explanation
SizedBox creates a fixed-size box. It is commonly used as a gap/spacer between widgets (e.g., SizedBox(height: 16)) or to give a specific width/height to a child. SizedBox.shrink() creates a zero-size invisible box.
33
Where is the entry point of a Flutter application?
Correct Answer
The main() function in lib/main.dart
Explanation
Every Flutter application starts with the main() function in lib/main.dart. Inside main(), you call runApp() with your root widget to attach it to the screen and start the Flutter rendering engine.
34
What does runApp() do in Flutter?
Correct Answer
It inflates the given widget and attaches it to the screen, starting the Flutter engine
Explanation
runApp() takes the given Widget and makes it the root of the widget tree. It inflates the widget and attaches it to the screen. The widget's build() method is called to produce the initial UI.
35
What does the build() method return in a Flutter widget?
Correct Answer
A Widget describing the part of the UI this widget represents
Explanation
The build() method must return a Widget. Flutter calls build() whenever the widget needs to be rendered or rebuilt (e.g., after setState()). It should be a pure function of the widget's properties and state.
36
What is the initState() lifecycle method used for in StatefulWidget?
Correct Answer
A lifecycle method called once when the State object is inserted into the widget tree for one-time initialization
Explanation
initState() is called exactly once when the State object is first created. It is the right place to perform one-time initialization: subscribing to streams, initializing AnimationControllers, or fetching initial data.
37
What is the dispose() lifecycle method used for in Flutter?
Correct Answer
Called when the State object is permanently removed; used to release resources like controllers and stream subscriptions
Explanation
dispose() is called when the State object is permanently removed from the tree. Override it to release resources acquired in initState(): TextEditingControllers, AnimationControllers, StreamSubscriptions, and FocusNodes.
38
What is the purpose of CrossAxisAlignment in a Column widget?
Correct Answer
It controls the horizontal alignment of children within the Column
Explanation
In a Column (vertical main axis), CrossAxisAlignment controls how children are aligned on the horizontal (cross) axis. Options: start, end, center, stretch, and baseline. mainAxisAlignment controls the vertical distribution.
39
Which widget is used to display a circular loading indicator?
Correct Answer
CircularProgressIndicator
Explanation
CircularProgressIndicator is a Material Design circular progress indicator (spinner). It can be determinate (with a value 0.0–1.0) or indeterminate (spinning indefinitely). LinearProgressIndicator provides a horizontal bar variant.
40
What does Image.network() do in Flutter?
Correct Answer
It displays an image loaded from a URL
Explanation
Image.network() displays an image loaded from a URL. Flutter downloads and caches the image. Other constructors: Image.asset() for bundled assets, Image.file() for local file images, and Image.memory() for in-memory bytes.
41
What is the Flexible widget and how does it differ from Expanded?
Correct Answer
Flexible allows the child to be smaller than available space; Expanded forces the child to fill all available space
Explanation
Both Flexible and Expanded use a flex factor to allocate space in Row/Column. Expanded forces the child to fill all allocated space. Flexible allows the child to be smaller — it can be its natural size if fit is FlexFit.loose.
1
What is the Provider package used for in Flutter?
Correct Answer
A state management solution that wraps InheritedWidget to expose objects down the widget tree
Explanation
Provider is a popular Flutter state management package that wraps InheritedWidget to make it simpler. It allows you to expose data (ChangeNotifier, Streams, etc.) to any widget in the tree without manually threading it through constructors.
2
What is InheritedWidget used for in Flutter?
Correct Answer
A base class for widgets that efficiently propagate information down the widget tree
Explanation
InheritedWidget propagates data down the widget tree without passing it through constructors. Descendants access it via BuildContext.dependOnInheritedWidgetOfExactType(). It is the foundation for Provider, Theme, and MediaQuery.
3
What does BLoC stand for in Flutter?
Correct Answer
Business Logic Component
Explanation
BLoC (Business Logic Component) is an architectural pattern that separates business logic from the UI. It uses Streams for inputs (events) and outputs (states), making the UI reactive and highly testable.
4
What does FutureBuilder do in Flutter?
Correct Answer
A widget that builds itself based on the latest snapshot of a Future, handling loading, error, and done states
Explanation
FutureBuilder takes a Future and a builder function, rebuilding the widget whenever the Future's state changes. The builder receives an AsyncSnapshot with connectionState (waiting/done/error) and the data or error.
5
What does StreamBuilder do in Flutter?
Correct Answer
A widget that rebuilds itself in response to new events emitted by a Stream
Explanation
StreamBuilder listens to a Stream and rebuilds its subtree whenever a new event is emitted. Useful for real-time data like Firestore updates, BLoC state streams, and WebSocket messages.
6
What is a GlobalKey used for in Flutter?
Correct Answer
Accessing a widget's State or RenderObject from outside its build method, and preserving identity across rebuilds
Explanation
GlobalKey uniquely identifies a widget in the entire app. It allows accessing a widget's State (GlobalKey<FormState> for form.validate()), its RenderObject size/position, or a specific widget across the tree.
7
What information does MediaQuery provide in Flutter?
Correct Answer
Device screen size, orientation, pixel density, text scale factor, and system UI insets (safe area)
Explanation
MediaQuery.of(context) returns a MediaQueryData object with: screen size (size.width/height), devicePixelRatio, textScaleFactor, padding (safe area insets for notches), and system UI visibility info.
8
What is ThemeData in Flutter?
Correct Answer
A class holding colors, typography, and component styles for the app, set in MaterialApp and accessed via Theme.of(context)
Explanation
ThemeData defines the visual properties of a Material app: color scheme, typography, button styles, input decoration themes, and more. It is set in MaterialApp's theme parameter and accessed anywhere via Theme.of(context).
9
What is the purpose of AnimationController in Flutter?
Correct Answer
To control an animation's duration, direction, and current value; drives Tween animations
Explanation
AnimationController generates values between 0.0 and 1.0 over a given duration. It can play forward, reverse, and repeat. It requires a vsync (TickerProvider) to sync with screen refresh, typically via SingleTickerProviderStateMixin.
10
What is a Tween in Flutter animations?
Correct Answer
An object that maps an AnimationController's 0.0–1.0 range to any interpolated range of values
Explanation
A Tween defines the range of values an animation produces. Tween<double>(begin: 0, end: 300) maps 0.0–1.0 to 0–300. You can tween Colors, Offsets, sizes, and custom types using the animate() method with an AnimationController.
11
What is a Hero animation in Flutter?
Correct Answer
A shared element transition where a widget visually flies between two screens with matching tag values
Explanation
Hero animations create shared element transitions between routes. Wrap a widget in Hero(tag: 'myTag') on both screens. Flutter smoothly animates it between the two routes when navigating. Tags must match exactly on both screens.
12
What is the main difference between ListView and ListView.builder?
Correct Answer
ListView builds all children at once; ListView.builder lazily builds only visible items on demand
Explanation
ListView takes a children list and builds all widgets upfront — suitable for small, fixed lists. ListView.builder lazily builds only the visible items using an itemBuilder function. This makes it memory-efficient for long or infinite lists.
13
What is GridView.builder in Flutter?
Correct Answer
A lazily-built scrollable 2D grid that creates items on demand using a gridDelegate for layout
Explanation
GridView.builder lazily builds grid items. SliverGridDelegateWithFixedCrossAxisCount specifies fixed column count; SliverGridDelegateWithMaxCrossAxisExtent specifies max item width. Great for photo galleries and product grids.
14
What is the shared_preferences package used for?
Correct Answer
Storing simple key-value pairs persistently on the device (user preferences, settings)
Explanation
The shared_preferences package provides persistent key-value storage. It wraps NSUserDefaults on iOS and SharedPreferences on Android. It supports String, int, double, bool, and List<String> values.
15
What is a MethodChannel in Flutter?
Correct Answer
A channel enabling asynchronous method calls between Flutter Dart code and native platform code (Android/iOS)
Explanation
MethodChannel enables communication between Flutter (Dart) and native platform code (Kotlin/Java on Android, Swift/ObjC on iOS). Call invokeMethod() from Dart and register a MethodCallHandler in the native layer.
16
What is the difference between final and const in Dart?
Correct Answer
final is set once at runtime; const is a compile-time constant — both are immutable after assignment
Explanation
final variables are assigned once (runtime) and cannot change. const variables are compile-time constants — values must be known at compile time. const also makes objects deeply immutable and enables object canonicalization.
17
What is a mixin in Dart?
Correct Answer
A way to reuse code in multiple class hierarchies without using traditional inheritance
Explanation
Mixins in Dart allow code reuse across class hierarchies using the with keyword. Unlike single inheritance, a class can use multiple mixins. Mixins cannot have constructors. Common Flutter examples: SingleTickerProviderStateMixin, WidgetsBindingObserver.
18
What is SingleChildScrollView used for in Flutter?
Correct Answer
Making a single-child widget scrollable when content overflows the available space
Explanation
SingleChildScrollView makes a single child widget scrollable. It is ideal when screen content might overflow (e.g., a form on a small screen). For large item lists, prefer ListView.builder for better performance.
19
What does LayoutBuilder provide in Flutter?
Correct Answer
A widget that provides the parent's constraints to the builder, enabling responsive layouts
Explanation
LayoutBuilder provides the parent widget's constraints (maxWidth, maxHeight, etc.) to the builder function, allowing different UIs based on available space. This is the primary tool for building responsive Flutter layouts.
20
What is the Riverpod package in Flutter?
Correct Answer
A state management library that improves on Provider with compile-time safety, global providers, and no BuildContext requirement
Explanation
Riverpod is a state management library from the same author as Provider. Improvements include: providers are global (no context needed), compile-time safe, testable, and support async out of the box with AsyncValue.
21
What is an Isolate in Dart/Flutter?
Correct Answer
An independent worker with its own memory heap; Dart's unit of concurrency with no shared memory
Explanation
Dart Isolates are independent workers that run concurrently with their own memory. Unlike threads, they do not share memory — they communicate via SendPort/ReceivePort message passing. Use compute() for a simple one-off Isolate.
22
What is CustomPainter used for in Flutter?
Correct Answer
Drawing custom graphics directly onto a Canvas inside a CustomPaint widget
Explanation
CustomPainter allows drawing directly on a Canvas via the CustomPaint widget. Implement paint() to draw shapes, paths, images, and text. shouldRepaint() controls when the painting should re-execute.
23
What is the Equatable package used for in Flutter?
Correct Answer
Automatically overriding == and hashCode based on props, enabling value equality — heavily used with BLoC states
Explanation
Equatable overrides == and hashCode based on a props list you define, enabling value equality without boilerplate. It is widely used in BLoC to prevent duplicate state emissions when the state's values have not actually changed.
24
What is the key difference between InkWell and GestureDetector?
Correct Answer
InkWell shows a Material ink splash ripple effect on tap; GestureDetector detects gestures without any visual feedback
Explanation
GestureDetector detects gestures with no visual feedback. InkWell extends this with Material Design ink ripple animations on tap. Use InkWell inside Material widgets for visual feedback; use GestureDetector when you control the visual response yourself.
25
What is the sqflite package in Flutter?
Correct Answer
A SQLite plugin for Flutter supporting local relational database storage on Android and iOS
Explanation
sqflite is a Flutter plugin for SQLite, enabling local relational database storage on Android and iOS. It supports SQL queries, transactions, and batch operations. For desktop/web support, consider the drift package.
26
What is Dart's null safety feature?
Correct Answer
A compile-time type system feature distinguishing nullable (String?) from non-nullable (String) types, preventing null errors at compile time
Explanation
Dart's sound null safety means types are non-nullable by default. You must explicitly declare nullable types with ? (e.g., String?). This eliminates null reference exceptions at compile time and improves app reliability.
27
What is a factory constructor in Dart?
Correct Answer
A constructor that can return an existing instance, a subtype, or use logic before creating — not required to create a new instance
Explanation
A factory constructor uses the factory keyword and does not always create a new instance — it can return a cached instance, a subtype, or compute the value. Commonly used for singletons, fromJson() deserializers, and named constructors.
28
What is go_router in Flutter?
Correct Answer
An officially recommended declarative routing package with URL-based navigation, deep links, and named routes built on Navigator 2.0
Explanation
go_router is Flutter's officially recommended routing package. It provides declarative, URL-based navigation built on Navigator 2.0, with named routes, path parameters, query parameters, redirects, and deep linking support.
29
What is Hive used for in Flutter?
Correct Answer
A lightweight, fast key-value NoSQL database written in pure Dart — faster than shared_preferences for structured data
Explanation
Hive is a fast, lightweight key-value NoSQL database for Flutter/Dart. It is written in pure Dart (no native dependencies), supports custom objects via TypeAdapters, and is significantly faster than shared_preferences for larger or structured data.
30
What is an AnimatedBuilder widget used for?
Correct Answer
Rebuilding only the subtree that depends on an animation, keeping static parent widgets from rebuilding unnecessarily
Explanation
AnimatedBuilder rebuilds only the widget returned by its builder function when the animation changes. The optional child parameter lets you pass a static sub-widget that is built once and passed into the builder without rebuilding.
31
What is a Dart extension method?
Correct Answer
A way to add new methods, getters, or operators to existing types without subclassing or modifying the original class
Explanation
Dart extension methods allow you to add new functionality to existing types — even types you don't own — without subclassing. Defined with the extension keyword. Example: adding .isNullOrEmpty getter to String.
32
What is the Dio package used for in Flutter?
Correct Answer
A powerful HTTP client supporting interceptors, file upload/download, timeout, FormData, and cancellation
Explanation
Dio is a feature-rich HTTP client for Dart/Flutter. It supports interceptors (for auth headers, logging), request cancellation, file uploads/downloads, response caching, and FormData — making it more powerful than the basic http package.
33
What is a Completer in Dart?
Correct Answer
A class that allows manually controlling a Future — you create the Future and resolve it later with complete() or completeError()
Explanation
Completer<T> gives you control over a Future. You create one with Completer<T>(), expose completer.future, and later call completer.complete(value) or completer.completeError(error). Useful when adapting callback-based APIs to Futures.
34
What is the spread operator (...) used for in Dart?
Correct Answer
Inserting all elements of a collection into another collection literal
Explanation
The spread operator (...) inserts all elements of a List, Set, or Map into another collection literal. Example: [...list1, ...list2]. The null-aware spread (...?) safely handles nullable collections.
35
What is Navigator 2.0 (Router) in Flutter?
Correct Answer
A declarative, URL-driven navigation API using Router, RouteInformationParser, and RouterDelegate for deep linking and web URL sync
Explanation
Navigator 2.0 introduces a declarative navigation API: the Router widget, RouteInformationParser (parses URLs), and RouterDelegate (controls the page stack). It enables full deep link support and URL synchronization on Flutter web.
36
What is a NotificationListener widget in Flutter?
Correct Answer
A widget that listens for Notifications bubbling up the widget tree (like scroll events) and runs a callback
Explanation
NotificationListener<T> intercepts Notification objects (like ScrollNotification, OverscrollNotification) that bubble up through the widget tree. Return true from onNotification to stop the notification from propagating further.
37
What is the TextEditingController used for in Flutter?
Correct Answer
Reading, setting, and listening to changes in a TextField's text content and cursor position
Explanation
TextEditingController lets you read (controller.text), set (controller.text = '...'), and listen to changes in a TextField. Assign it to TextField's controller parameter. Always dispose it in dispose() to free resources.
38
What is the purpose of the WillPopScope widget in Flutter?
Correct Answer
Intercepting the Android back button or navigation pop gesture to run custom logic or confirm before leaving the screen
Explanation
WillPopScope wraps a route and intercepts pop events (Android back button, navigation gesture). The onWillPop callback returns a Future<bool> — returning false prevents the pop. In Flutter 3.12+, prefer PopScope with canPop and onPopInvoked.
39
What is a CustomScrollView in Flutter?
Correct Answer
A scroll view that takes a list of Slivers as children, allowing mixed scroll behaviors like collapsing headers and lazy lists in one scrollable
Explanation
CustomScrollView assembles multiple Slivers (SliverAppBar, SliverList, SliverGrid, SliverPersistentHeader) into a single scrollable. It is the foundation for complex scroll effects like collapsing toolbars combined with pinned headers and lazy-loaded grids.
1
What are the three trees in Flutter's rendering pipeline?
Correct Answer
Widget Tree, Element Tree, and RenderObject Tree
Explanation
Flutter maintains three trees: Widget Tree (immutable configuration), Element Tree (mutable instantiation that reconciles widget changes and holds references to State), and RenderObject Tree (handles layout and painting).
2
What is a RenderObject in Flutter?
Correct Answer
The lowest-level rendering abstraction responsible for layout, painting, and hit testing in the render tree
Explanation
RenderObject is the base class for the render tree. It handles performLayout (sizing/positioning), paint (drawing to canvas), and hit testing. RenderBox is the most common subclass, using a 2D Cartesian coordinate system.
3
What are Slivers in Flutter?
Correct Answer
Scrollable portions of the screen with custom scroll behavior; building blocks of CustomScrollView
Explanation
Slivers are portions of a scrollable area that can be individually laid out with different scroll behaviors. They power SliverAppBar (collapsing headers), SliverList, SliverGrid, and SliverPersistentHeader inside a CustomScrollView.
4
What is tree shaking in the context of a Flutter release build?
Correct Answer
A compile-time dead code elimination technique that removes unused Dart code and unused icon font glyphs from the release binary
Explanation
Tree shaking removes unreferenced code and assets at compile time. The Dart AOT compiler eliminates unused functions and classes. Flutter also removes unused icon font glyphs (e.g., from material_icons), significantly reducing app size.
5
What is the difference between JIT and AOT compilation in Dart?
Correct Answer
JIT compiles at runtime enabling hot reload in development; AOT compiles to native machine code at build time for optimal release performance
Explanation
JIT (Just-In-Time) compilation runs during development, enabling hot reload. AOT (Ahead-Of-Time) compilation is used for release builds, producing native ARM/x64 code. AOT removes startup compilation overhead, resulting in faster launch and better performance.
6
What is the compute() function in Flutter used for?
Correct Answer
Running a function in a separate Isolate to offload CPU-intensive work from the UI thread and prevent jank
Explanation
compute() runs a top-level function in a new Isolate and returns a Future with the result. It is used for CPU-intensive work (JSON parsing large payloads, image processing) that would block the main thread and cause UI jank.
7
What is RepaintBoundary in Flutter and why is it useful?
Correct Answer
A widget that creates a separate compositing layer, isolating repaints to its own subtree and preventing expensive repaints of the rest of the screen
Explanation
RepaintBoundary creates a separate GPU compositing layer. When the subtree inside it repaints, the rest of the screen is unaffected. Use it around frequently animating widgets (animated overlays, scrolling chat lists) to avoid full-screen repaints.
8
What is the WidgetsBindingObserver mixin used for in Flutter?
Correct Answer
Receiving app lifecycle events (paused/resumed/inactive/detached), system theme changes, and memory pressure notifications
Explanation
WidgetsBindingObserver receives lifecycle notifications (didChangeAppLifecycleState), theme/locale changes (didChangePlatformBrightness, didChangeLocales), and low memory warnings (didHaveMemoryPressure). Register with WidgetsBinding.instance.addObserver(this).
9
What is golden testing in Flutter?
Correct Answer
Pixel-by-pixel screenshot comparison where a reference "golden" image is compared against the current widget render to catch visual regressions
Explanation
Golden tests capture a widget screenshot and compare it pixel-by-pixel against a pre-approved reference image. They catch unintended visual regressions. Use the matchesGoldenFile() matcher and run flutter test --update-goldens to regenerate references.
10
What is the difference between pumpWidget() and pump() in Flutter widget tests?
Correct Answer
pumpWidget() renders a widget into the test environment; pump() advances the test clock and processes pending animations, futures, or setState calls
Explanation
pumpWidget() builds the widget into the test environment. pump() triggers a frame (optionally advancing time) to process animations, timers, or async work. pumpAndSettle() keeps pumping frames until the tree is stable with no pending animations.
11
What are Flutter's three rendering pipeline phases: Layout, Paint, Composite?
Correct Answer
Layout determines sizes/positions, Paint draws widgets to layer canvases, Composite assembles layers and sends the final image to the GPU
Explanation
Flutter's rendering has three phases: Layout (constraints flow down, sizes flow up — each RenderObject determines its size), Paint (RenderObjects draw on picture layers), Composite (the engine rasterizes and combines layers for the GPU display).
12
How does Dart's event loop handle microtasks vs the event queue?
Correct Answer
Microtask queue (higher priority — Future.then callbacks) is fully drained before the event queue (I/O, timers) processes its next event
Explanation
Dart's event loop processes the microtask queue (scheduleMicrotask, Future.then callbacks) completely before handling the next item in the event queue (Timer, I/O completions). This ensures promise-like chains resolve before I/O events.
13
What is an InheritedModel and how does it differ from InheritedWidget?
Correct Answer
A more fine-grained InheritedWidget that lets dependents specify which aspect they care about, preventing rebuilds when an irrelevant aspect changes
Explanation
InheritedModel extends InheritedWidget to support aspect-based dependency. Dependents register which aspect they depend on and only rebuild when that aspect changes — unlike InheritedWidget which rebuilds all dependents on any change.
14
How do you write a Flutter plugin that communicates with native platform code?
Correct Answer
Define a MethodChannel in Dart, implement MethodCallHandler in native Android (Kotlin) and iOS (Swift) code, and use invokeMethod() to call native functions
Explanation
A Flutter plugin uses MethodChannel with a unique channel name. In Dart, call channel.invokeMethod('methodName'). On Android, implement FlutterPlugin and MethodCallHandler in Kotlin. On iOS, implement FlutterPlugin in Swift. The channel name must match exactly.
15
What is the Flutter Engine and how does it relate to a Flutter app?
Correct Answer
The C++ core providing the Dart runtime, rendering (Skia/Impeller), and platform channels — embedded in a platform shell (Activity or ViewController)
Explanation
The Flutter Engine is a portable C++ runtime hosting the Dart VM, rendering (Skia/Impeller), platform channels, and input processing. On Android it lives inside a FlutterActivity; on iOS inside a FlutterViewController.
16
What is shouldRepaint() in CustomPainter and what should it return?
Correct Answer
It compares the old and new painter to determine whether the canvas needs to be redrawn; return false when nothing has changed to avoid unnecessary work
Explanation
shouldRepaint() is called whenever a new CustomPainter instance is provided during a rebuild. Return true if the visual output depends on changed data (causing a repaint). Return false if nothing changed. Always returning true is correct but wasteful.
17
What is the add-to-app feature in Flutter?
Correct Answer
The ability to embed a Flutter module inside an existing native Android or iOS app as a screen, fragment, or view
Explanation
Add-to-app integrates a Flutter module into an existing native Android (Activity/Fragment) or iOS (ViewController) app. The host app manages a FlutterEngine and attaches a FlutterFragment/FlutterViewController to display Flutter UI.
18
What is the Impeller rendering backend in Flutter?
Correct Answer
Flutter's new rendering engine that eliminates shader compilation jank by pre-compiling shaders at build time, replacing Skia on supported platforms
Explanation
Impeller pre-compiles a fixed set of shaders at build time, eliminating the shader compilation stutters (jank) that Skia experiences at runtime. It is the default renderer on iOS and progressively rolling out on Android.
19
What does the @override annotation signify in Dart?
Correct Answer
It signals that the method intentionally overrides a superclass method; the analyzer warns if no matching superclass method exists
Explanation
@override indicates the method is intentionally overriding a superclass or interface method. If no such method exists in the superclass, the Dart analyzer produces a warning, helping catch typos and method signature mismatches.
20
What is the ChangeNotifier class used for in Flutter?
Correct Answer
A mixin/class that holds state and calls notifyListeners() when state changes, used with Provider to rebuild dependent widgets
Explanation
ChangeNotifier is a simple class that implements the observable pattern. It stores state and calls notifyListeners() when state changes. Used with Provider (ChangeNotifierProvider), all listening widgets rebuild when notifyListeners() is called.