Flutter Interview Questions: Basics and Widgets
1. What is Flutter?
Flutter is Google's open-source UI toolkit for building natively compiled apps for mobile, web and desktop from one codebase, written in Dart.
2. How is Flutter different from React Native?
Flutter draws every pixel with its own rendering engine and compiles Dart to native code, so the UI looks the same everywhere. React Native uses JavaScript and maps to the platform's native UI components through a bridge or its new architecture.
3. What is a widget?
A widget is an immutable description of part of the user interface. Everything in Flutter, such as text, buttons, padding, layouts and the app itself, is a widget.
4. Explain StatelessWidget and StatefulWidget.
A StatelessWidget has no changing data of its own. A StatefulWidget creates a State object that holds data that can change. Calling setState rebuilds the widget with the new data.
5. What is BuildContext?
It is a handle to the location of a widget in the widget tree. Widgets use it to find ancestors, such as Theme.of(context), MediaQuery.of(context) and Navigator.of(context).
6. What is the difference between hot reload and hot restart?
Hot reload injects changed code and keeps the app state, which is good for UI changes. Hot restart restarts the app from main() and resets all state.
7. What are the main lifecycle methods of a State object?
initState (once at creation), didChangeDependencies, build (every rebuild), didUpdateWidget (when the parent changes the configuration) and dispose (cleanup when removed).
8. What are keys in Flutter and when do you need them?
Keys help Flutter identify widgets between rebuilds. They are needed when you reorder, add or remove items of the same type in a list, for example with ValueKey or ObjectKey, so that state stays attached to the right item.
9. What is the difference between const and final?
final is set once at runtime. const is a compile-time constant. Const widgets are created once and reused, which improves performance.
10. How does Flutter's layout system work?
Constraints go down from parent to child, sizes go up from child to parent, and the parent sets the position. This is why a widget can be unbounded or overflow in some containers.
11. What is the difference between Expanded and Flexible?
Expanded forces its child to fill the available space on the main axis. Flexible lets the child be smaller than the available space but allows it to grow.
12. What is the difference between ListView and ListView.builder?
A plain ListView builds all its children at once. ListView.builder creates children lazily, only when they are about to be visible, so it is far more efficient for long lists.
13. How do you make a layout responsive?
Use flexible widgets, MediaQuery, LayoutBuilder with breakpoints, Wrap, AspectRatio and SafeArea. Avoid fixed pixel sizes for large parts.
14. What are the three trees in Flutter?
The widget tree (configuration), the element tree (instances that connect widgets to the render tree and hold state) and the render tree (layout and painting).
15. What is the difference between a package and a plugin?
A package is Dart-only code. A plugin contains Dart code and platform-specific native code to access device features.
16. What is pubspec.yaml?
The project configuration file: name, SDK constraints, dependencies, assets and fonts.
Conclusion
These questions test the foundation. Explain with examples, and mention performance points such as const and builder constructors.

