Flutter Interview Questions and Answers


What is Flutter?
  • Flutter is an open-source UI software development toolkit created by Google. It's used for building natively compiled applications for mobile (Android and iOS), web, and desktop from a single codebase.
What is Dart? Why does Flutter use Dart?
  • Dart is an object-oriented, class-based, garbage-collected programming language developed by Google. Flutter uses Dart for several reasons:
    • Performance: Dart can be compiled into native code, providing excellent performance.
    • Productivity: Dart's features like hot reload and a strong type system improve developer productivity.
    • Ahead-of-Time (AOT) and Just-in-Time (JIT) Compilation: Dart supports both, enabling fast development cycles (JIT for hot reload) and high performance in production (AOT).
    • Garbage Collection: Simplifies memory management.
Explain the difference between Stateless and Stateful Widgets.
  • Stateless Widget: A widget that does not have mutable state. Its configuration is set when the widget is created and remains unchanged throughout its lifetime. Examples: Text, Icon, Image.
  • Stateful Widget: A widget that has mutable state. Its state can change over time in response to user interactions or other events. When the state changes, the widget is rebuilt to reflect the new state. Examples: Checkbox, Slider, widgets that handle user input or animations.
What is the purpose of the setState() method?
  • setState() is a method in StatefulWidget that is called to notify the Flutter framework that the internal state of an object has changed. Calling setState() schedules the build() method to be called again, causing the UI to be updated to reflect the new state.
What is the widget tree in Flutter?
  • The widget tree is a conceptual tree structure that represents the hierarchy of widgets in your Flutter application's UI. The root of the tree is typically your main application widget (e.g., MaterialApp or CupertinoApp), and it branches down to all the individual widgets that make up the UI.
Explain the concept of Hot Reload and Hot Restart.
  • Hot Reload: Allows you to quickly see the effect of code changes in your running application without losing the current state. It injects updated source code files into the running Dart Virtual Machine (VM).
  • Hot Restart: Restarts the entire application from scratch, discarding the current state. It's faster than a full restart but slower than hot reload. Useful when changes affect the application's fundamental structure or state.
What is the difference between MaterialApp and CupertinoApp?
  • MaterialApp: Provides widgets and themes that follow the Material Design guidelines (Android-style).
  • CupertinoApp: Provides widgets and themes that follow the iOS Human Interface Guidelines (iOS-style).
What is a Scaffold widget?
  • Scaffold is a basic Material Design visual layout structure. It provides a standard structure for an app screen, including elements like AppBar, body, floatingActionButton, bottomNavigationBar, drawer, etc.
How do you handle user input from a TextField?
  • You can use a TextEditingController to get and set the text in a TextField. You can also use the onChanged or onSubmitted callbacks.
What is the purpose of the pubspec.yaml file?
  • The pubspec.yaml file is a configuration file for your Flutter project. It's used to:
    • Manage project dependencies (packages).
    • Define project metadata (name, description, version).
    • Specify assets (images, fonts, etc.).
How do you add external packages to your Flutter project?
  • You declare the package in the dependencies section of your pubspec.yaml file and then run flutter pub get in your terminal.
What is the main function in a Flutter application?
  • The main() function is the entry point of your Dart application. In a Flutter app, it typically calls runApp() with your main application widget.
What is a Future in Dart? How is it used in asynchronous programming?
  • A Future represents a value or error that will be available at some point in the future. It's used for asynchronous operations like fetching data from the internet or reading a file. You use async and await keywords to work with Futures in a more synchronous-looking way.
Explain the difference between async and await keywords.
  • async: Marks a function as asynchronous, indicating that it may contain await expressions. An async function always returns a Future.
  • await: Pauses the execution of an async function until the awaited Future completes. The value of the await expression is the result of the completed Future.
What is a FutureBuilder?
  • FutureBuilder is a widget that builds itself based on the latest snapshot of interaction with a Future. It's useful for displaying data that will be available asynchronously (e.g., fetching data from an API).
How do you handle navigation between screens in Flutter?
  • Using the Navigator class and its methods like push() and pop() for simple navigation.
  • Using named routes with Navigator.pushNamed() for more structured navigation.
What is the purpose of Navigator.push() and Navigator.pop()?
  • Navigator.push(): Pushes a new route onto the navigator stack, effectively navigating to a new screen.
  • Navigator.pop(): Removes the current route from the navigator stack, returning to the previous screen.
What are named routes in Flutter? How do you use them?
  • Named routes are a way to define routes using string names (e.g., '/home', '/settings'). You define them in the routes map of your MaterialApp or CupertinoApp and navigate using Navigator.pushNamed(). This makes your navigation code cleaner and easier to manage.
How do you pass data between screens during navigation?
  • Using constructor arguments: Pass data to the constructor of the new screen's widget when using Navigator.push().
  • Using route arguments: Pass data as arguments when using Navigator.pushNamed() and access them using ModalRoute.of(context)!.settings.arguments in the destination screen.
What is the purpose of the key parameter in widgets?
  • Keys are used to uniquely identify widgets and their associated state. They are particularly important when dealing with lists of widgets that change dynamically, as they help Flutter efficiently update the UI by matching the old and new widget trees.
Explain the difference between const and final in Dart.
  • const: A compile-time constant. The value must be known at compile time and cannot be changed. Instances of const objects are canonicalized (only one instance is created for identical values).
  • final: A runtime constant. The value is assigned at runtime and cannot be changed after it's initialized.
What are the different types of tests in Flutter?
  • Unit Tests: Test a single function, method, or class.
  • Widget Tests: Test a single widget in isolation.
  • Integration Tests: Test the entire application flow or large parts of it running on a real device or emulator.
How do you perform asynchronous operations in Flutter?
  • Using Future and the async/await keywords.
  • Using streams for handling sequences of asynchronous events.
What is a Stream in Dart?
  • A Stream represents a sequence of asynchronous events. It's useful for handling continuous data flows, like user input events, network responses, or real-time data updates.
What is the purpose of the Provider package for state management?
  • The Provider package is a popular and simple state management solution. It makes it easy to provide data to descendants in the widget tree and rebuild widgets when the data changes. It leverages the concept of InheritedWidgets internally.
How do you use ChangeNotifierProvider with the Provider package?
  • You create a class that extends ChangeNotifier and call notifyListeners() when the state changes.
  • You wrap a part of your widget tree with ChangeNotifierProvider to provide an instance of your ChangeNotifier.
  • You use Consumer or Provider.of() to access the data in descendant widgets.
What is the difference between Consumer and Provider.of(context)?
  • Consumer: A widget that rebuilds its child subtree whenever the provided data changes. It's more granular and can lead to better performance by limiting the scope of rebuilds.
  • Provider.of(context): Retrieves the provided data. By default, it also causes the widget to rebuild when the data changes. You can use listen: false to prevent rebuilding if you only need to read the data.
What is the purpose of the InheritedWidget?
  • InheritedWidget is a base class for widgets that efficiently propagate information down the widget tree. When an InheritedWidget changes, any dependent widgets that registered for updates will be rebuilt. Many state management solutions, including Provider, use InheritedWidgets under the hood.
How do you fetch data from a REST API in Flutter?
  • Using the http package to make HTTP requests (GET, POST, etc.).
  • Decoding the JSON response using dart:convert.
  • Mapping the JSON data to Dart objects (models).
How do you handle errors during HTTP requests?
  • Using try-catch blocks to handle exceptions that might occur during the request.
  • Checking the HTTP status code of the response to determine if the request was successful.
What is the purpose of the FutureBuilder widget?
  • FutureBuilder is used to build a widget tree based on the state of a Future. It allows you to show different UI based on whether the Future is pending, completed with data, or completed with an error.
How do you handle file uploads in Flutter?
  • Using packages like image_picker for picking images or the http package to send files as part of a multipart request.
How do you store data locally in a Flutter application?
  • shared_preferences: for simple key-value storage.
  • sqflite: for working with SQLite databases.
  • File system: reading and writing files.
  • Other packages for more complex local databases (e.g., Hive, Moor).
What is the difference between mainAxisAlignment and crossAxisAlignment in Row and Column?
  • mainAxisAlignment: Aligns children along the main axis (horizontal for Row, vertical for Column).
  • crossAxisAlignment: Aligns children along the cross axis (vertical for Row, horizontal for Column).
How do you add padding or margin to a widget?
  • Using the Padding widget to add space inside the widget's boundary.
  • Using the Container widget's padding and margin properties.
How do you display a list of items in Flutter?
  • Using ListView for simple lists.
  • Using ListView.builder for efficiently building lists with a large number of items.
What is the purpose of ListView.builder?
  • ListView.builder is more efficient than a regular ListView for lists with a large or infinite number of items because it only builds the widgets that are currently visible on the screen, recycling existing ones as the user scrolls.
How do you handle taps on list items?
  • Wrap each list item widget (or the part you want to be tappable) with an InkWell or GestureDetector and use their onTap callback.
What is the purpose of the Expanded and Flexible widgets?
  • Expanded: Forces a child of a Row, Column, or Flex to fill the available space along the main axis.
  • Flexible: Gives a child of a Row, Column, or Flex the flexibility to shrink or expand to fill the available space, but it doesn't force it to fill the entire space.
How do you add images to your Flutter application?
  • Add the image file to the assets folder.
  • Declare the asset in the pubspec.yaml file under the assets section.
  • Use Image.asset('path/to/your/image.png') to display the image.
How do you display images from the internet?
  • Use Image.network('url_of_image'). Consider using a caching image library like cached_network_image for better performance.
What is the purpose of the setState() method? (Revisited)
  • setState() is called within a StatefulWidget's State object to notify the framework that the internal state has changed and that the UI should be rebuilt by calling the build() method again.
How do you create a custom widget in Flutter?
  • Define a new class that extends either StatelessWidget or StatefulWidget.
  • Implement the build() method to describe the widget's UI based on its properties and state.
What is the purpose of the const keyword when creating widgets?
  • Using const with a widget constructor indicates that the widget and its properties are compile-time constants. This allows Flutter to optimize rendering by reusing existing instances of identical const widgets instead of rebuilding them.
How do you handle orientation changes in Flutter?
  • Flutter automatically rebuilds the UI when the device orientation changes. You can use MediaQuery.of(context).orientation to detect the current orientation and build different layouts accordingly.
How do you restrict the orientation of your application?
  • Using the SystemChrome.setPreferredOrientations() method from the flutter/services.dart library.
What is the purpose of the pub get and pub upgrade commands?
  • flutter pub get: Fetches all the dependencies listed in your pubspec.yaml file.
  • flutter pub upgrade: Fetches the latest versions of all dependencies listed in your pubspec.yaml file, respecting version constraints.
What is a package in Flutter?
  • A package is a collection of Dart code and other assets that can be shared and reused across different Flutter projects. Packages are published on pub.dev.
What is a plugin in Flutter?
  • A plugin is a specific type of package that provides platform-specific functionality using native code (Kotlin/Java for Android, Swift/Objective-C for iOS).
How do you communicate between Dart code and native platform code?
  • Using Platform Channels:
    • MethodChannel: for invoking named methods.
    • EventChannel: for receiving a stream of events.
    • BasicMessageChannel: for sending structured messages.
What is the purpose of the debugShowCheckedModeBanner property in MaterialApp?
  • When set to true, it displays a "DEBUG" banner in the top-right corner of the app in debug mode. Set it to false for release builds.
How do you add custom fonts to your Flutter application?
  • Add the font files to an assets folder (e.g., fonts).
  • Declare the fonts in the pubspec.yaml file under the fonts section.
  • Use the font family name in TextStyle.
What is the difference between Opacity and AnimatedOpacity?
  • Opacity: Applies a static opacity to its child.
  • AnimatedOpacity: Animates the opacity of its child when the opacity value changes.
What are Implicit Animations? Give an example.
  • Implicit animations are animations that are triggered automatically when a property of an animatable widget changes. You don't need to explicitly manage an AnimationController. Examples: AnimatedContainer, AnimatedOpacity, AnimatedCrossFade.
What are Explicit Animations? Give an example.
  • Explicit animations require you to manually control the animation using an AnimationController. This gives you more control over the animation process. Examples: FadeTransition, SlideTransition, Hero animations.
What is a Hero animation?
  • A Hero animation is a type of transition that makes a widget appear to "fly" from one screen to another. It's used for visually connecting elements across different screens.
How do you handle form validation in Flutter?
  • Using the Form widget and TextFormField.
  • Providing a validator callback function to TextFormField.
  • Using the FormState to validate and save the form.
What is the purpose of the GlobalKey?
  • A GlobalKey is a unique key that can be used to access the state of a widget from anywhere in the application. It's useful for interacting with widgets whose state you need to access from outside their direct parent (e.g., accessing a FormState).
What are Theme and ThemeData in Flutter?
  • Theme: A widget that defines the visual properties (colors, fonts, shapes, etc.) for descendant widgets.
  • ThemeData: An object that contains the configuration for a Theme. You typically provide a ThemeData to your MaterialApp.
How do you access the current theme data in a widget?
  • Using Theme.of(context).
What is the purpose of the BuildContext?
  • BuildContext is a handle to the location of a widget in the widget tree. It's used to access ancestors in the tree (e.g., finding the nearest Scaffold or Theme). Each widget has its own BuildContext.
Explain the concept of "lifting state up".
  • "Lifting state up" is a pattern where state that is shared between multiple widgets is moved to a common ancestor widget. The ancestor manages the state and passes it down to the descendant widgets. This is a fundamental concept in state management.
What is the difference between crossAxisAlignment: CrossAxisAlignment.stretch and mainAxisAlignment: MainAxisAlignment.spaceBetween?
  • crossAxisAlignment: CrossAxisAlignment.stretch: Stretches the children along the cross axis to fill the available space.
  • mainAxisAlignment: MainAxisAlignment.spaceBetween: Places the children evenly along the main axis, with the first child at the start and the last child at the end, and the remaining space distributed between the children.
How do you create a responsive UI in Flutter?
  • Using layout widgets like Expanded, Flexible, LayoutBuilder, and OrientationBuilder.
  • Using MediaQuery.of(context) to get information about the device size and orientation.
  • Creating different layouts for different screen sizes (e.g., using separate widgets or conditional logic).
What is the purpose of the LayoutBuilder widget?
  • LayoutBuilder provides constraints (minimum and maximum width and height) from its parent. It's useful for building different layouts based on the available space, making your UI more responsive.
What is the purpose of the OrientationBuilder widget?
  • OrientationBuilder rebuilds its child whenever the device orientation changes. It's useful for building different UI based on whether the device is in portrait or landscape mode.
How do you handle background tasks in Flutter?
  • For short-lived tasks, you can use Isolate.spawn() to run code in a separate isolate (thread).
  • For longer-running or persistent tasks, you might need platform-specific solutions or packages that handle background execution (e.g., workmanager, firebase_jobdispatcher).
What is an Isolate in Dart?
  • An Isolate is an independent worker that has its own memory space and event loop. Isolates communicate with each other by sending messages. This is how Dart achieves concurrency without shared memory (preventing race conditions).
How do you handle permissions in Flutter (e.g., camera, location)?
  • Using platform-specific code or packages that handle permission requests (e.g., permission_handler). You need to request permissions from the user at runtime.
What is the purpose of the Dismissible widget?
  • Dismissible is a widget that can be dismissed by dragging it in a specified direction. It's commonly used in lists to implement swipe-to-delete functionality.
How do you add interactivity to a custom widget?
  • If the widget needs to manage its own state, make it a StatefulWidget and use setState() to trigger rebuilds.
  • Use GestureDetector or other gesture widgets to detect user interactions (taps, drags, etc.).
What is the purpose of the Flexible widget's flex property?
  • The flex property determines how much of the available space along the main axis a Flexible or Expanded widget should occupy relative to other flexible children. A child with flex: 2 will take up twice as much space as a child with flex: 1.
How do you display a dialog box in Flutter?
  • Using showDialog() from the Material library. You provide a builder function that returns the dialog widget (e.g., AlertDialog, SimpleDialog).
How do you display a bottom sheet?
  • Using showModalBottomSheet() from the Material library.
What is the difference between RaisedButton, FlatButton, and OutlineButton? (Note: these are deprecated in favor of ElevatedButton, TextButton, OutlineButton in newer Flutter versions)
  • RaisedButton (now ElevatedButton): Has a shadow and appears "raised". Used for primary actions.
  • FlatButton (now TextButton): Has no shadow or elevation. Used for less important actions.
  • OutlineButton (still OutlineButton): Has a border but no fill. Used for secondary actions.
How do you add custom icons to your Flutter application?
  • Using icon fonts. Add the font file to your assets and configure it in pubspec.yaml. Then, use the icon code points in Icon widgets.
What is the purpose of the GlobalKey? (Revisited)
  • A GlobalKey provides a unique identifier that is global across the entire application. It's used to access the state or the widget itself from anywhere in the widget tree, which is useful for scenarios like accessing form state or getting the size of a widget.
What is the difference between main() and runApp()?
  • main() is the entry point of your Dart application.
  • runApp() is a function provided by the Flutter framework that takes a widget and makes it the root of the widget tree, effectively starting the Flutter UI.
How do you handle different environments (development, production) in your Flutter app?
  • Using environment variables (can be challenging in Flutter directly, often handled during the build process).
  • Using different configuration files loaded based on build flags or environment variables.
  • Using packages that help manage configurations for different environments.
What is the purpose of the debugPrint() function?
  • debugPrint() is similar to print() but is specifically designed for debugging in Flutter. It handles long strings gracefully and doesn't interfere with the output of the running application in release mode.
How do you inspect the widget tree during development?
  • Using the Flutter DevTools, which provides a visual representation of the widget tree, performance metrics, and debugging tools.
What is the purpose of the Container widget?
  • Container is a convenience widget that combines common painting, positioning, and sizing widgets. It's often used for styling (color, decoration, padding, margin) and positioning its child.
What are Render Objects in Flutter? (Advanced)
  • Render objects are the low-level objects that handle the layout, painting, and hit testing of the UI. Widgets are a declarative way to configure the render tree.
Explain the build process of a Flutter application.
  • Dart code is compiled into native code (ARM or x86) for mobile and desktop, and into JavaScript for the web.
  • The Flutter engine (written in C++) handles rendering, text layout, platform channels, and other low-level tasks.
  • The native code communicates with the platform APIs.
What is the purpose of the pub get command? (Revisited)
  • flutter pub get downloads all the packages listed in the dependencies and dev_dependencies sections of your pubspec.yaml file.
How do you manage dependencies with version constraints?
  • You specify version constraints in the pubspec.yaml file using operators like ^ (caret), ~ (tilde), >, <, >=, <=. The caret operator (^) is commonly used and allows for updates to the latest non-breaking version.
What is the purpose of the pubspec.lock file?
  • The pubspec.lock file records the exact versions of all dependencies (including transitive dependencies) that were used when flutter pub get was last run. This ensures that everyone working on the project uses the same dependency versions.
How do you handle internationalization (i18n) and localization (l10n) in Flutter?
  • Using the flutter_localizations package and the intl package.
  • Defining localized strings in ARB files.
  • Generating localized code using the flutter gen-l10n command.
What is the purpose of the Localizations widget?
  • The Localizations widget provides access to the localized resources for the current locale.
How do you display a circular progress indicator?
  • Using the CircularProgressIndicator widget.
How do you display a linear progress indicator?
  • Using the LinearProgressIndicator widget.
What is the purpose of the Flexible widget's fit property?
  • The fit property determines how the Flexible widget's child is sized.
    • FlexFit.tight: The child is forced to fill the available space (similar to Expanded).
    • FlexFit.loose: The child can be as large as its intrinsic size, up to the available space.
How do you create a custom icon font?
  • Use a tool like Fontello or IcoMoon to create an icon font from SVG files.
  • Add the font file and its configuration to your Flutter project.
What are Keys? (Revisited)
  • Keys are identifiers for widgets, elements, and render objects. They are crucial for maintaining state when the widget tree changes dynamically.
What is the difference between ValueKey, ObjectKey, and UniqueKey?
  • ValueKey: Identifies widgets based on their value. Useful when widgets represent data items.
  • ObjectKey: Identifies widgets based on the identity of an object. Useful when widgets are associated with specific objects.
  • UniqueKey: Creates a unique key every time it's called. Useful when you need a guaranteed unique identifier.
How do you handle deep linking in Flutter?
  • Configure deep links in your Android (AndroidManifest.xml) and iOS (Info.plist) project files.
  • Use packages that help handle incoming deep links (e.g., uni_links).
What is the purpose of the WillPopScope widget?
  • WillPopScope controls whether the current route can be popped (e.g., by the user pressing the back button). It's useful for displaying a confirmation dialog before leaving a screen with unsaved changes.
How do you manage different environments (development, staging, production) in your app?
  • Using build configurations or flavors (Android) and schemes (iOS) to define environment-specific settings.
  • Using packages that help manage configurations for different environments.
What are Flavors in Flutter?
  • Flavors (or build configurations/schemes) allow you to define different versions of your application with different configurations (e.g., different API endpoints, app names, icons) for different environments (development, staging, production).
How do you build a release version of your Flutter application?
  • For Android: flutter build apk --release or flutter build appbundle --release.
  • For iOS: flutter build ipa --release.
What is the purpose of code signing in Flutter?
  • Code signing is a security measure that verifies the authenticity and integrity of your application. It's required to distribute your application through app stores.
What is the difference between APK and App Bundle for Android?
  • APK (Android Package Kit): A single file that contains all the code, resources, and assets for your Android app.
  • App Bundle: A publishing format that includes your app's compiled code and resources. Google Play uses the App Bundle to generate and serve optimized APKs for each user's device configuration. App Bundles are generally recommended.
What is the purpose of the SafeArea widget?
  • SafeArea is a widget that insets its child by sufficient padding to avoid intrusions by the operating system (e.g., notches, status bars, navigation bars). It ensures your UI is not obscured by these elements.
How do you handle keyboard visibility and scrolling when the keyboard appears?
  • Wrap your content in a SingleChildScrollView to allow scrolling when the keyboard covers input fields.
  • Use MediaQuery.of(context).viewInsets.bottom to get the height of the keyboard.
What is the purpose of the Flexible widget's fit property? (Revisited)
  • fit: FlexFit.tight forces the child to fill the available space.
  • fit: FlexFit.loose allows the child to be as large as its intrinsic size, up to the available space.
How do you create a custom painter in Flutter? (Advanced)
  • Create a class that extends CustomPainter and override the paint() method to draw on a canvas.
  • Use the CustomPaint widget to display your custom painting.
What is the purpose of the Stack widget?
  • The Stack widget allows you to layer widgets on top of each other. Children are positioned relative to the edges of the stack box.
What is the difference between Stack and Column/Row?
  • Stack layers widgets in the z-axis (on top of each other).
  • Column and Row arrange widgets along a single axis (vertically or horizontally).
How do you position children within a Stack?
  • Using the Positioned widget as a child of the Stack. Positioned allows you to specify the distance from the edges of the stack (top, bottom, left, right) and optionally the width and height.
What is the purpose of the AnimatedBuilder widget? (Advanced)
  • AnimatedBuilder is a performance optimization widget. It rebuilds only the part of the widget tree that depends on an animation, preventing unnecessary rebuilds of the entire widget tree during an animation.
What is the purpose of the MediaQuery widget?
  • MediaQuery provides information about the media (e.g., size, orientation, device pixel ratio, text scale factor). You access its data using MediaQuery.of(context). It's essential for building responsive UIs.
How do you handle platform-specific UI differences (e.g., iOS vs. Android)?
  • Using conditional logic based on Theme.of(context).platform or Platform.isIOS/Platform.isAndroid from dart:io.
  • Using platform-specific widgets like MaterialApp and CupertinoApp at the root level, or using libraries that provide platform-adaptive widgets.
What is the purpose of the Expanded widget? (Revisited)
  • Expanded is a widget that expands a child of a Row, Column, or Flex to fill the available space along the main axis. It uses the FlexFit.tight fit.
What is the purpose of the Flexible widget? (Revisited)
  • Flexible is similar to Expanded but gives the child flexibility in how it fills the available space using the fit property. It doesn't force the child to fill the entire space.
How do you add shadows to a widget?
  • Using the BoxDecoration in a Container and setting the boxShadow property.
  • Using widgets that have built-in shadow properties (e.g., ElevatedButton).
  • Using the PhysicalModel widget for more control over shadows.
What is the purpose of the ClipRRect widget?
  • ClipRRect clips its child using a rounded rectangle. It's commonly used to apply rounded corners to images or other widgets.
What is the purpose of the ClipOval widget?
  • ClipOval clips its child into an oval shape. It's commonly used to make circular profile pictures.
What is the purpose of the InkWell widget?
  • InkWell is a Material Design widget that provides a visual ripple effect when tapped. It's often used to make non-button widgets tappable.
What is the difference between GestureDetector and InkWell?
  • GestureDetector is a more general-purpose widget for detecting various gestures (tap, drag, long press, etc.) and does not provide a visual feedback by default.
  • InkWell is specifically for tap gestures in Material Design and provides the Material Design ripple effect.
How do you add a gradient background to a widget?
  • Using the BoxDecoration in a Container and setting the gradient property.
What is the purpose of the Spacer widget?
  • Spacer is a widget that takes up space in a Row or Column. It's useful for creating flexible spacing between widgets. It's essentially a Expanded widget with a default flex of 1.
How do you handle different screen sizes and densities?
  • Using layout widgets (Expanded, Flexible, LayoutBuilder).
  • Using MediaQuery.of(context) to get screen information.
  • Providing different asset variants (e.g., images for different pixel ratios) in your pubspec.yaml.
What is the purpose of the SliverAppBar in a CustomScrollView? (Advanced)
  • SliverAppBar is an app bar that integrates with a CustomScrollView to provide dynamic scrolling behavior (e.g., collapsing and expanding).
What are Slivers in Flutter? (Advanced)
  • Slivers are portions of a scrollable area. They are used in CustomScrollView to create custom scrolling effects and efficiently handle large lists of items. Examples: SliverList, SliverGrid, SliverAppBar.
How do you profile the performance of your Flutter application?
  • Using the Flutter DevTools performance tab to monitor CPU usage, UI and GPU threads, and identify performance bottlenecks.
What is the difference between the UI thread and the GPU thread in Flutter?
  • UI Thread: Runs the Dart code, builds the widget tree, and creates the layer tree.
  • GPU Thread: Renders the layer tree to the screen. Performance issues in the UI thread can lead to jank (dropped frames).
What is "jank" in Flutter?
  • Jank refers to dropped frames, which causes the UI to stutter or appear choppy. It happens when the UI thread or GPU thread takes too long to process a frame (ideally, frames should be rendered at 60fps or 120fps).
How can you avoid jank in your Flutter application?
  • Avoid expensive computations on the UI thread.
  • Use const widgets and widget keys to optimize rebuilds.
  • Use efficient list building widgets (ListView.builder, GridView.builder).
  • Perform background tasks in Isolates.
What is the purpose of the RepaintBoundary widget? (Advanced)
  • RepaintBoundary creates a separate layer for its child, which can improve performance by preventing the child from being repainted when unrelated parts of the UI change. Use it cautiously, as creating layers can also have overhead.
How do you handle dependency injection in Flutter?
  • Using packages like get_it or provider (which can also be used for dependency injection).
What is the purpose of the NavigatorObserver? (Advanced)
  • NavigatorObserver allows you to observe events happening within the Navigator (e.g., routes being pushed or popped). It's useful for logging navigation events or integrating with analytics.
How do you add a splash screen to your Flutter application?
  • This is typically handled on the native platform side (Android and iOS) by configuring the launch screen or splash screen in the native project files.
What is the purpose of the Overlay widget? (Advanced)
  • Overlay is a stack of entries that can be used to display widgets on top of other widgets, independent of the normal widget tree flow. It's used for things like dialogs, tooltips, and custom overlays.
How do you handle push notifications in Flutter?
  • Using packages like firebase_messaging or other platform-specific notification packages.
  • Configuring push notification services on the native platforms.
What is the purpose of the GlobalKey? (Final revisit)
  • A GlobalKey provides a unique identifier that is global across the entire application. It's used to access the state or the widget itself from anywhere in the widget tree. This is necessary when you need to interact with a widget whose state or methods are not directly accessible through the normal widget tree hierarchy.