250+ Flutter Interview Questions

1. Flutter Basics (30 Questions)

Q1. What is Flutter?

A: Flutter is an open-source UI toolkit by Google for building natively compiled applications for mobile, web, and desktop from a single codebase using the Dart programming language.

Q2. What is Dart, and why is it used in Flutter?

A: Dart is a client-optimized programming language for apps on multiple platforms. Flutter uses Dart for its fast performance, hot reload feature, and ability to compile to native code.

Q3. What is the role of the main() function in a Flutter app?

A: The main() function is the entry point of a Flutter app. It initializes the app and runs the root widget using runApp().

Q4. What is a widget in Flutter?

A: A widget is a building block of a Flutter UI. Everything in Flutter, like buttons, text, or layouts, is a widget, and they are composed to create the app’s interface.

Q5. Explain the difference between Stateless and Stateful widgets.

A: A StatelessWidget is immutable and doesn’t change its UI after being built (e.g., static text). A StatefulWidget is mutable, allowing UI updates when its state changes (e.g., a counter).

Q6. What is the build() method in Flutter?

A: The build() method describes the widget’s UI. It returns a widget tree that Flutter renders on the screen and is called whenever the UI needs to be updated.

Q7. What is hot reload in Flutter?

A: Hot reload allows developers to see UI changes instantly without restarting the app, preserving the app’s state. It speeds up development by recompiling only the changed code.

Q8. What is the purpose of the pubspec.yaml file?

A: The pubspec.yaml file manages the app’s dependencies, assets, and metadata like name, version, and description. It’s used by the Pub package manager.

Q9. What is a MaterialApp widget?

A: MaterialApp is a widget that sets up a Flutter app with Material Design structure, including navigation, themes, and scaffolding for the app’s UI.

Q10. What is the Scaffold widget used for?

A: The Scaffold widget provides a basic app structure with components like AppBar, Drawer, FloatingActionButton, and Body for building Material Design layouts.

Q11. What is the difference between runApp() and MaterialApp?

A: runApp() is a function that starts the Flutter app by rendering the root widget. MaterialApp is a widget that configures the app with Material Design features.

Q12. How do you add a dependency in Flutter?

A: Add the dependency (e.g., http: ^1.2.0) under dependencies in the pubspec.yaml file, then run flutter pub get to fetch it.

Q13. What is a BuildContext in Flutter?

A: BuildContext is an object that holds the location of a widget in the widget tree. It’s used to access theme, navigation, or other inherited widget data.

Q14. What is the setState() method used for?

A: The setState() method notifies Flutter to rebuild the UI when the state of a StatefulWidget changes, triggering the build() method.

Q15. What is the role of the key property in a widget?

A: The key property uniquely identifies a widget in the widget tree, helping Flutter efficiently update or reorder widgets during rebuilds.

Q16. What is the Expanded widget used for?

A: The Expanded widget makes a child widget take up all available space within a Row, Column, or Flex, distributing space based on its flex property.

Q17. Explain the SafeArea widget.

A: The SafeArea widget ensures its child widgets avoid system UI intrusions like notches, status bars, or navigation bars, keeping content visible.

Q18. What is the Container widget?

A: The Container widget is a versatile widget for styling, sizing, and positioning its child with properties like padding, margin, color, and decoration.

Q19. What is the purpose of the async and await keywords in Dart?

A: async marks a function as asynchronous, allowing it to perform tasks like API calls. await pauses execution until a future completes, returning its result.

Q20. Write a simple Flutter app to display “Hello, World!” in the center of the screen.

A:

import ‘package:flutter/material.dart’;

void main() {

  runApp(MyApp());

}

class MyApp extends StatelessWidget {

  @override

  Widget build(BuildContext context) {

    return MaterialApp(

      home: Scaffold(

        body: Center(

          child: Text(‘Hello, World!’),

        ),

      ),

    );

  }

}

Q21. What is the ThemeData class used for?

A: ThemeData defines the visual style (colors, fonts, etc.) for a Flutter app or widget tree, applied via MaterialApp or Theme widget.

Q22. What is a GestureDetector widget?

A: GestureDetector is a widget that detects user gestures like taps, swipes, or drags on its child and triggers callbacks like onTap or onPanUpdate.

Q23. What is the Future class in Dart?

A: A Future represents a value that will be available later, used for asynchronous operations like API calls. It resolves to a value or an error.

Q24. How do you handle errors in a Future?

A: Use try-catch with await or the .catchError() method on a Future to handle errors gracefully.

Q25. What is the Column widget?

A: The Column widget arranges its children vertically in a linear layout, stacking them from top to bottom.

Q26. What is the Row widget?

A: The Row widget arranges its children horizontally in a linear layout, placing them side by side.

Q27. What is the ListView widget used for?

A: The ListView widget displays a scrollable list of children, either vertically or horizontally, ideal for long lists of items.

Q28. How do you add padding to a widget?

A: Use the Padding widget with the padding property (e.g., EdgeInsets.all(16)) to add space around its child widget.

Q29. What is the AppBar widget?

A: The AppBar widget creates a top bar in a Scaffold, typically containing a title, actions, and navigation controls.

Q30. What is the difference between mainAxisAlignment and crossAxisAlignment in a Row or Column?

A: mainAxisAlignment controls alignment along the primary axis (horizontal for Row, vertical for Column). crossAxisAlignment controls alignment along the perpendicular axis.

Read the complete eBook on our Android app.

This is just a demo preview. Download our app to unlock all chapters with full access and learn anytime, anywhere.

Read the complete eBook on our Android app.

This is just a demo preview.
Download our app to unlock all chapters with full access and learn anytime, anywhere.

Related ebooks

Continue reading