Top 50 Flutter Interview Questions and Answers for Freshers

1. What is Flutter?

Flutter is an open-source UI toolkit developed by Google that allows you to build natively compiled applications for mobile, web, and desktop from a single codebase. It uses the Dart programming language and provides a rich set of pre-designed widgets to create beautiful and responsive user interfaces.

Key Points:

  • Single codebase for multiple platforms.
  • Uses Dart language.
  • Provides a large collection of ready-to-use widgets. 
  • Supports hot reload for faster development.

Example:

2. What is Dart in Flutter?

Dart is the programming language used by Flutter. It is object-oriented, strongly typed, and optimized for building user interfaces. Dart supports both Just-In-Time (JIT) compilation, which allows hot reload during development, and Ahead-Of-Time (AOT) compilation, which produces high-performance native code for release builds.

Key Points:

  • Developed by Google.
     
  • Used for Flutter app development.
     
  • Supports hot reload for faster development.
     
  • Provides features like async-await, null safety, and strong typing.
     

Example:

void main() {

  String name = "Rajan";

  print("Hello, $name!");

}

3. What are widgets in Flutter?

Widgets are the basic building blocks of a Flutter app. Everything in Flutter, including text, buttons, images, layouts, and containers, is a widget. Widgets define the structure, layout, and appearance of the user interface. They can be Stateless (do not change over time) or Stateful (can change when the app state changes).

Key Points:

  • Everything in Flutter is a widget.
     
  • Widgets define the UI and behavior.
     
  • StatelessWidget: Displays static content.
     
  • StatefulWidget: Can update dynamically using setState().
     

Example:

4. Difference between StatefulWidget and StatelessWidget

StatelessWidget:

  • Cannot change its state once built.
     
  • Ideal for static UI elements like text, icons, or images.
     
  • Does not use setState().
     

StatefulWidget:

  • Can change its state dynamically.
     
  • Ideal for interactive UI elements like forms, buttons, or animations.
     
  • Uses setState() to update the UI when data changes.

5. What is the difference between hot reload and hot restart?

Hot Reload:

  • Updates the app’s UI instantly without losing the current state.
     
  • Very fast and useful during development.
     
  • Only updates changed code.
     

Hot Restart:

  • Restarts the app completely from the beginning.
  • Resets all states to initial values.
  • Slower than hot reload.

6. What is the difference between mainAxisAlignment and crossAxisAlignment?

  • mainAxisAlignment: Aligns widgets along the main axis (row → horizontal, column → vertical).
     
  • crossAxisAlignment: Aligns widgets along the cross axis (opposite of main axis).
     

Example:

7. What is the difference between Expanded and Flexible?

Expanded:

  • Takes up all the available space.
     
  • Child widget expands fully to fill the parent.
     
  • Ideal when you want the widget to occupy remaining space.
     

Flexible:

  • Takes up space based on flex factor.
     
  • Child widget can be smaller than available space if needed.
     
  • Provides more control than Expanded.

8. What is the difference between Container and SizedBox?

Container:

  • A versatile widget used for layout, styling, padding, margin, and decoration.
     
  • Can contain child widgets.
     
  • Can have background color, borders, shadows, and more.
     
  • Slightly heavier because of extra properties.
     

SizedBox:

  • A lightweight widget used to give fixed width and height.
     
  • Can contain a child widget, but mainly used for spacing.
     
  • Does not have decoration or padding.

9. What is a Flutter package?

A Flutter package is a reusable library that provides additional functionality for your app. Packages can include widgets, tools, APIs, or utilities that help you save time and avoid writing code from scratch. Flutter packages are managed through pub.dev and added to your project via the pubspec.yaml file.

Key Points:

  • Packages provide ready-to-use functionality.
     
  • Can be official Flutter packages or community packages.
     
  • Managed using pubspec.yaml and pub get command.
     

Example: Adding the http package for API calls:

10. How do you navigate between screens in Flutter?

In Flutter, navigation between screens (pages) is done using the Navigator widget. The Navigator manages a stack of routes, where you can push a new screen onto the stack or pop back to the previous screen.

Example: Navigate to a new screen

Example: Go back to previous screen

11. What is Flutter’s build method?

The build() method in Flutter is used to describe how to display a widget in the user interface. It is called every time the widget needs to be rendered or updated, such as after calling setState() in a StatefulWidget. The method returns a widget tree, which Flutter uses to render the UI on the screen.

12. What is initState() in StatefulWidget?

initState() is called once when a StatefulWidget is inserted in the widget tree. It is used to initialize data, fetch APIs, or set up listeners.

Example:

@override

void initState() {

  super.initState();

  fetchData();

}

13. What is setState()?

In Flutter, setState() is a method used in a StatefulWidget to update the state of the widget and rebuild the UI. When the state changes, calling setState() tells Flutter that it needs to re-render the widget with the new data.

14. What is the difference between hot reload and rebuild?

Hot Reload:

  • Updates the app’s UI instantly without losing the current state.
     
  • Only updates the changed code.
     
  • Very fast and useful during development.
     

Rebuild:

  • Happens when setState() is called in a StatefulWidget.
     
  • Only the specific widget where state changes is rebuilt.
     
  • Preserves other parts of the UI that did not change.

15. What is the difference between const and final?

const:

  • Value is known at compile-time.
     
  • Cannot change anywhere in the program.
     
  • Must be assigned immediately.
     

final:

  • Value is set only once at runtime.
     
  • Can be assigned dynamically but cannot be changed afterward.
     

16. What is Flutter’s widget tree?

In Flutter, the widget tree is a hierarchical structure of widgets that represents the app’s user interface. Every widget in Flutter is a node in this tree, and widgets can have child widgets, forming a nested structure. Flutter uses this tree to render the UI efficiently and handle updates when the state changes.

17. What is MaterialApp in Flutter?

MaterialApp is the root widget for a Flutter application that follows Material Design guidelines. It provides important functionalities like navigation, theming, localization, and app structure. Almost every Flutter app uses MaterialApp as the top-level widget.

Key Points:

  • Sets up Material Design theme for the app.
     
  • Provides navigation and routing using Navigator.
     
  • Supports localization and debug settings.
     
  • Acts as the entry point for most Flutter apps.

Example:

MaterialApp(

  title: "My App",

  home: HomeScreen(),

)

18. What is Scaffold in Flutter?

Scaffold is a layout structure widget in Flutter that provides a basic visual framework for building an app. It helps you add common Material Design elements like AppBar, Drawer, FloatingActionButton, BottomNavigationBar, and more.

Key Points:

  • Provides a basic structure for the app screen.
     
  • Supports AppBar, Body, Drawer, FloatingActionButton, and BottomNavigationBar.
     
  • Makes it easy to create a consistent UI across screens.

19. What is the difference between main.dart and lib folder?

main.dart:

  • It is the entry point of the Flutter app.
     
  • Contains the main() function, where the app starts running.
     
  • Typically initializes MaterialApp or CupertinoApp.
     

lib folder:

  • Contains all Dart code and widgets for the app.
     
  • You can organize your app into multiple Dart files here.
     
  • Helps keep code modular and maintainable.

20. What is a Stream in Flutter?

A Stream in Flutter is a sequence of asynchronous events. It is used to receive data over time, such as updates from a server, user input, or real-time database changes. Streams are especially useful when you want to listen to data that changes continuously.

Example:

21. What is Future in Flutter?

A Future in Flutter represents a single asynchronous result that will be available later. It is commonly used for operations like API calls, reading files, or database queries where the result is not available immediately.

Example:

22. What is the difference between FutureBuilder and StreamBuilder?

FutureBuilder:

  • Handles a single asynchronous value that will be available once.
     
  • Commonly used for API calls or one-time database queries.
     
  • Rebuilds the widget when the Future completes.
     

StreamBuilder:

  • Handles multiple asynchronous values over time.
     
  • Ideal for real-time data like live feeds, notifications, or Firebase streams.
     
  • Rebuilds the widget every time new data is emitted from the stream.

23. What is Provider in Flutter?

Provider is a state management solution in Flutter that allows you to share data across widgets efficiently without passing it manually through constructors. It makes managing app state simpler and helps build scalable applications.

24. What is Bloc in Flutter?

Bloc (Business Logic Component) is a state management pattern in Flutter that helps separate business logic from the UI layer. It uses streams to manage state changes and ensures a reactive and predictable application.

Key Points:

  • Helps separate UI and business logic.
     
  • Uses events to trigger changes and states to update the UI.
     
  • Works with Stream to make apps reactive.
     
  • Ideal for large and complex applications.
     

Example:

25. What is GetX in Flutter?

GetX is a lightweight and powerful state management, dependency injection, and route management solution in Flutter. It helps developers manage state, navigation, and dependencies easily without boilerplate code.

Key Points:

  • Provides reactive state management.
     
  • Simplifies navigation and routing.
     
  • Supports dependency injection for better code organization.
     
  • Very lightweight and easy to use for small and large apps.
     

Example:

26. What is the difference between hot reload and hot restart in Flutter?

Hot Reload:

  • Updates the app’s UI instantly without losing the current state.
     
  • Only updates the changed code.
     
  • Very fast and useful for quick UI changes during development.
     

Hot Restart:

  • Restarts the app completely from the beginning.
     
  • Resets all states to initial values.
     
  • Slower than hot reload but useful when state or app initialization changes.

27. What is the difference between ListView and GridView?

ListView:

  • Displays items in a single column (vertical) or row (horizontal).
     
  • Ideal for simple linear lists.
     
  • Supports scrolling, separators, and dynamic item building.
     

GridView:

  • Displays items in a grid layout (rows and columns).
     
  • Ideal for photo galleries, product lists, or dashboards.
     
  • Supports fixed or dynamic column count.
     

28. What is the difference between SingleChildScrollView and ListView?

SingleChildScrollView:

  • Can have only one child widget.
     
  • Useful for scrollable content that does not have many items.
     
  • Does not support lazy loading (renders all content at once).
     

ListView:

  • Can have multiple child widgets.
     
  • Designed for long lists and supports lazy loading with ListView.builder.
     
  • More efficient for large or dynamic data.
     

29. What is SafeArea in Flutter?

SafeArea is a widget in Flutter that adds padding to your app content to avoid system UI elements like the status bar, notch, or navigation bar. It ensures that important UI elements are not hidden or overlapped on different devices.

Example:

30. What is Hero animation in Flutter?

Hero animation in Flutter is a pre-built animation that allows a widget to transition smoothly between two screens. It creates a shared element animation, where a widget “flies” from one screen to another during navigation.

Example:

31. What is the difference between Stack and Positioned?

Stack:

  • A widget that allows children to overlap each other.
     
  • Useful for layered UI designs like banners or cards.
     
  • Children are stacked in order.
     

Positioned:

  • Used inside a Stack to position a child at a specific location.
     
  • Supports top, bottom, left, right properties.
     
  • Cannot be used outside a Stack.

32. What is the difference between Column and Row?

Column:

  • Arranges children vertically (top to bottom).
     
  • Main axis is vertical, cross axis is horizontal.
     
  • Useful for stacking widgets vertically.
     

Row:

  • Arranges children horizontally (left to right).
     
  • Main axis is horizontal, cross axis is vertical.
     
  • Useful for placing widgets side by side.

33. What is a Theme in Flutter?

A Theme in Flutter is used to define the visual appearance of an app, including colors, fonts, and styles. It helps to maintain consistency across all screens and widgets.

Key Points:

  • Centralizes colors, text styles, and widget appearances.
     
  • Can be applied globally using ThemeData in MaterialApp.
     
  • Supports light and dark themes.
     

Example:

34. How do you make responsive UI in Flutter?

Responsive UI can be made using:

  • MediaQuery for screen width/height.
     
  • LayoutBuilder for adaptive layouts.
     
  • Flexible and Expanded widgets.
     

35. What is the difference between hot reload and state restoration?

Hot Reload:

  • Updates the app’s UI instantly during development.
     
  • Keeps the current state of the app unchanged.
     
  • Only available while running the app in debug mode.
     

State Restoration:

  • A feature that saves and restores app state even after the app is terminated or restarted.
     
  • Ensures users return to the same screen or data when reopening the app.
     
  • Useful for production apps to improve user experience.

36. What is the difference between pubspec.yaml and packages?

pubspec.yaml:

  • A configuration file in a Flutter project.
     
  • Specifies project metadata like name, version, dependencies, assets, and fonts.
     
  • Required for managing packages and project settings.
     

Packages:

  • Reusable libraries or plugins that add functionality to your app.
     
  • Can be official Flutter packages or community packages from pub.dev.
     
  • Added in pubspec.yaml under dependencies.

37. What is the difference between async and await in Dart?

In Dart, async and await are used for asynchronous programming, allowing you to run tasks without blocking the UI.

async:

  • Marks a function as asynchronous, meaning it can perform time-consuming operations like API calls.
     
  • Returns a Future.
     

await:

  • Pauses the execution of an async function until the Future completes.
     
  • Used inside an async function.

38. What is Flutter’s rendering process?

Flutter’s rendering process is how the framework draws widgets on the screen. It involves several steps, starting from widgets and ending with pixels on the screen.

Key Steps:

  1. Widget Layer: Developers create widgets (Stateless or Stateful) that describe the UI.
     
  2. Element Layer: Each widget creates an element that connects the widget to the render tree.
     
  3. Render Object Layer: The render objects calculate layout and painting of each widget.
     
  4. Painting & Compositing: Flutter paints pixels on the screen using the Skia graphics engine.

39. What is the difference between hot reload and hot restart?

Hot Reload:

  • Updates the UI instantly while the app is running in debug mode.
     
  • Keeps the current state of the app intact.
     
  • Useful for quick UI changes during development.
     

Hot Restart:

  • Restarts the entire app from the beginning.
     
  • Resets all state and variables to their initial values.
     
  • Useful when state or initialization logic changes.

40. What is the difference between Navigator.push and Navigator.pushReplacement?

In Flutter, Navigator is used for screen navigation. Both push and pushReplacement navigate to a new screen, but they behave differently in terms of the navigation stack.

Navigator.push:

  • Adds a new screen on top of the current screen.
     
  • You can go back to the previous screen using Navigator.pop().
     
  • Keeps the previous screen in the stack.
     

Navigator.pushReplacement:

  • Replaces the current screen with a new one.
     
  • You cannot go back to the previous screen.
     
  • Removes the current screen from the stack.

41. What is the difference between Positioned.fill and Align?

Both Positioned.fill and Align are used to position widgets, but they work differently:

Positioned.fill:

  • Used inside a Stack to make a widget fill the entire Stack or match its parent’s size.
     
  • Can be combined with padding to adjust edges.
     
  • Only works inside Stack.
     

Align:

  • Positions a widget within its parent using an alignment property like Alignment.center or Alignment.topRight.
     
  • Works outside Stack and doesn’t require filling the parent.
     
  • Adjusts the widget’s position without stretching it.

42. What is flutter doctor?

flutter doctor is a command-line tool in Flutter that helps you check the setup and environment of your Flutter development system. It identifies missing dependencies, SDKs, or tools required to run Flutter apps.

Key Points:

  • Checks for Flutter SDK, Dart SDK, IDEs, and connected devices.
     
  • Provides a summary of issues and suggestions to fix them.
     
  • Helps ensure your development environment is ready.

43. What is Flutter’s render tree?

The render tree in Flutter is the internal structure that Flutter uses to draw widgets on the screen. It is created from the widget tree and contains RenderObjects that handle layout, painting, and compositing.

44. What is the difference between GestureDetector and InkWell?

GestureDetector:

  • Detects gestures like tap, double tap, long press, swipe, and more.
     
  • Does not provide visual feedback when tapped.
     
  • Can be used anywhere, including custom widgets.
     

InkWell:

  • Detects tap gestures and provides ripple effect as visual feedback.
     
  • Must be used inside Material widgets.
     
  • Ideal for buttons and clickable cards.

45. What is the difference between Future and Stream in Flutter?

Future:

  • Represents a single asynchronous value.
     
  • Completes once and then returns the result or error.
     
  • Commonly used for API calls or one-time data fetching.
     

Stream:

  • Represents multiple asynchronous values over time.
     
  • Can emit data continuously, like a live feed or notifications.
     
  • Used with StreamBuilder to update UI automatically.

     

46. How to call APIs in Flutter?

In Flutter, APIs are called using HTTP requests to fetch or send data from a server. The http package is commonly used for making API calls.

Key Points:

Use the http package for GET, POST, PUT, DELETE requests.
Handle asynchronous requests using async and await.
Parse the response, usually in JSON format, to use in your app.
Example:

47. How to handle JSON in Flutter?

Use dart:convert to decode and encode JSON

In Flutter, JSON data is commonly used when receiving or sending data to APIs. Flutter handles JSON using Dart’s built-in dart:convert library to convert JSON into Dart objects and vice versa.

Key Points:

  • JSON is handled using jsonDecode() and jsonEncode().
     
  • API responses are usually converted into Dart maps or model classes.
     
  • Model classes make data easier to manage and type-safe.
     

Example (Decoding JSON):

48. What is difference between hot reload and rebuild in Flutter?


Hot Reload:

  • Updates the UI instantly during development.
     
  • Keeps the current app state (like counters or form data).
     
  • Injects updated code into the running app without restarting it.
     
  • Used mainly for fast development and testing.
     

Rebuild:

  • Happens when Flutter re-runs the build() method of widgets.
     
  • Can occur due to setState(), parent widget changes, or hot reload.
     
  • Updates the UI based on the current state values.

49. What is difference between async and Future?

  • async: Marks a function asynchronous.
     
  • Future: Represents the result returned in future.
     

50. How to handle local storage in Flutter?

In Flutter, local storage is used to save data on the device so it can be accessed later, even after the app is closed. Flutter provides different ways to store data depending on the use case.

Key Points:

SharedPreferences: Used for storing small key–value data like login status or theme settings.
SQLite (sqflite): Used for storing structured and large data in tables.
Local files: Used for storing text or JSON files on the device.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.

How to extract filename from Uri?

Now, we can extract filename with and without extension :) You will convert your bitmap to uri and get the real path of your file. Now w...