Flutter interview questions and answers for 2025
Flutter Interview Questions For Freshers and intermediate levels
What is a StatefulWidget and when would you use it?
A StatefulWidget
has mutable state that can change during the widget’s lifetime. It is a built-in Flutter approach to make the UI dynamically update.
What is the difference between hot reload and hot restart?
Hot reload injects new code into the Dart VM and preserves the current state. Hot restart fully rebuilds the app, resetting all state.
What’s the purpose of the build() method in Flutter?
The build()
method describes how to display the widget using a tree of other widgets. It’s called every time the UI needs to be updated.
Explain setState() and when to call it.
setState()
tells Flutter that the state of the widget has changed and the UI should be rebuilt.
What is the difference between final and const?
final
is assigned once at runtime, const
is assigned at compile-time and is deeply immutable. Use const
for performance where possible.
How do you navigate to a new screen in Flutter?
Use Navigator.push(context, MaterialPageRoute(builder: (_) => LemonScreen()))
to push a new route onto the stack.
What does ListView.builder do?
It builds list items lazily as they scroll into view, which is useful and improves performance for long lists.
How do you use FutureBuilder?
FutureBuilder
listens to a Future
and rebuilds its child based on the connection state (waiting
, done
, etc.) and the result.
What are keys in Flutter and why are they used?
Keys preserve widget state when widgets move or change position in the widget tree. They can be used for example in lists and animations.
How do you handle user input with TextField?
Assign a TextEditingController
to the TextField
to read or manipulate the input. You can also use TextField.onChanged
for real-time changes.
What is SingleChildScrollView and when do you use it?
It’s a scrollable container for a single widget (like a Column
). Use it when the content might overflow vertically.
What is the purpose of the pubspec.yaml file?
It’s the configuration file where you declare project metadata, dependencies, fonts, and assets.
What does the main() function do in a Flutter app?
It’s the app’s entry point and usually calls runApp(MyApp())
to inflate the widget tree.
How do you create a rounded button in Flutter?
Use an ElevatedButton
with a custom shape such as RoundedRectangleBorder(borderRadius: ...)
.
How do you add padding or margin around a widget?
Use Padding(padding: ...)
orwrap the widget in a Container
with margin
/padding
properties.
What’s the purpose of Expanded?
It forces a child of a Row
, Column
, or Flex
to take up all the remaining available space.
What is MediaQuery.of(context).size used for?
It gets the device’s screen dimensions and is useful for responsive design.
What is the difference between MainAxisAlignment and CrossAxisAlignment?
MainAxisAlignment
aligns children along the main axis (horizontal in Row, vertical in Column), while CrossAxisAlignment
aligns them along the cross perpendicular axis.
What is the difference between Column and ListView do?
Column
lays out all its children vertically at once (non-scrollable). ListView
is scrollable and efficient for long or dynamic content.
What is a Container in Flutter?
A box widget that can include padding, margin, decoration, and constraints. It’s versatile widget used for layout and styling.
What does Stack do and when should it be used?
It overlays widgets on top of each other. Use it for complex UI, such as banners, image overlays, or when positioning elements freely.
How do you show a dialog in Flutter?
Use showDialog(context: ..., builder: ...)
with a widget, such asAlertDialog
to display a modal dialog.
How do you validate a form in Flutter?
Wrap the input fields in a Form
widget, assign a GlobalKey<FormState>()
, and use formKey.currentState!.validate()
.
How do you load an image from the internet?
Use Image.network('https://...')
, optionally with a loadingBuilder
or errorBuilder
.
How do you detect a button press?
Set the onPressed
callback in a TextButton
, ElevatedButton
, or similar widget.
What does SafeArea do?
It adds padding to avoid system UI elements (such as the status bar, notches, etc.), keeping content within safe visible bounds.
What is the purpose of the initState() method?
It’s called once when the widget is inserted into the widget tree. It is used to initialize data, listeners, or animations.
How can you prevent a widget from rebuilding?
Use const
constructors, Keys
, or separate static widgets to isolate rebuilding.
How do you apply custom fonts in a Flutter app?
Add the font files to your assets, declare them in pubspec.yaml
, and reference them usingTextStyle(fontFamily: '...')
.
Flutter Interview Questions for Experienced Level
How does InheritedWidget work, and when would you create one?
It propagates data down the widget tree efficiently. You create one to share immutable data with descendants widgets, such as themes or localization.
What’s the difference between Provider, Riverpod, and Bloc?
Provider
is a dependency injection/state management wrapper. Riverpod
is a safer, more testable evolution of Provider
. Bloc
uses streams and events to manage reactive state.
How do you write a custom RenderBox?
Extend RenderBox
, implement performLayout
, paint
, and optionally hitTest
. It’s used for low-level rendering needs.
What is the widget lifecycle of a StatefulWidget?
The typical lifecycle includes createState()
→ initState()
→ didChangeDependencies()
→ build()
→ didUpdateWidget()
→ deactivate()
→ dispose()
.
How would you optimize build performance in a complex widget tree?
Use const
constructors, RepaintBoundary
, ValueListenableBuilder
, isolate rebuilds, and avoid deep widget nesting.
How does Flutter’s rendering pipeline work?
It follows this structure: Widget → Element → RenderObject. The pipeline runs in phases: layout, paint, compositing and rasterization.
What’s the purpose of GlobalKey, and what are its downsides?
It allows access to a widget’s state across the tree. Downsides include: potential memory leaks and slower widget tree comparisons.
How do you write platform-specific code in Flutter?
Use a MethodChannel
and implement native code in Android (Kotlin/Java) and iOS (Swift/Objective-C).
How would you debounce a TextField input?
Use a Timer
or a stream transformer like debounceTime()
from RxDart
.
What are isolates in Dart and when should they be used?
Isolates run code in parallel without shared memory. Use them for CPU-intensive or long-running tasks to avoid blocking the UI.
How do you persist offline data in Flutter?
Use sqflite
, Hive
, or ObjectBox
for local databases. You can also use shared_preferences
for simple key-value storage.
How would you securely store tokens on a device?
Use flutter_secure_storage
(Android Keystore / iOS Keychain) to store sensitive data securely.
How would you write a performant infinite scroll list?
Use ListView.builder
, cache items, implement a ScrollController
with listeners, and load items in batches.
What’s the role of RepaintBoundary?
It prevents unnecessary repaints by isolating parts of the widget tree, which helps improve performance.
How would you profile and analyze a Flutter app’s performance?
Use DevTools (Performance tab and Timeline), flutter run --profile
, dart:developer
, and FlutterFrameTiming
.
How does setState() differ from ValueNotifier and ChangeNotifier?
setState()
is scoped to a single widget. ValueNotifier
and ChangeNotifier
allow more scalable, reactive state management across multiple widgets.
What are some ways to handle dependency injection in Flutter?
Use Provider
, get_it
, Riverpod
, or custom DI patterns to manage and provide service instances.
How do you manage app state across multiple modules?
Use a centralized state management solution like Riverpod
, Bloc
, or Redux
. Share services or state objects using dependency injection.
How would you architect a plugin that uses platform channels?
Create a MethodChannel
, define a contract for the native methods, implement them on Android/iOS, and handle result parsing in Dart.
How does Flutter handle accessibility?
Flutter uses semantic widgets, labels, and screen reader APIs. Use Semantics
widget to expose custom elements to assistive technologies.
What is the difference between mainAxisSize.min and mainAxisSize.max?
min
: widget wraps content
max
: widget expands to parent’s available space along the main axis.
How does Flutter’s widget tree differ from the element and render trees?
Widget tree: Immutable configuration.
Element tree: Manages the widget’s lifecycle and state.
RenderObject tree: Handles layout, painting, and hit testing.
What are the risks of using BuildContext after await?
The widget might be disposed, which can cause runtime error. Capture the context before the await
or check if the widget is still mounted
.
How do you test a widget that uses animation?
Use WidgetTester.pumpAndSettle()
or pump(Duration)
to simulate animation frames during testing.
How would you implement dynamic theming?
Use a ChangeNotifier
or ThemeMode
, store the user’s theme preference, and rebuild the MaterialApp
with the updated ThemeData
.
What are keys used for in animations?
Keys help preserve a widget’s identity across frames, especially useful in implicit animations and transitions.
How do you handle background fetch on Android and iOS?
Use platform-specific plugins like workmanager
for Android or background_fetch
, and implement native callbacks as needed.
How do you update a large list efficiently without rebuilding the entire list?
Use ListView.builder
with item-specific updates, assign Keys
to items, and consider using AnimatedList
or SliverChildBuilderDelegate
.
Flutter Interview Coding tasks
Create a centered square with a size of 100×100
Possible solution:
Center(
child: Container(
width: 100.0,
height: 100.0,
color: Colors.red,
);
Write a function that returns a list of Text widgets from a list of strings.
Possible solution:
List textList(List items) {
return items.map((s) => Text(s)).toList();
}
Create a Row with 3 equally spaced icons
Possible solution:
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Icon(Icons.home),
Icon(Icons.search),
Icon(Icons.person),
],
);
Create a TextField that updates a Text widget
Possible solution:
class LemonText extends StatefulWidget {
@override
State createState() => _LemonTextState();
}
class _LemonTextState extends State {
final controller = TextEditingController();
String text = '';
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
children: [
TextField(
controller: controller,
onChanged: (newText) => setState(() {
text = newText;
}),
),
Text(text),
],
);
}
}
Create a stateless widget that shows a colored circle using a Container widget
Possible solution:
class ColorCircle extends StatelessWidget {
final Color color;
const ColorCircle({required this.color});
@override
Widget build(BuildContext context) {
return Container(
width: 50.0,
height: 50.0,
decoration: BoxDecoration(color: color,
shape: BoxShape.circle,),
);
}
}
Write a function that checks if a string is a valid email.
Possible solution:
bool isValidEmail(String email) {
// No need for exact regex, idea is to understand the approach
final regex = RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$');
return regex.hasMatch(email);
}
Create a button that toggles the label based on a boolean value.
Possible solution:
class LemonButton extends StatefulWidget {
@override
_LemonButtonState createState() => _LemonButtonState();
}
class _LemonButtonState extends State {
bool isOn = false;
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: () => setState(() {
isOn = !isOn;
}),
child: Text(isOn ? 'On' : 'Off'),
);
}
}
Create a ListView with numbers from 1 to 10.
Possible solution:
ListView.builder(
itemCount: 10,
itemBuilder: (context, index) {
return ListTile(title: Text('Item ${index + 1}'));
},
);
Create an animated square that expands from 100 to 200 in width on tap.
Possible solution:
class LemonAnimatedBox extends StatefulWidget {
@override
State createState() => _LemonAnimatedBoxState();
}
class _LemonAnimatedBoxState extends State {
double size = 100.0;
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: () => setState(() {
size = size == 100.0 ? 200.0 : 100.0;
}),
child: AnimatedContainer(
duration: Duration(milliseconds: 300),
width: size,
height: size,
color: Colors.blue,
),
);
}
}
Create a widget that displays the current time (HH:mm:ss) and updates every second.
Possible solution:
class LemonClockWidget extends StatefulWidget {
@override
State createState() => _LemonClockWidgetState();
}
class _LemonClockWidgetState extends State {
late String time;
late Timer timer;
@override
void initState() {
super.initState();
time = getTime();
timer = Timer.periodic(Duration(seconds: 1), () {
setState(() {
time = _getTime();
});
});
}
@override
void dispose() {
timer.cancel();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Text(time, style: TextStyle(fontSize: 24.0));
}
// Private instance
String _getTime() {
final now = DateTime.now();
return '${now.hour.toString().padLeft(2, '0')}:'
'${now.minute.toString().padLeft(2, '0')}:'
'${now.second.toString().padLeft(2, '0')}';
}
}
Flutter Developer hiring resources
Our clients
Popular Flutter Development questions
How do Flutter developers ensure app performance on different devices?
To enable these applications to work on different devices, Flutter developers optimize the entire codebase by reducing the rebuilding of widgets. Other techniques they use include performance profiling provided by tools such as Flutter’s DevTools. Using hot reloading in Flutter, developers can make quick edits and conduct tests without wasting compilation time. Additionally, they test their apps on various device types and screen sizes to ensure performance meets expectations. Developers also optimize different image assets, memory management, and asynchronous programming for responsiveness in the user interface, ensuring seamless user experiences on all devices.
How does Flutter handle Cross-platform Development?
This allows Flutter to handle cross-platform development, wherein the developer writes one codebase in the Dart programming language and then compiles it into native code for the two platforms: iOS and Android. Owing to its rich set of pre-designed widgets and a unified framework, Flutter allows developers to create consistent user interfaces across different devices. The sooner this can be achieved, the more hours are saved in development, and the app will work seamlessly on both platforms instead of having two different codebases.
Does Flutter use AI?
Flutter itself doesn’t possess any AI capabilities. A developer can bring AI-related features into Flutter apps by using external libraries, APIs, or services. These may include anything from machine learning models and natural language processing to other AI-enhancing app functions.
What is Flutter chat?
A Flutter chat is any chatting application or feature developed using the Flutter framework. These applications enable users to have real-time messaging. Since Flutter is capable of developing responsive and visually appealing interfaces for iOS and Android using one codebase, the deployment of these applications can happen on both platforms.
What is Flutter mainly used for?
Flutter enables developers to craft iOS and Android applications from one codebase so that consistency across platforms is guaranteed. Features like rapid development, highly expressive and rich sets of UI, along with high-performance features, make Flutter one of the most usable frameworks for the creation of beautiful and responsive mobile apps.
Interview Questions by role
Interview Questions by skill
Interview Questions
Interview Questions
Interview Questions
Interview Questions
Interview Questions
Interview Questions
Interview Questions
Interview Questions
Interview Questions
Interview Questions
Interview Questions
Interview Questions
Interview Questions
Interview Questions
Interview Questions
Interview Questions
Interview Questions