βββ README.md
/README.md:
--------------------------------------------------------------------------------
1 | # Flutter Interview Questions and Answers
2 |
3 | Flutter is booming in the mobile market as the next revolution. It has proven to hold the potential to win over every mobile technology and become the only choice for cross-platform app development in the future. Follow along and check the first most comprehensive list of Flutter Interview Questions and Answers that will trend on mobile developers interviews in 2020.
4 |
5 | > You could find all the answers here π https://www.fullstack.cafe/Flutter.
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | ### Q1: What is Flutter? β
14 |
15 | **Answer:**
16 |
17 | **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.
18 |
19 |
20 | π **Source:** [flutter.dev](https://flutter.dev)
21 |
22 |
23 | ### Q2: When to use main Axis Alignment and cross Axis Alignment? β
24 |
25 | **Answer:**
26 |
27 | **For Row:**
28 | `mainAxisAlignment` = Horizontal Axis
29 | `crossAxisAlignment` = Vertical Axis
30 |
31 | 
32 |
33 | **For Column:**
34 |
35 | `mainAxisAlignment` = Vertical Axis
36 | `crossAxisAlignment` = Horizontal Axis
37 |
38 | 
39 |
40 |
41 | [Image source](https://flutter.dev/docs/development/ui/layout#aligning-widgets)
42 |
43 | π **Source:** [stackoverflow.com](https://stackoverflow.com/questions/53850149/flutter-crossaxisalignment-vs-mainaxisalignment/53856933#53856933)
44 |
45 |
46 | ### Q3: What is Dart and why does Flutter use it? ββ
47 |
48 | **Answer:**
49 |
50 | **Dart** is an *object-oriented*, *garbage-collected* programming language that you use to develop Flutter apps.
51 | It was also created by Google, but is open-source, and has community inside and outside Google.
52 | Dart was chosen as the language of **Flutter** for the following reason:
53 | - Dart is **AOT** (Ahead Of Time) compiled to fast, predictable, native code, which allows almost all of Flutter to be written in Dart. This not only makes Flutter fast, virtually everything (including all the widgets) can be customized.
54 | - Dart can also be **JIT** (Just In Time) compiled for exceptionally fast development cycles and game-changing workflow (including Flutterβs popular sub-second stateful hot reload).
55 | - Dart allows Flutter to avoid the need for a separate declarative layout language like *JSX* or *XML*, or separate visual interface builders, because Dartβs declarative, programmatic layout is easy to read and visualize. And with all the layout in one language and in one place, it is easy for Flutter to provide advanced tooling that makes layout a snap.
56 |
57 | π **Source:** [hackernoon.com](https://hackernoon.com/why-flutter-uses-dart-dd635a054ebf)
58 |
59 |
60 | ### Q4: What is a "widget" and mention its importance in Flutter? ββ
61 |
62 | **Answer:**
63 |
64 | - Widgets are basically the UI components in Flutter.
65 | - It is a way to describe the configuration of an *Element*.
66 | - They are inspired from components in **React**.
67 |
68 | Widgets are important in Flutter because everything within a Flutter application is a **Widget** , from a simple β_Textβ_ to β_Buttonsβ_ to β_Screen Layoutsβ_.
69 |
70 | π **Source:** [stackoverflow.com](https://stackoverflow.com/questions/50958238/what-is-a-widget-in-flutter)
71 |
72 |
73 | ### Q5: How many types of widgets are there in Flutter? ββ
74 |
75 | **Answer:**
76 |
77 | There are two types of widgets:
78 | 1. **StatelessWidget**β: A widget that does not require mutable state.
79 | 2. **StatefulWidget**: A widget that has mutable state.
80 |
81 | π **Source:** [proandroiddev.com](https://proandroiddev.com/flutter-from-zero-to-comfortable-6b1d6b2d20e)
82 |
83 |
84 | ### Q6: When should you use WidgetsBindingObserver? ββ
85 |
86 | **Answer:**
87 |
88 | WidgetsBindingObserver should be used when we want to listen to the `AppLifecycleState` and call stop/start on our services.
89 |
90 | π **Source:** [www.filledstacks.com](https://www.filledstacks.com/post/flutter-application-life-cycle-management/)
91 |
92 |
93 | ### Q7: What is the difference between "main()" and "runApp()" functions in Flutter? ββ
94 |
95 | **Answer:**
96 |
97 | - `main ()` function came from *Java*-like languages so it's where all program started, without it, you can't write any program on Flutter even without UI.
98 | - `runApp()` function should return *Widget* that would be attached to the screen as a root of the *Widget Tree* that will be rendered.
99 |
100 | π **Source:** [stackoverflow.com](https://stackoverflow.com/questions/58883728/what-is-the-difference-between-main-function-and-the-runapp-function-in-flutte)
101 |
102 |
103 | ### Q8: What is the difference between Expanded and Flexible widgets? ββ
104 |
105 | **Answer:**
106 |
107 | `Expanded` is just a shorthand for `Flexible`
108 |
109 | Using expanded this way:
110 | ```dart
111 | Expanded(
112 | child: Foo(),
113 | );
114 | ```
115 | is strictly equivalent to:
116 | ```dart
117 | Flexible(
118 | fit: FlexFit.tight,
119 | child: Foo(),
120 | );
121 | ```
122 |
123 | You may want to use `Flexible` over `Expanded` when you want a different `fit`, useful in some responsive layouts.
124 |
125 | The difference between `FlexFit.tight` and `FlexFit.loose` is that loose will allow its child to have a maximum size while tight forces that child to fill all the available space.
126 |
127 | π **Source:** [stackoverflow.com](https://stackoverflow.com/questions/52645944/flutter-expanded-vs-flexible)
128 |
129 |
130 | ### Q9: How is Flutter different from a WebView based application? ββ
131 |
132 | **Answer:**
133 |
134 | - Code you write for a **WebView** or an app that runs similarly has to go through multiple layers to finally get executed (like Cordova for Ionic).** In essence, Flutter leapfrogs that by **compiling down to native **ARM** code to execute on both platforms.
135 | - βHybridβ apps are slow, sluggish and look different from the platform they run on. *Flutter* apps run much, much faster than their hybrid counterparts.
136 | - Itβs much easier to access native components and sensors using plugins rather than using **WebView** which canβt take full use of their platform.
137 |
138 | π **Source:** [medium.com](https://medium.com/@dev.n/answering-questions-on-flutter-app-development-6d50eb7223f3)
139 |
140 |
141 | ### Q10: What is the pubspec.yaml file and what does it do? ββ
142 |
143 | **Answer:**
144 |
145 | - The `pubspec.yaml` file allows you to define the packages your app relies on, declare your assets like images, audio, video, etc.
146 | - It allows you to set constraints for your app.
147 | - For Android developers, this is roughly similar to a `build.gradle` file.
148 |
149 | π **Source:** [medium.com](https://medium.com/@dev.n/answering-questions-on-flutter-app-development-6d50eb7223f3)
150 |
151 |
152 | ### Q11: What is an App state? ββ
153 |
154 | **Answer:**
155 |
156 | - State that is not *ephemeral*, that you want to share across many parts of your app, and that you want to keep between user sessions, is what we call **application state** (sometimes also called *shared state*).
157 | - Examples of application state:
158 | - User preferences
159 | - Login info
160 | - Notifications in a social networking app
161 | - The shopping cart in an e-commerce app
162 | - Read/unread state of articles in a news app
163 |
164 | π **Source:** [flutter.dev](https://flutter.dev/docs/development/data-and-backend/state-mgmt/ephemeral-vs-app)
165 |
166 |
167 | ### Q12: What are the different build modes in Flutter? ββ
168 |
169 | **Answer:**
170 |
171 | - The Flutter tooling supports three modes when compiling your app, and a headless mode for testing.
172 | - You choose a compilation mode depending on where you are in the development cycle.
173 | - The modes are:
174 | - Debug
175 | - Profile
176 | - Release
177 |
178 | π **Source:** [flutter.dev](https://flutter.dev/docs/testing/build-modes)
179 |
180 |
181 | ### Q13: What is Fat Arrow Notation in Dart and when do you use it? ββ
182 |
183 | **Answer:**
184 |
185 | The fat arrow syntax is simply a short hand for returning an expression and is similar to `(){ return expression; }`.
186 |
187 | The fat arrow is for returning a single line, braces are for returning a code block.
188 |
189 | Only an expressionβnot a statementβcan appear between the arrow (`=>`) and the semicolon (`;`). For example, you canβt put an *if* statement there, but you can use a *conditional* expression
190 | ```dart
191 | // Normal function
192 | void function1(int a) {
193 | if (a == 3) {
194 | print('arg was 3');
195 | } else {
196 | print('arg was not 3');
197 | }
198 | }
199 |
200 | // Arrow Function
201 | void function2(int a) => print('arg was ${a == 3 ? '' : 'not '}3');
202 | ```
203 |
204 |
205 | π **Source:** [stackoverflow.com](https://stackoverflow.com/questions/51868395/flutter-dart-difference-between-and/51869508)
206 |
207 |
208 | ### Q14: Does Flutter work like a browser? How is it different from a WebView based application? ββ
209 |
210 | **Answer:**
211 |
212 | To answer this question simply: **Code you write for a WebView or an app that runs similarly has to go through multiple layers to finally get executed.** In essence, Flutter leapfrogs that by **compiling down to native ARM** code to execute on both platforms. βHybridβ apps are slow, sluggish and look different from the platform they run on. Flutter apps run much, much faster than their hybrid counterparts. Also, itβs much easier to access native components and sensors using plugins rather than using WebViews which canβt take full use of their platform.
213 |
214 | π **Source:** [medium.com](https://medium.com/@dev.n/answering-questions-on-flutter-app-development-6d50eb7223f3)
215 |
216 |
217 | ### Q15: What is the pubspec.yaml file and what does it do? ββ
218 |
219 | **Answer:**
220 |
221 | The `Pubspec.yaml` allows you to define the packages your app relies on, declare your assets like images, audio, video, etc. It also allows you to set constraints for your app. For Android developers, this is roughly similar to a `build.gradle` file, but the differences between the two are also evident.
222 |
223 | π **Source:** [medium.com](https://medium.com/@dev.n/answering-questions-on-flutter-app-development-6d50eb7223f3)
224 |
225 |
226 | ### Q16: When do we use double.INFINITY? βββ
227 |
228 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
229 |
230 |
231 | ### Q17: Differentiate StatelessWidget and StatefulWidget? βββ
232 |
233 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
234 |
235 |
236 | ### Q18: Why do we pass functions to widgets? βββ
237 |
238 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
239 |
240 |
241 | ### Q19: Differentiate between Hot Restart and Hot Reload? βββ
242 |
243 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
244 |
245 |
246 | ### Q20: Explain Navigator Widget and its push pop functions in Flutter? βββ
247 |
248 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
249 |
250 |
251 | ### Q21: Differentiate between required and optional parameters in Dart? βββ
252 |
253 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
254 |
255 |
256 | ### Q22: Differentiate between named parameters and positional parameters in Dart? βββ
257 |
258 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
259 |
260 |
261 | ### Q23: What is ScopedModel / BLoC Pattern? βββ
262 |
263 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
264 |
265 |
266 | ### Q24: What is Streams in Flutter/Dart? βββ
267 |
268 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
269 |
270 |
271 | ### Q25: Explain the different types of Streams? βββ
272 |
273 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
274 |
275 |
276 | ### Q26: Why is the build() method on State and not Stateful Widget? βββ
277 |
278 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
279 |
280 |
281 | ### Q27: What are packages and plugins in Flutter? βββ
282 |
283 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
284 |
285 |
286 | ### Q28: What are keys in Flutter and when to use it? βββ
287 |
288 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
289 |
290 |
291 | ### Q29: Do you know what Ephemeral state means? βββ
292 |
293 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
294 |
295 |
296 | ### Q30: What are Null-aware operators? βββ
297 |
298 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
299 |
300 |
301 | ### Q31: What is debug mode and when do you use it? βββ
302 |
303 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
304 |
305 |
306 | ### Q32: What is profile mode and when do you use it? βββ
307 |
308 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
309 |
310 |
311 | ### Q33: What is release mode and when do you use it? βββ
312 |
313 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
314 |
315 |
316 | ### Q34: How would you execute code only in debug mode? βββ
317 |
318 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
319 |
320 |
321 | ### Q35: How is InheritedWidget different from Provider? βββ
322 |
323 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
324 |
325 |
326 | ### Q36: What are some pros of Flutter? βββ
327 |
328 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
329 |
330 |
331 | ### Q37: Name some cons of using Flutter? βββ
332 |
333 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
334 |
335 |
336 | ### Q38: Where are the layout files? Why doesnβt Flutter have layout files? βββ
337 |
338 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
339 |
340 |
341 | ### Q39: What are some pros and cons of Scoped Model vs BLoC and vice versa? ββββ
342 |
343 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
344 |
345 |
346 | ### Q40: Explain async, await in Flutter/Dart? ββββ
347 |
348 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
349 |
350 |
351 | ### Q41: What is Future in Flutter/Dart? ββββ
352 |
353 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
354 |
355 |
356 | ### Q42: What are the similarities and differences of Future and Stream? ββββ
357 |
358 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
359 |
360 |
361 | ### Q43: What are Global Keys? ββββ
362 |
363 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
364 |
365 |
366 | ### Q44: What is a MediaQuery in Flutter and when do we use it? ββββ
367 |
368 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
369 |
370 |
371 | ### Q45: What is the difference between double.INFINITY and MediaQuery? ββββ
372 |
373 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
374 |
375 |
376 | ### Q46: When would you use App state or Ephemeral state over another? ββββ
377 |
378 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
379 |
380 |
381 | ### Q47: How does Dart AOT work? ββββ
382 |
383 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
384 |
385 |
386 | ### Q48: Why should you use kReleaseMode instead of assert? ββββ
387 |
388 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
389 |
390 |
391 | ### Q49: What is the purpose of SafeArea in Flutter? ββββ
392 |
393 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
394 |
395 |
396 | ### Q50: What is a difference between these operators "?? and ?." ββββ
397 |
398 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
399 |
400 |
401 | ### Q51: List some approaches for State management in Flutter βββββ
402 |
403 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
404 |
405 |
406 | ### Q52: Explain Stateful Widget Lifecycle in details βββββ
407 |
408 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
409 |
410 |
411 | ### Q53: Why Are StatefulWidget and State Separate Classes? βββββ
412 |
413 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
414 |
415 |
416 | ### Q54: What is the difference between debug mode and profile mode? βββββ
417 |
418 | See π **[Answer](https://www.fullstack.cafe/Flutter)**
419 |
420 |
421 |
422 |
423 |
--------------------------------------------------------------------------------