Flutter

 

Flutter Interview Questions














Here in this article, I will be sharing some Flutter Interview questions collections which will help you to crack your interview very easily.

Flutter Questions

1. What is Flutter?
Flutter is an open-source UI toolkit from Google for crafting beautiful, natively compiled applications for desktop, web, and mobile from a single codebase. Flutter apps are built using the Dart programming language.

2. What are the advantages of using flutter?
For developing mobile applications, Flutter usually fulfills the custom needs and requirements. 

It offers the following advantages:- 
    1. Hot Reload 
    2. Fast Development 
    3. Screen Reader 
    4. Quick Rendering 
    5. Cross-platform 
    6. Flutter goes native 
    7. Open source & free 
    8. Themes for Android & iOS

3. What are the types of widgets present in flutter?

In flutter, widgets can be divided into two categories:- 
1.  Stateless Widget:-  Input Data-->Widget-->Renders UI 
2. Stateful Widget:-  Input Data-->Widget-->Internal State-->Renders UI

Stateless Widget:- A widget that does nothing is a Stateless Widget. In essence, they are static and don’t store any state.   Thus, they don't save values that may change. 

Stateful Widget:- A widget that does anything is a Stateful Widget. Stateful widgets are dynamic by nature, which means they can monitor changes and update the UI accordingly.

4. Write the difference between main() and runApp() in flutter?
main():- This function starts the program. Flutter does not allow us to write any program without the main() function. 

runApp():- Using runApp(), you are able to return the widgets that are connected to the screen as a root of the widget tree that will be rendered on the screen. This function is called in the main function, which is the driver of the app.

5. What are the best editors for Flutter development?
Here are some popular IDEs for Flutter development:-
    1. Android Studio 
    2. Visual Studio
    3. IntelliJ IDEA 
    4. Xcode 
    5. Eclipse 
    6. Emacs Vim, etc.

6. Why do we need mixins?
Dart does not support multiple inheritances. Thus to implement the multiple inheritances in Flutter/Dart, we need mixins. Mixins provide a way to write the reusable class's code in multiple class hierarchies.

7. In What technology is Flutter built?
Flutter is built using C, C++, Skia - 2D rendering engine and Dart (a modern, concise, object-oriented language).

8. What is the use of the pubspec.yaml file?
When you create a new Flutter project, It includes a pubspec.yaml file also known as 'pubspec' at the top of the project tree. IT contains metadata about the project that is required by Dart and Flutter tooling. It is written in YAML and human readable. The pubspec file contains the dependency information that project requires like packages and their versions, fonts etc.

9. What is BuildContext?
BuildContext in Flutter is the part of the widgets in the Element tree so that each widget has its own BuildContext. We mainly use it to get a reference to another widget or theme. For example, if we want to use a material design element, it is required to reference it to the scaffold. We can get it using the Scaffold.of(context) method.

10. What do you understand from 'State'? What is the use of the setState() method?
State refers to the information that you can read synchronously when a widget is built and it might change during the lifetime of the widget. The widget implementor should ensure that the 'State' is promptly notified on change of state using State.setState method. The 'setState' method is used to notify the changed state of an internal object.

11. Explain the lifecycle of a StatefulWidget?
The State objects have following lifecycle methods. 
    1. createState 
    2. initState 
    3. didChangeDependencies 
    4. build 
    5. didUpdateWidget 
    6. setState 
    7. deactivate 
    8. dispose

12. When to use main Axis Alignment and cross Axis Alignment?
For Row: mainAxisAlignment = Horizontal Axis crossAxisAlignment = Vertical Axis 

For Column: mainAxisAlignment = Vertical Axis crossAxisAlignment = Horizontal Axis

13. What are the different build modes in Flutter?
The modes are:- 
    1. Debug 
    2. Profile 
    3. Release

14. What is Flex box in Flutter?
The Flex class in Flutter is used to display its children in a one-dimensional array. With this widget, you can control the axis where the children are placed. This axis is called as the main axis.

15. What is use of http package in Flutter?
The HTTP package is used in the Flutter project to provide a simple way to fetch data from the Internet. You can use the HTTP package by just adding it to the pubspec.yaml package.

16. What is use of Navigation.push and Navigation.pop function?
The push method is used to add a route to the stack of routes managed by the navigator. The pop method is used to remove the current route from the stack of routes managed by the navigator.

Darts Questions

17. What is Dart ?
Dart is a client-oriented programming language that may create quick apps for various platforms, including mobile, desktop, server, and online. Dart is an object-oriented, garbage-collected, open-source general-purpose programming language with C-style syntax. 

It was created by Google and later certified as a standard by the European Committee for Standardization (ECMA). Dart is a server-side and browser-side programming language.

18. What is the use of Dart?
Dart is used in association with Flutter to create mobile apps. This is one of Dart's most popular applications nowadays. The fact that Dart and Flutter are cross-platform is a significant advantage. It means that instead of creating two different apps for iPhone and Android, you can create an app with simply one codebase.

19. What are the data types in the Dart language?
    1. Strings: String values are represented by the keyword String. 
    2. Booleans: A Boolean value is represented by the bool keyword. 
    3. Lists: Predefined List classes are used to describe lists. 
    4. Maps: Predefined Map classes are used to describe Maps. 
    5. The Dynamic Type: The dynamic keyword is explicitly used as a type annotation.

20.What is type-checking in Dart?
Type checking in Dart is the process of testing and enforcing the constraints of types at either compile-time (i.e., statically) or runtime (i.e., dynamically). 

21. Which OS does Dart language supports ?
Dart language supports Linux, macOS and Windows operating system

22. What are streams in Dart?
A Stream is a sequence of asynchronous events. It is like an asynchronous Iterable—where, instead of getting the next event when you ask for it, the stream tells you that there is an event when it is ready. In other words, streams are a source of asynchronous events delivered sequentially. 

For example: 
Future<int> sumStream(Stream<int> stream) async { 
            var sum = 0; 
            await for (final value in stream) { 
                               sum += value; 
                      
            return sum; 
}

23. What is a pub in Dart?
In Dart, pub is a tool for manage Dart packages.

25. What are the types of list in Dart?
There are two types of list in Dart that are given below: 
    1. Fixed Length List : (length fixed) 
    2. Growable List: (Length can change at runtime.

26. What is a constructor in Dart?
A constructor is a special function of the class that is responsible for initializing the variables of the class. Dart defines a constructor with the same name as that of the class. A constructor is a function and hence can be parameterized.

27. What is Null -aware operator in Dart?
Dart's null-aware operators allow you to perform calculations based on whether or not a value is null. It's a shortened version of a longer expression. Instead of throwing an error, a null-aware operator can be used to make nullable types useful in Dart. The null check operator ! will treat the nullable value in front of it, a variable that may or may not be null, as non-nullable.

28. What does async and await do in Dart?
Asynchronous function is a function that returns the type of Future. We put await in front of an asynchronous function to make the subsequence lines waiting for that future's result. We put async before the function body to mark that the function support await.

29. What's the difference between async and async * in Dart?
- async gives you a Future 
- async* gives you a Stream.

30. What are the Snapshots in Dart?
The Dart relies heavily on snapshots. Snapshots are files that include objects and other runtime information. 

Script snapshots:- Snapshot files can be created from Dart programs. All of the program code and dependencies are prepared and ready to run in these folders. This enables quick start-ups. 

Full snapshots:- The Dart core libraries can be compiled into a snapshot file, allowing them to be loaded quickly. The core libraries are prebuilt snapshots that are loaded at runtime in most standard distributions of the main Dart 

Object snapshots:- Dart is an asynchronous programming language. For concurrency, it takes advantage of isolates. Because these are message-passing workers, a mechanism to serialize a message is required. This is accomplished by creating a snapshot from a particular object, which is then passed to another isolate for deserialization.

31. What build modes are available in Flutter?
Flutter is made up of three build modes: - 
1. Debug Mode- This mode is for debugging apps on a device or a simulator. 
2. Profile Mode- Some debugging abilities are available, along with an analysis of app's performance in testing rounds. 
3. Release Mode- This mode is used when deploying the app. This mode is for faster performance. You cannot debug or edit the code in this mode.




Comments