🔹 1. When to use main Axis Alignment and cross Axis Alignment?
Answer:
For Row:mainAxisAlignment
= Horizontal AxiscrossAxisAlignment
= Vertical Axis
For Column:
mainAxisAlignment
= Vertical AxiscrossAxisAlignment
= Horizontal Axis
🔹 2. What is Flutter?
Answer:
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.
🔹 3. What is the difference between Expanded and Flexible widgets?
Answer:
Expanded
is just a shorthand for Flexible
Using expanded this way:
Expanded(
child: Foo(),
);
is strictly equivalent to:
Flexible(
fit: FlexFit.tight,
child: Foo(),
);
You may want to use Flexible
over Expanded
when you want a different fit
, useful in some responsive layouts.
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.
🔹 4. What is the pubspec.yaml file and what does it do?
Answer:
- The
pubspec.yaml
file allows you to define the packages your app relies on, declare your assets like images, audio, video, etc. - It allows you to set constraints for your app.
- For Android developers, this is roughly similar to a
build.gradle
file.
🔹 5. Does Flutter work like a browser? How is it different from a WebView based application?
Answer:
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.
🔹 6. When should you use WidgetsBindingObserver?
Answer:
WidgetsBindingObserver should be used when we want to listen to the AppLifecycleState
and call stop/start on our services.
🔹 7. What is the difference between "main()" and "runApp()" functions in Flutter?
Answer:
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.runApp()
function should return Widget that would be attached to the screen as a root of the Widget Tree that will be rendered.
🔹 8. What is an App state?
Answer:
- 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).
- Examples of application state: - User preferences - Login info - Notifications in a social networking app - The shopping cart in an e-commerce app - Read/unread state of articles in a news app
🔹 9. What is the pubspec.yaml file and what does it do?
Answer:
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.
🔹 10. What are the different build modes in Flutter?
Answer:
- The Flutter tooling supports three modes when compiling your app, and a headless mode for testing.
- You choose a compilation mode depending on where you are in the development cycle.
- The modes are: - Debug - Profile - Release
🔹 11. What is Dart and why does Flutter use it?
Answer:
Dart is an object-oriented, garbage-collected programming language that you use to develop Flutter apps. It was also created by Google, but is open-source, and has community inside and outside Google. Dart was chosen as the language of Flutter for the following reason:
- 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.
- 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).
- 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.
🔹 12. How many types of widgets are there in Flutter?
Answer:
There are two types of widgets: 1. StatelessWidget : A widget that does not require mutable state. 2. StatefulWidget: A widget that has mutable state.
🔹 13. How is Flutter different from a WebView based application?
Answer:
- 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.
- “Hybrid” apps are slow, sluggish and look different from the platform they run on. Flutter apps run much, much faster than their hybrid counterparts.
- 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.
🔹 14. What is a "widget" and mention its importance in Flutter?
Answer:
- Widgets are basically the UI components in Flutter.
- It is a way to describe the configuration of an Element.
- They are inspired from components in React.
Widgets are important in Flutter because everything within a Flutter application is a Widget , from a simple “Text” to “Buttons” to “Screen Layouts”.
🔹 15. What is Fat Arrow Notation in Dart and when do you use it?
Answer:
The fat arrow syntax is simply a short hand for returning an expression and is similar to (){ return expression; }
.
The fat arrow is for returning a single line, braces are for returning a code block.
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
// Normal function void function1(int a) { if (a == 3) { print('arg was 3'); } else { print('arg was not 3'); } }
// Arrow Function void function2(int a) => print('arg was ${a == 3 ? '' : 'not '}3');
No comments:
Post a Comment