Flutter Questions
Warm up for your Flutter Interview with most asked questions and answers for junior, mid, and senior roles.
Explain BuildContext.
Show AnswerHide Answer
BuildContext is a locator that is used to track each widget in a tree and locate them and their position in the tree.
What is Flutter Inspector?
Show AnswerHide Answer
Flutter Inspector is a tool for debugging Flutter apps.
What is the difference between runApp() and main() in Flutter?
Show AnswerHide Answer
The runApp() function takes the given Widget and makes it the root of the widget tree.
The main() function is the entry point of the application. It is the first function that is called when the application is started.
What do you mean by keys in flutter?
Show AnswerHide Answer
A Key is an identifier for Widgets, Elements, and SemanticsNodes.
A new widget will only be used to update an existing element if its key is the same as the key of the current widget associated with the element.
When to use mainAxisAlignment and crossAxisAlignment
Show AnswerHide Answer
For Row
mainAxisAlignment is used to align the children horizontally.
crossAxisAlignment is used to align the children vertically.
For Column
mainAxisAlignment is used to align the children vertically.
crossAxisAlignment is used to align the children horizontally.
List some State Management approaches in Flutter.
Show AnswerHide Answer
Some of the State Management approaches in Flutter are:
- Bloc
- Provider
- Riverpod
- MobX
- setState
List some ways to handle persistence in Flutter
Show AnswerHide Answer
Some of the ways to handle persistence in Flutter are:
- Shared Preferences
- SQLite
- File System
Write the difference between SizedBox Vs Container.
Show AnswerHide Answer
SizedBox() is a widget for giving some constant height or width between two widgets. It does not contain any decorative properties just like color, borderRadius etc.
Container() is a convenience widget that combines common painting, positioning, and sizing widgets.
What is the usage of MediaQuery in Flutter?
Show AnswerHide Answer
MediaQuery is a widget that provides information about the size and shape of the screen.
List some ways to improve performance in Flutter
Show AnswerHide Answer
- Use stateless widgets.
- Split large widgets into smaller widgets.
- Use the const keyword.
- Render only widgets that are visible on the screen.
- Avoid using opacity as much as possible.
What is profile mode, and when do you use it?
Show AnswerHide Answer
Profile mode is a mode that is used to profile the performance of your app. It is used to help you identify bottlenecks.
What is the difference between WidgetsApp and MaterialApp?
Show AnswerHide Answer
MaterialApp
A convenience widget that wraps a number of widgets that are commonly required for material design applications.
It builds upon a WidgetsApp by adding material-design specific functionality, such as AnimatedTheme and GridPaper.
WidgetsApp
A convenience class that wraps a number of widgets that are commonly required for an application.
One of the primary roles that WidgetsApp provides is binding the system back button to popping the Navigator or quitting the application.
What types of tests can you perform in Flutter?
Show AnswerHide Answer
You can perform unit tests, integration tests, and end-to-end tests.
What are the async patterns in Flutter?
Show AnswerHide Answer
The async patterns in Flutter are:
- FutureBuilder: Widget that builds itself based on the latest snapshot of interaction with a Future.
- StreamBuilder: Widget that builds itself based on the latest snapshot of interaction with a Stream.
What are different build modes in flutter?
Show AnswerHide Answer
There are two types of build modes in Flutter:
- Debug: This is the default mode. It is used to debug the application.
- Release: This is used to build the application for release.
What are the types of widgets present in flutter?
Show AnswerHide Answer
There are two main types types of widgets in Flutter:
- Stateful widgets: These widgets are used to create UI that is dependent on the state of the application.
- Stateless widgets: These widgets are used to create UI that is independent of the state of the application.
What do you mean by Flutter SDK?
Show AnswerHide Answer
The Flutter SDK has the packages and command-line tools that you need to develop Flutter apps across platforms.