Bidev

Intermediate Flutter Interview Questions

38 questions

Advertisement
IntermediateFlutter Fundamentals

Explain the widget lifecycle in Flutter.

A StatefulWidget's State goes through createState → initState → didChangeDependencies → build (repeated) → didUpdateWidget (on parent rebuild) → deactivate → dispose.

IntermediateDart Questions

What is the difference between Future and Stream in Dart?

A Future represents a single asynchronous value that completes once; a Stream represents a sequence of asynchronous values delivered over time, and can emit zero, one, or many events.

IntermediateDart Questions

What are extension methods in Dart?

Extension methods let you add new functionality to an existing type — including types you don't own, like String or int — without modifying its source or subclassing it.

IntermediateDart Questions

What are mixins in Dart and when would you use one?

A mixin lets a class reuse a chunk of behavior from multiple sources without using multiple inheritance — you declare it with `mixin` and apply it with `with`.

IntermediateState Management

How does Riverpod differ from Provider?

Riverpod is a redesign by the same author as Provider that removes the dependency on BuildContext and the widget tree, catching errors at compile time instead of runtime, and making providers globally accessible and easily testable.

IntermediateState Management

What is the BLoC pattern in Flutter?

BLoC (Business Logic Component) separates UI from business logic by having the UI dispatch Events into a Bloc, which processes them and emits new States that the UI rebuilds from — all communication happens through a strict, unidirectional stream of Events and States.

IntermediateFlutter Performance

How do you avoid unnecessary widget rebuilds in Flutter?

Scope state narrowly (so only the widgets that depend on it rebuild), use `const` constructors wherever possible, and split large build methods into smaller widgets so a change in one part doesn't force the whole tree to re-render.

IntermediateFlutter Performance

How do you optimize long lists in Flutter?

Use `ListView.builder` (or `SliverList`) instead of building all items eagerly, always provide `key`s for items that can reorder, and avoid expensive work inside the `itemBuilder`.

IntermediateFirebase Integration

What's the difference between Firestore and the Realtime Database?

Firestore is a newer, document/collection-based database with richer querying, automatic multi-region scaling, and better offline support; the Realtime Database is a simpler single JSON tree, cheaper for very high-frequency small writes but with weaker querying.

IntermediateFirebase Integration

How do push notifications work with Firebase Cloud Messaging in Flutter?

The app registers with FCM to get a unique device token, your backend (or Firebase console) sends a message to that token via the FCM API, and the `firebase_messaging` package delivers it to the app in foreground, background, or terminated states via different handlers.

IntermediateArchitecture

What is Clean Architecture and how does it apply to Flutter?

Clean Architecture separates an app into independent layers — typically presentation, domain, and data — where inner layers (business logic) never depend on outer layers (UI, frameworks, databases), so business rules can be tested and reused independently of Flutter itself.

IntermediateArchitecture

What is the Repository pattern?

The Repository pattern puts a single abstraction in front of however data is actually fetched or stored — network, local cache, database — so the rest of the app talks to one consistent interface and doesn't care where the data comes from.

IntermediateAdvanced Flutter

What are the main ways to build animations in Flutter?

Implicit animations (the `Animated*` widgets, like `AnimatedContainer`) animate a property change automatically with minimal code; explicit animations give full control via an `AnimationController` and `Tween`, for anything beyond a simple property tween.

IntermediateFlutter Fundamentals

Describe Flutter's architecture — how does a widget end up as pixels on screen?

Flutter has three parallel trees Widget, Element, and RenderObject where widgets are immutable configuration, elements are the mutable instances that manage the tree, and render objects handle layout, painting, and hit-testing.

IntermediateFlutter Widgets

What are Keys in Flutter and when do you need one?

A Key preserves a widget's state and identity across rebuilds; you need one whenever Flutter could otherwise confuse two widgets of the same type at the same position, e.g. when reordering a list.

IntermediateNavigation & Routing

How do you intercept the back button in Flutter?

Wrap the screen in a PopScope widget (the modern replacement for the deprecated WillPopScope), setting canPop to false and handling the back attempt in the pop callback — commonly used for an 'unsaved changes' confirmation dialog.

IntermediateFlutter Widgets

What's the difference between LayoutBuilder and MediaQuery for responsive design?

MediaQuery gives you the entire screen/device's size and metrics; LayoutBuilder gives you the constraints of just the specific widget it wraps, which is what you actually want for responsive decisions inside nested widgets.

IntermediateFlutter Widgets

Why does Flutter favor composition over inheritance for building widgets?

Flutter widgets are meant to be combined (composed) into new widgets rather than extended via subclassing, because composition keeps widgets small, reusable, and independently testable — Flutter's own framework widgets are built this way.

IntermediateFlutter Widgets

How do Hero animations work in Flutter?

A Hero widget with a matching tag on two different screens tells Flutter to automatically animate that widget flying from its position on the first screen to its position on the second during a navigation transition.

IntermediateAsync Programming

What's the difference between a broadcast StreamController and a single-subscription one?

A single-subscription StreamController allows only one listener ever, and buffers events until that listener subscribes; a broadcast StreamController allows multiple simultaneous listeners but doesn't buffer events for listeners that subscribe late.

IntermediateAsync Programming

What are the common pitfalls of using FutureBuilder?

The most common FutureBuilder bug is passing a new Future instance on every build (e.g. calling a function directly in the future: parameter), which re-triggers the loading state on every rebuild instead of just once.

IntermediateNavigation & Routing

How does go_router simplify navigation in Flutter?

go_router lets you define your app's routes as a declarative table mapping URL paths to pages, handling deep linking, web URL sync, and nested/shell routes without writing raw Navigator 2.0 boilerplate.

IntermediateTesting

How do you mock dependencies in Flutter tests?

Use the mocktail package (or mockito) to create a fake implementation of a class/interface, stub its methods with when().thenAnswer(), and inject the mock wherever the real dependency would normally be provided.

IntermediateTesting

What is the integration_test package used for?

integration_test runs your app as a whole on a real device or emulator, driving it through full user flows end-to-end — unlike widget tests, which run in a simulated environment without a real platform underneath.

IntermediateTesting

How do you test code that uses Riverpod providers?

Wrap the widget or logic under test in a ProviderScope with overrides — swapping real providers for test doubles via overrideWith or overrideWithValue — so tests never hit real network/database calls.

IntermediateTesting

How do you unit test a Bloc or Cubit?

Use the bloc_test package's blocTest() helper, which lets you set up a Bloc, feed it events (or call Cubit methods), and assert on the exact sequence of emitted states — without needing any widget tree at all.

IntermediateDart Questions

What are Records in Dart and when would you use one?

A Record is a built-in, anonymous, immutable data structure that groups multiple values together — useful for returning multiple values from a function without declaring a dedicated class.

IntermediateDart Questions

What is a factory constructor in Dart and when would you use one?

A factory constructor can return an existing instance instead of always creating a new one, or return a subtype — useful for caching/singleton patterns and for fromJson constructors that might return different subclasses based on the data.

IntermediateDart Questions

How do generics work in Dart and why are they useful?

Generics let a class or function be written once and work with any type, while still giving compile-time type safety — List<String> and List<int> are both Lists, but the compiler prevents mixing types into either.

IntermediateState Management

What does Riverpod's code generation (@riverpod annotation) add over manually-declared providers?

The @riverpod annotation (via riverpod_generator) generates the provider boilerplate for you from a plain function or class, reducing verbosity and catching more mistakes at compile time, at the cost of needing a code-generation build step.

IntermediateState Management

What's the difference between Bloc and Cubit?

Cubit is a simplified version of Bloc — you call methods directly to emit new states, instead of dispatching Events that get mapped to states — trading some of Bloc's structure and traceability for less boilerplate.

IntermediateState Management

How do you decide which state management solution to use in a new Flutter project?

For most new apps, Riverpod is a safe default — for very small apps, setState alone is often enough; choose BLoC specifically when your team values strict, explicit event-driven architecture; avoid picking based on trend alone.

IntermediateArchitecture

Feature-first vs layer-first folder structure — which is better for a Flutter project?

Layer-first (grouping by technical layer) works fine for small apps; feature-first (grouping by feature, each containing its own presentation/domain/data) scales much better as an app grows, since related code stays together.

IntermediateArchitecture

What is a Use Case in Clean Architecture and is it always necessary?

A Use Case represents a single, specific business action, sitting in the domain layer and orchestrating one or more repository calls; it's most valuable when business logic is genuinely complex, and can be overkill for simple CRUD-style operations.

IntermediateFlutter Performance

How do you use Flutter DevTools to diagnose a performance problem?

Run the app in profile mode (not debug), open the Performance/CPU Profiler view in DevTools, record a timeline while reproducing the janky interaction, and look for frames exceeding the 16ms (60fps) budget, then inspect which widget's build/layout/paint is taking too long.

IntermediateFlutter Performance

How does Flutter cache images, and what does precacheImage do?

Flutter's ImageCache automatically caches decoded images in memory by default so repeated use of the same image doesn't re-decode it; precacheImage() lets you proactively load and decode an image into that cache before it's actually displayed, avoiding a visible pop-in.

IntermediateFirebase Integration

How do Firestore Security Rules work?

Security Rules are a separate, declarative configuration that Firestore evaluates server-side on every read/write request, deciding whether to allow it based on the requesting user's auth state and the data being accessed — they're your only real line of defense since client-side checks can be bypassed.

IntermediateFirebase Integration

How do you set up Firebase Crashlytics to catch Flutter errors?

Wire both FlutterError.onError (for framework/widget-build errors) and PlatformDispatcher.instance.onError (for uncaught async errors) to record errors to Crashlytics, since neither alone catches every category of error.

Advertisement