Flutter Interview Question
Flutter Interview Question
1. What is Dart?
a. Dart is a general-purpose, object-oriented programming language with C-style syntax. It is open-
source and developed by Google in 2011. The Dart language can be compiled both AOT (Ahead-
of-Time) and JIT (Just-in-Time.
2. What is Flutter?
a. Flutter is a framework developed by Google that allows you to build natively compiled mobile
applications with one programming language and a single codebase. Flutter is not a language;
it is an SDK. Flutter apps use Dart programming language for creating an app. Flutter is mainly
optimized for 2D mobile apps that can run on both Android and iOS platforms.
Profile mode is used to measure the performance of our applications. In this mode, some
debugging ability is maintained to profile your app's performance. This mode is disabled on the
emulator and simulator because they are not representative of real performance.
Release mode allows us to optimize the codes and generate them without any debug data in a
fully optimized form. In this mode, many of the application's code will be entirely removed or
rewritten. We use this mode when we are ready to release the app. It enables maximum
optimization and minimal footprint size of the application.
Widget Tests: It tests a single widget. Its goal is to ensure that the widget's UI looks and interacts
with other widgets as expected.
Integration Tests: It validates a complete app or a large part of the app. Its goal is to ensure that
all the widgets and services work together as expected.
For mobile applications the source code is compiled for multiple processors ARM, ARM64, x64
and for both platforms - Android and iOS. This means there are multiple resulting binary files
for each supported processor and platform combination.
10.What is a Widget? and how many types of widgets are there in Flutter?
a. Widgets are high level objects used to describe any part of an application. It can be but is not
limited to UI elements, layout (alignment, padding, ...), data (theme, configurations, …). In
flutter everything is a widget, almost everything you'll code will be inside a Widget. There are 2
types of widgets in Flutter, Stateless & Stateful widgets.
StatefulWidget is also immutable, but it’s coupled with a State Object that allows you to
rebuild the widget with new values whenever calling setState().
12.What is the difference between WidgetsApp and MaterialApp?
a. WidgetsApp provides basic navigation. Together with the widgets library, it includes many of
the foundational widgets that Flutter uses.
MaterialApp and the corresponding material library is a layer built on top of WidgetsApp and
the widgets library. It implements Material Design, which gives the app a unified look and feel
on any platform or device. You can also use CupertinoApp to make iOS users feel at home, or
you can even build your own set of custom widgets to fit your brand.
16.What is a Stream?
a. It is a sequence of asynchronous data. We can create a stream using async generator ( async*)
and listen to it using listen(). There are 2 types of streams, Single Subscription and
Broadcast streams.
Broadcast Streams: These streams deliver events to their subscribers. Upon subscribing to
events, subscribers are immediately able to start listening to them. These are versatile streams
that allow several listeners to listen simultaneously. Furthermore, one can listen again even
after canceling a previous subscription.
18.What is BuildContext and how is it useful?
a. It is actually the widget's element in the Element tree, so every widget has its own
BuildContext. You usually use it to get a reference to the theme or to another widget. For
example, if you want to show a material dialog, you need a reference to the scaffold. You can
get it with Scaffold.of(context), where context is the build context. of() searches up the
tree until it finds the nearest scaffold.
While Optional parameters doesn’t have to be specified by the caller while calling the function.
Optional parameters can only be declared after required parameters. It can be Positional [ ] or
Named { }, it can also have a default value, which is used when a caller does not specify a value.
23.What is MediaQuery?
a. It provides a higher-level view of the current app’s screen size and can also give more detailed
information about the device and its layout preferences.
24.Why do we need Mixins?
a. Dart does not support multiple inheritances. Thus, to implement multiple inheritances in
Flutter/Dart, we need mixins. Mixins provide a way to write the reusable class's code in multiple
class hierarchies.
Every isolate has an event loop, which schedules asynchronous tasks to run. The tasks can be
on one of two different queues: the microtask queue or the event queue. Microtasks always
run first, but they are mainly internal tasks that the developer doesn't need to worry about.
Calling a future puts the task on the event queue when the future completes.
A lot of new Dart programmers think async methods run on a separate thread. Although that
may be true for I/O operations that the system handles, it isn't the case for your own code.
That's why if you have an expensive computation, you need to run it on a separate isolate.
App State: It is the state that we intend to share across different parts of the app and which we
want to maintain between sessions. These types of states can thus be used globally.
On the other hand, there’s also a danger of being too reliant on third party packages. They can
break, have bugs, or even be abandoned. When you need to switch to a new package down the
road, you might have to make huge changes to your code.
Typically, small applications are served well by just using the Navigator API, via the MaterialApp
constructor’s MaterialApp.routes property.
More elaborate applications are usually better served by the Router API, via the
MaterialApp.router constructor. This requires some more up-front work to describe how
to parse deep links for your application and how to map the application state to the set of active
pages but is more expressive in the long run.
2) When possible, use const constructor to tell Flutter that it doesn't need to rebuild the widget.
3) Keep the subtree of a stateful widget as small as possible. If a stateful widget needs to have
a subtree under it, create a custom widget for the stateful widget and give it a child parameter.
• General project settings, like name of the project, version, description, etc.
• Dependencies within a project.
• The assets of the project (e.g., images, audio, etc.)