CAE Notes
CAE Notes
Explain the concept of State in Flutter and differentiate between Stateful and Stateless widgets.
Describe the role of Widgets in Flutter and categorize different types of widgets based on their
functionality.
Explain how decision-making constructs and loops work in Dart programming. Why are they
important in app development?
Discuss the significance of MediaQuery in Flutter and how it helps in responsive UI design.
Q1: Explain the key features of Flutter and discuss its advantages and disadvantages.
Flutter is an open-source UI toolkit developed by Google for building natively compiled applications
for mobile, web, and desktop from a single codebase.
Features of Flutter:
Single Codebase: Write one code and deploy on multiple platforms.
Fast Performance: Uses Dart and Skia rendering engine for high performance.
Hot Reload: Instantly see changes during development.
Customizable Widgets: Provides rich, pre-designed widgets.
Direct Compilation: Compiles into native ARM code for speed.
Advantages of Flutter:
Faster app development with Hot Reload.
Cross-platform compatibility (iOS, Android, Web, Windows, macOS, Linux).
High performance due to native compilation.
A growing community and extensive documentation.
Disadvantages of Flutter:
Large app size compared to native apps.
Limited third-party libraries compared to native platforms.
iOS development limitations, as Flutter relies on Google’s implementations.
Q2: Describe the step-by-step installation process of Flutter on Windows and macOS.
Installation on Windows:
1. Download Flutter SDK from the official website.
2. Extract the ZIP file to the desired location (e.g., C:\flutter).
3. Add Flutter to the system path:
o Open Environment Variables → Edit Path → Add C:\flutter\bin.
4. Install dependencies:
o Install Git, Android Studio, and the Flutter plugin.
5. Verify installation: Run flutter doctor in the command prompt.
Installation on macOS:
1. Download Flutter SDK for macOS.
2. Extract it and move it to /Users/<your-username>/flutter.
3. Add Flutter to the PATH by modifying .zshrc or .bashrc.
4. Install Xcode and Android Studio.
5. Run flutter doctor to check for missing dependencies.
Explain the architecture of a Flutter application and analyze how Flutter handles UI rendering.
Q 4 Define and explain the purpose of getters and setters in Dart with an example.
Getters and Setters in Dart are used to encapsulate data and control access to object properties.
Getter: Retrieves the value of a property.
Setter: Modifies a property while ensuring validation.
class Student {
String _name = '';
void main() {
Student s = Student();
s.name = 'Alice'; // Using setter
print(s.name); // Using getter
}
O/p -- Alice
Q4: Compare synchronous and asynchronous programming in Dart with examples. Which
approach is better for Flutter applications?
In Dart, synchronous operations run sequentially, blocking execution, while asynchronous operations
execute independently without waiting.
Synchronous Programming Example:
void main() {
print('Start');
print('Processing...');
print('End');
}
Unit - 2
1. Explain the concept of State in Flutter and differentiate between Stateful and Stateless
widgets.
In Flutter, the State refers to the data that can change during the lifetime of an application. It plays a
crucial role in building dynamic UI components that update based on user interactions or external
changes.
Stateless Widgets: These widgets are immutable, meaning their properties cannot change
once created. They are used for UI components that do not need to update dynamically.
Examples include Text, Icon, and Container.
Stateful Widgets: These widgets can change their state over time. They use a State object,
which allows modification without recreating the entire widget. Examples include TextField
(where user input changes the UI) and Checkbox (which toggles selection).
Flutter follows a declarative UI approach, meaning when a state changes, the framework rebuilds only
the necessary parts of the widget tree to reflect updates efficiently.
2. Describe the role of Widgets in Flutter and categorize different types of widgets based on
their functionality.
Widgets are the fundamental building blocks of Flutter applications, defining both structure and
behavior of UI components. Everything in Flutter is a widget, including text, buttons, layouts, and
even the entire application itself.
Widgets in Flutter can be broadly classified into:
1. Structural Widgets: Define the layout of the app, such as Scaffold, AppBar, Container, and
Column.
2. Interactive Widgets: Handle user interaction, such as GestureDetector, InkWell,
ElevatedButton, and TextField.
3. Styling and Theming Widgets: Control visual appearance, such as Padding, Margin, Align,
and DecoratedBox.
4. Stateful and Stateless Widgets: Manage state (StatefulWidget) or remain constant
(StatelessWidget).
5. Animation & Media Widgets: Help create animations and display media, such as Image,
VideoPlayer, and Hero.
The flexibility of widgets in Flutter enables developers to build complex UIs using a composition-
based approach, ensuring scalability and maintainability.
3. Explain how decision-making constructs and loops work in Dart programming. Why are they
important in app development?
Dart, the programming language used in Flutter, provides decision-making constructs and loops to
control program flow based on conditions and repeated executions.
Decision-Making Constructs:
if, if-else: Used to execute a block of code based on a condition.
else-if ladder: Allows multiple conditions to be checked sequentially.
switch-case: Used for handling multiple specific cases efficiently.
Loops in Dart:
For loop: Executes a block of code a fixed number of times.
While loop: Executes a block as long as a condition remains true.
Do-while loop: Similar to while, but guarantees at least one execution.
For-in loop: Iterates over elements in a collection, such as lists or maps.
These constructs are crucial in app development as they enable efficient data processing, user
interactions, animations, and event handling. For example, loops are used in data pagination, and
conditional statements help in form validation.
4. Discuss the significance of MediaQuery in Flutter and how it helps in responsive UI design.
MediaQuery in Flutter is a powerful tool that provides information about the current device’s screen
dimensions, orientation, text scaling, and other layout-related properties. It is essential for creating
responsive and adaptive user interfaces that work seamlessly across different screen sizes.
MediaQuery provides details such as:
Screen width and height: Helps adjust UI elements dynamically based on device size.
Orientation: Determines whether the device is in portrait or landscape mode, enabling layout
changes accordingly.
Text scale factor: Adjusts font sizes based on user preferences for better accessibility.
Using MediaQuery, developers can ensure that their applications provide a consistent experience
across mobile, tablet, and desktop devices by making UI components adapt dynamically rather than
using fixed pixel-based dimensions.