Flutter Part 2
Flutter Part 2
Flutter Part 2
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.
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
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();
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(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])
Topics: Flutter
Answer:
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 .
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.
Topics: Flutter
Answer:
Streams can be created in many ways but they all are used in the same way; the asynchronous for loop(
await for). E.g
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.
Topics: Flutter
Answer:
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.
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
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> .
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.
Topics: Flutter
Answer:
To name a few:
Page 7 of 9
FullStack.Cafe - Kill Your Tech Interview
Topics: Flutter
Answer:
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.
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
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.
Topics: Flutter
Answer:
Scaffold
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