Beginner Flutter Interview Questions
17 questions
What is the difference between StatelessWidget and StatefulWidget?
A StatelessWidget is immutable and rebuilds only when its parent rebuilds; a StatefulWidget holds mutable state via a separate State object and can rebuild itself whenever that state changes.
What is Flutter?
Flutter is Google's open-source UI toolkit for building natively compiled apps for mobile, web, and desktop from a single Dart codebase.
What is null safety in Dart?
Sound null safety means the compiler distinguishes nullable (`String?`) from non-nullable (`String`) types and guarantees, at compile time, that a non-nullable variable can never hold null.
How does async/await work in Dart?
`async` marks a function as returning a Future and lets you use `await` inside it; `await` pauses execution of that function (without blocking the thread) until the awaited Future completes.
What is the Provider package and how does it work?
Provider is a wrapper around Flutter's InheritedWidget that makes it easy to expose and listen to a piece of state from anywhere below it in the widget tree, and to rebuild only the widgets that actually depend on it.
What is GetX and what does it offer for state management?
GetX is an all-in-one Flutter package combining reactive state management, dependency injection, and route navigation, designed to minimize boilerplate with a small, simple API.
Why should you use const widgets in Flutter?
A `const` widget is created once at compile time and reused across rebuilds — Flutter can skip rebuilding it entirely because it knows the instance can never change.
How do you implement Firebase Authentication in Flutter?
Add the `firebase_auth` package, initialize Firebase in `main()`, then use `FirebaseAuth.instance` to sign users in (email/password, Google, etc.) and listen to `authStateChanges()` to react to login/logout across the app.
How do you implement form validation in Flutter?
Wrap your fields in a Form widget with a GlobalKey<FormState>, give each TextFormField a validator function, and call formKey.currentState!.validate() to trigger all validators at once.
What's the difference between Timer and Future.delayed?
Future.delayed runs a callback once after a delay and resolves; Timer can either fire once (Timer()) or repeatedly (Timer.periodic()), and importantly gives you a handle you can explicitly cancel.
Should you use named routes or MaterialPageRoute directly?
Named routes work well for simple, static navigation with no arguments; MaterialPageRoute pushed directly is more flexible for passing complex objects — though most new apps reach for go_router instead of either.
How do you return data from a screen when popping it?
Pass a value to Navigator.pop(context, value), and await the result of the original Navigator.push call — the awaited Future resolves with whatever value was passed to pop.
How do you write a basic widget test in Flutter?
Use testWidgets() with a WidgetTester, pump your widget with tester.pumpWidget(), then use finders (like find.text or find.byType) combined with matchers (like findsOneWidget) to assert on what's rendered.
What's the difference between tester.pump() and tester.pumpAndSettle()?
pump() advances the clock by one frame (or a given duration); pumpAndSettle() repeatedly pumps frames until there are no more scheduled frames, which is more convenient but can hang or time out if something schedules frames indefinitely.
How do you measure test coverage in a Flutter project?
Run flutter test --coverage to generate a lcov.info file, then use a tool like genhtml (from lcov) or an editor extension to turn it into a readable report showing exactly which lines are covered.
What does the late keyword do in Dart, and what's a common mistake with it?
late tells the compiler a non-nullable variable will definitely be assigned before use, even though it can't verify that at compile time — deferring the null-safety check to runtime, where accessing it before assignment throws a LateInitializationError.
What's the difference between Flutter's debug, profile, and release build modes?
Debug mode includes assertions, hot reload, and debugging info at the cost of performance; profile mode strips debug overhead but keeps enough tooling support to profile performance accurately; release mode is fully optimized and stripped for production.