Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

FullStack.

Cafe - Kill Your Tech Interview

FullStack.Cafe - Kill Your Tech Interview

Q1: Differentiate StatelessWidget and StatefulWidget ? ☆☆☆

Topics: Flutter

Answer:

Stateless : Widget state creates ONLY ONCE, then it can update values but not state explicitly. That's why it
has only one class which extends with StatelessWidget . They can never re-run build() method again.

Stateful : Widgets can update their STATE (locally) & values multiple times upon event triggered.
That's the reason, the implementation is also different. In this, we have 2 classes, one is StatefulWidget & the
other is it's State implementation handler i.e. State<YourWidget> . So if I say, they can re-run build() method
again & again based on events triggered.

A StatelessWidget will never rebuild by itself (but can from external events). A StatefulWidget can.
A StatelessWidget is static wheres a StatefulWidget is dynamic.

See the diagram below:

Q2: Differentiate between Hot Restart and Hot Reload? ☆☆☆

Topics: Flutter

Answer:

Hot Reload

Flutter hot reload features works with combination of Small r key on command prompt or Terminal.
Hot reload feature quickly compile the newly added code in our file and sent the code to Dart Virtual
Machine. After done updating the Code Dart Virtual Machine update the app UI with widgets.
Hot Reload takes less time then Hot restart.
There is also a draw back in Hot Reload, If you are using States in your application then Hot Reload
preservers the States so they will not update on Hot Reload our set to their default values.

Page 1 of 9
FullStack.Cafe - Kill Your Tech Interview

Hot Restart

Hot restart is much different than hot reload.


In Hot restart it destroys the preserves State value and set them to their default. So if you are using States
value in your application then after every hot restart the developer gets fully compiled application and all the
states will be set to their defaults.
The app widget tree is completely rebuilt with new typed code.
Hot Restart takes much higher time than Hot reload.

Q3: Explain Navigator Widget and its push/pop functions in


Flutter? ☆☆☆

Topics: Flutter

Answer:

Navigator Widget is a simple widget that maintains a stack of Routes , or in simpler terms, a history of visited
screens/pages.

When we navigate to another screen, we use the push methods and Navigator widget adds the new screen
onto the top of the stack.

new RaisedButton(
onPressed:(){
**Navigator._of_(context).pushNamed('/screen2');**
},
child: new Text("Push to Screen 2"),
),

Now when we want to get rid of the last visited screen, we would need to pop Routes from the Navigator’s stack
using the pop methods.

Navigator._of_(context).pop();

Q4: Differentiate between required and optional parameters in


Dart ☆☆☆

Topics: Flutter

Answer:

Required Parameters

Dart required parameters are the arguments that are passed to a function and the function or method required
all those parameters to complete its code block.

findVolume(int length, int breath, int height) {


print('length = $length, breath = $breath, height = $height');
}

findVolume(10,20,30);

Page 2 of 9
FullStack.Cafe - Kill Your Tech Interview

Optional Parameters

Optional parameters are defined at the end of the parameter list, after any required parameters.
In Flutter/Dart, there are 3 types of optional parameters:
Named
Parameters wrapped by { }
eg. getUrl(int color, [int favNum])
Positional
Parameters wrapped by [ ] )
eg. getUrl(int color, {int favNum})
Default
Assigning a default value to a parameter.
eg. getUrl(int color, [int favNum = 6])

Q5: Differentiate between named parameters and positional


parameters in Dart? ☆☆☆

Topics: Flutter

Answer:

Both named and positional parameters are part of optional parameter:

Optional Positional Parameters:

A parameter wrapped by [ ] is a positional optional parameter.

getHttpUrl(String server, String path, [int port=80]) {


// ...
}

You can specify multiple positional parameters for a function:

getHttpUrl(String server, String path, [int port=80, int numRetries=3]) {


// ...
}

In the above code, port and numRetries are optional and have default values of 80 and 3 respectively. You
can call getHttpUrl with or without the third parameter. The optional parameters are positional in that you
can't omit port if you want to specify numRetries .

Optional Named Parameters:

A parameter wrapped by { } is a named optional parameter.

getHttpUrl(String server, String path, {int port = 80}) {


// ...
}

You can specify multiple named parameters for a function:

getHttpUrl(String server, String path, {int port = 80, int numRetries = 3}) {
// ...
}

Page 3 of 9
FullStack.Cafe - Kill Your Tech Interview

You can call getHttpUrl with or without the third parameter. You must use the parameter name when calling
the function.
Because named parameters are referenced by name, they can be used in an order different from their
declaration.

getHttpUrl('example.com', '/index.html', numRetries: 5, port: 8080);


getHttpUrl('example.com', '/index.html', numRetries: 5);

Q6: What are Streams in Flutter/Dart? ☆☆☆

Topics: Flutter

Answer:

Asynchronous programming in Dart is characterized by the Future and Stream classes.

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.

Streams can be created in many ways but they all are used in the same way; the asynchronous for loop(
await for). E.g

Future<int> sumStream(Stream<int> stream) async {


var sum = 0;
await for (var value in stream) {
sum += value;
}
return sum;
}

Streams provide an asynchronous sequence of data.

Data sequences include user-generated events and data read from files.

You can process a stream using either await for or listen() from the Stream API.

Streams provide a way to respond to errors.

There are two kinds of streams: single subscription or broadcast.

Q7: Explain the different types of Streams? ☆☆☆

Topics: Flutter

Answer:

There are two kinds of streams.

1. Single subscription streams

The most common kind of stream.


It contains a sequence of events that are parts of a larger whole. Events need to be delivered in the
correct order and without missing any of them.
This is the kind of stream you get when you read a file or receive a web request.

Page 4 of 9
FullStack.Cafe - Kill Your Tech Interview

Such a stream can only be listened to once. Listening again later could mean missing out on initial
events, and then the rest of the stream makes no sense.
When you start listening, the data will be fetched and provided in chunks.

2. Broadcast streams

It intended for individual messages that can be handled one at a time. This kind of stream can be used
for mouse events in a browser, for example.
You can start listening to such a stream at any time, and you get the events that are fired while you
listen.
More than one listener can listen at the same time, and you can listen again later after canceling a
previous subscription.

Q8: Why is the build() method on State and not Stateful Widget?
☆☆☆

Topics: Flutter

Answer:

Putting a Widget build( BuildContext context ) method on State rather than putting a Widget
build( BuildContext context , State state ) method on StatefulWidget gives developers more flexibility when
subclassing StatefulWidget .
For example, AnimatedWidget is a subclass of StatefulWidget that introduces an abstract Widget
build( BuildContext context ) method for its subclasses to implement. If StatefulWidget already had a build
method that took a State argument, AnimatedWidget would be forced to provide its State object to
subclasses even though its State object is an internal implementation detail of AnimatedWidget .
Conceptually, StatelessWidget could also be implemented as a subclass of StatefulWidget in a similar
manner. If the build method were on StatefulWidget rather than State , that would not be possible anymore.
Putting the build function on State rather than StatefulWidget also helps avoid a category of bugs related
to closures implicitly capturing this. If you defined a closure in a build function on a StatefulWidget , that
closure would implicitly capture this, which is the current widget instance, and would have the (immutable)
fields of that instance in scope.

Q9: What are packages and plugins in Flutter? ☆☆☆

Topics: Flutter

Answer:

Packages allow you to import new widgets or functionality into your app.
There is a small distinction between packages and plugins.
Packages are usually new components or code written purely in Dart whereas plugins work to allow more
functionality on the device side using native code.
Usually on DartPub, both packages and plugins are referred to as packages and only while creating a new
package is the distinction clearly mentioned.

Q10: What are keys in Flutter and when to use it? ☆☆☆

Topics: Flutter

Answer:

Page 5 of 9
FullStack.Cafe - Kill Your Tech Interview

A Key is an identifier for Widgets , Elements and SemanticsNodes .


A new widget will only be used to update an existing element if its key is the same as the key of the current
widget associated with the element.
Keys must be unique amongst the Elements with the same parent.
Subclasses of Key should either subclass LocalKey or GlobalKey .
Keys are useful when manipulating collections of widgets of the same type.
If you find yourself adding, removing, or reordering a collection of widgets of the same type that hold some
state, then, you should use a key.

Q11: When do we use double.INFINITY ? ☆☆☆

Topics: Flutter

Answer:

We use double.INFINITY when we want a box that is as big as possible as allowed by its parent.

Q12: What is debug mode and when do you use it? ☆☆☆

Topics: Flutter

Answer:

In debug mode, the app is set up for debugging on the physical device, emulator, or simulator.
It is used during development stage and when you want to use hot reload.
Debug mode for mobile apps mean that:
Assertions are enabled.
Service extensions are enabled.
Compilation is optimized for fast development and run cycles (but not for execution speed, binary size, or
deployment).
Debugging is enabled, and tools supporting source level debugging (such as DevTools) can connect to
the process.
Debug mode for a web app means that:
The build is not minified and tree shaking has not been performed.
The app is compiled with the dartdevc compiler for easier debugging.
By default, flutter run compiles to debug mode.

Q13: What is profile mode and when do you use it? ☆☆☆

Topics: Flutter

Answer:

In profile mode, some debugging ability is maintained—enough to profile your app’s performance.
Profile mode is used when you want to analyze performance.
Profile mode is disabled on the emulator and simulator, because their behavior is not representative of real
performance.
On mobile, profile mode is similar to release mode, with the following differences:
Some service extensions, such as the one that enables the performance overlay, are enabled.
Tracing is enabled, and tools supporting source-level debugging (such as DevTools) can connect to the
process.
Profile mode for a web app means that:

Page 6 of 9
FullStack.Cafe - Kill Your Tech Interview

The build is not minified but tree shaking has been performed.
The app is compiled with the dart2js compiler.
The command flutter run --profile compiles to profile mode.

Q14: What is release mode and when do you use it? ☆☆☆

Topics: Flutter

Answer:

Use release mode for deploying the app, when you want maximum optimization and minimal footprint
size.
Use release mode when you are ready to release your app.
For mobile, release mode (which is not supported on the simulator or emulator), means that:
Assertions are disabled.
Debugging information is stripped out.
Debugging is disabled.
Compilation is optimized for fast startup, fast execution, and small package sizes. Service extensions are
disabled.
Release mode for a web app means that:
The build is minified and tree shaking has been performed.
The app is compiled with the dart2js compiler for best performance.
The command flutter run --release compiles to release mode.
You can compile to release mode for a specific target with flutter build <target> .

Q15: How is InheritedWidget different from Provider ? ☆☆☆

Topics: Flutter

Answer:

Provider is mostly features based on Inheritedwidget . Provider basically takes the logic of InheritedWidget ,
but reduce the boilerplate to the strict minimum.

Q16: What are some pros of Flutter? ☆☆☆

Topics: Flutter

Answer:

To name a few:

Can present components that look native to each platform


Reactive UI architecture
Easy to program UI components
The UI components cannot break with OS updates and are the same across OS versions because the app
ships with all the UI rendering code.
Can build in VS Code; after installation, the tooling is invisible -- it just works.
No expertise in iOS, Android, Xcode, or Android Studio is required to build and deploy an app, unless you
need to write native libraries not already available.
Can debug on emulator and device from VS Code
Can hot load changes, easing the UI dev cycle with instant feedback

Page 7 of 9
FullStack.Cafe - Kill Your Tech Interview

Excellent official documentation


UI has native performance, apparently fast enough to support graphical UI (e.g. games)
Interest in Flutter has been growing rapidly over the past several years
Google appears to be making Flutter and Dart a high priority. Recently announced staffing increases. First
implementing their new IoT OS (Fuchsia) for Dart.
Libraries are readily discoverable via Dart packages and manageable via CLI
Dart is easier to learn and master than Typescript and Java/Kotlin and yet well suited to existing Javascript
and Java devs, so except for reputation, the language makes Flutter a better starting technology for new
devs and devs not already familiar with React. This may also make the code easier and less expensive to
maintain in the long run.
Dart provides a tidier way to scope and organize code than other languages (personal opinion).

Q17: Name some cons of using Flutter? ☆☆☆

Topics: Flutter

Answer:

There are some cons:

Dart and Flutter are not presently very marketable skills. (It may be possible to contract oneself out for
implementing whole apps, but harder to get a job working for someone else.)
Minimum 4.7MB app
Have to have a Mac to build for iOS
Probably not ready for iOS, but may be soon. iOS UI support is proving challenging, lots of issues reported,
apparently slow to get fixed. The most significant appear to be text editing functions (many of which have
been resolved) and text rendering (whose status I can't find).
Lots of issues with access to camera, slow to get fixed (maybe 3rd party plugins can address?)
Some issues reported with accessing photos on device (maybe 3rd party plugins can address?)
Does not provide hook for saving app state before Android opts to temporarily kill an app to recover memory
Some risk that Apple may take issue with Flutter apps in the future because Google is a competitor and
because the Flutter approach requires Google to emulate portions of the iOS UI
Few high profile apps have been developed in Flutter, creating a Catch-22 situation for motivating others to
adopt; also not very well proven.
Not a very large collection of supporting libraries yet; will have to implement your own native and non-native
libraries as needed.

Q18: How to declare async function as a variable in Dart? ☆☆☆

Topics: Flutter

Answer:

Async functions are normal functions with some sugar on top. The function variable type just needs to specify
that it returns a Future:

class Example {
Future<void> Function() asyncFuncVar;
Future<void> asyncFunc() async => print('Do async stuff...');

Example() {
asyncFuncVar = asyncFunc;
asyncFuncVar().then((_) => print('Hello'));
}
}

Page 8 of 9
FullStack.Cafe - Kill Your Tech Interview

void main() => Example();

Q19: How is whenCompleted() different from then() in Future? ☆☆☆

Topics: Flutter

Answer:

.whenComplete will fire a function either when the Future completes with an error or not, while .then returns
a new Future which is completed with the result of the call to onValue (if this future completes with a value)
or to onError (if this future completes with an error)
.whenCompleted is the asynchronous equivalent of a "finally" block.

Q20: What is the difference between Scaffold and Container in


Flutter? ☆☆☆

Topics: Flutter

Answer:

Scaffold and container both serves different purpose for design.

Scaffold

Implements the basic material design visual layout structure.


This class provides APIs for showing drawers, snack bars, and bottom sheets.

Container

A convenience widget that combines common painting, positioning, and sizing widgets.
It basically contains different widget into one widget over which you can give padding , size, position etc.

You need Scaffold widget as main parent of your page where you use container for smaller widget into page to
give them different properties like size, border, padding, margin etc.

Page 9 of 9

You might also like