Dart Top 10 Interview Questions

1) What does ".." mean in Dart?

".." in Dart means "cascade operator", and is used for easy configuration.

The difference between ".." and "." Is that the return from calling ".." is equivalent to this, and "." Returns the value returned by the method


2) Explain Dart scope?

Dart is no "public" "private," and other keywords, the default is public, private variables with an underscore _beginning


3) Is Dart a single-threaded model? How does it work?

Dart is a single-threaded model

Dart runs in a single thread with a message loop mechanism, which contains two task queues, one is a "micro task queue" microtask queue and the other is called an "event queue" event queue .
After the entry function main () is executed, the message loop mechanism is started. First, the tasks in the micro task queue will be executed one by one in accordance with the FIFO order. After all the micro task queues are executed, the tasks in the event queue will be executed. After the event tasks are executed, the micro tasks will be executed. Endlessly


4) How does Dart multitasking work in parallel?

Dart doesn't have multithreading, Dart which provides a similar new thread, but the worker does not operate independently of shared memory - an isolate


5) What is Dart Future?

Dart runs in a single thread with a message loop mechanism, which contains two task queues, one is a "micro task queue" micro task queue and the other is called an "event queue" event queue .

Future is in fact the case to the "event queue" in insert an event, when there is free time to go to perform, when finished will default callback Future.then(v)method.

And we can also use Future.microtaskto insert a mission to "micro-task queue" method, which would improve the efficiency of his execution.

Because in each isolate of Dart, the execution priority is: Main> MicroTask> EventQueue


6) What is Dart Stream

Stream, like Feature, is a tool for handling asynchronous.

But the difference between Stream and Feature is that Stream can receive multiple asynchronous results, while Feature has only one.

Stream can be used to create Stream.fromFuture, can also be used StreamController to create and control.

Another point to note is that an ordinary Stream can only have one subscriber. If you want to subscribe, you must use it asBroadcastStream()


7) Explain Lifecycle of StatefulWidget?

initState(): Widget initializes the current State. The Context cannot be obtained in the current method. If you want to obtain it, you can try Future.delayed()

didChangeDependencies(): In initState()the call, State the time change of the object dependencies will be called.

deactivate(): When State the time is temporarily removed from the tree view calls this method, this method is also called when the page switching, and Android in the onPause same.

dispose(): Called when the widget is destroyed.

didUpdateWidget: Called when the widget state changes


8) How does Flutter communicate with Android iOS?

Flutter by PlatformChannelinteracting with native, which PlatformChannelis divided into three types:

BasicMessageChannel: Used to pass strings and semi-structured messages.
MethodChannel: Used to pass method calls. Flutter actively calls Native methods and gets the corresponding return value.
EventChannel: for communication of event streams


9) What are Widgets, RenderObjects, and Elements?

Widget Only used to store the information needed for rendering.
RenderObject Responsible for managing layout, drawing and other operations.
Element This is the entity on this huge control tree


10) What is state management and why is it needed?

First of all, state is actually a conceptual thing, distinguishing between global state and local state.

The local state is, for example, the information entered in a control, and the global state is, for example, the userId requested from the background after login.

When more and more global states exist and multiple pages share a state, we need to manage it.

Common state management is:

  • ScopedModel
  • BLoC
  • Redux / FishRedux
  • Provider

11) What is BLoC Mode?

BLoC is a method of building applications using reactive programming. This is a completely asynchronous world composed of streams