Loading the lesson...
In the print dialog, choose "Save as PDF" as the destination.
Operating Systems II - Lab 05
Planning, three-layer architecture, theming, data models, and the logic layer
UI Layer
Widgets, screens, user interactions, visual calculations
Business Logic Layer
Date processing, search logic, calculations
Data Layer
Models, classes, and external data sources
UI, Business Logic, or Data before writing codeContainer(color: Color(0xFF1565C0), child: Text('Header')),
Container(color: Color(0xFF1565C0), child: Text('Section')),
Container(color: Color(0xFF1565C0), child: Text('Footer')),// DRY - color defined once, reused everywhere
final primaryColor = Color(0xFF1565C0);
Container(color: primaryColor, child: Text('Header')),
Container(color: primaryColor, child: Text('Footer')),ThemeData, attached to MaterialAppTheme.of(context) instead of a hardcoded valueContainer(
color: Theme.of(context).primaryColor,
child: Text('Hello', style: TextStyle(color: Theme.of(context).colorScheme.onPrimary)),
)MaterialApp(
theme: ThemeData.light(),
darkTheme: ThemeData.dark(),
themeMode: ThemeMode.dark,
)| Approach | When to Use |
|---|---|
SingleChildScrollView | Wraps a Column; content stays full size and the user scrolls to reach all of it |
ListView | Replaces the Column outright; scrolls natively, best for repeating items |
Expanded | Content shrinks and adapts to fit instead of scrolling |
final, set once via the constructorclass PersonModel {
final String name;
final int age;
final DateTime birthDate;
PersonModel({required this.name, required this.age, required this.birthDate});
}build method only displays results; it never performs the calculation itselfint calculateDaysAlive() {
final today = DateTime.now();
return today.difference(person.birthDate).inDays;
}pub.dev for relevant keywords, then check popularity, maintenance status, and licenseflutter pub get resolves them automaticallydependencies:
intl: ^0.19.0BuildContext, just inputs and calculations.class DaysCalculator {
final DateTime birthDate;
DaysCalculator(this.birthDate);
int calculateDaysAlive() => DateTime.now().difference(birthDate).inDays;
bool isOver1000DaysOld() => calculateDaysAlive() > 1000;
}StatelessWidget never changes after build; a StatefulWidget can, via setStatesetState tells Flutter: data changed, rebuild this widget with the new valuesUser Taps Calculate
UI Reads State
Build Data Model
Logic Returns a Result
setState Updates the UI
ThemeData and Theme.of(context) makes global changes, like dark mode, a one-line editSingleChildScrollView, ListView, and Expanded each solve screen-overflow differentlyStatefulWidget plus setState is what makes a Flutter UI react to changing dataMahmoud Abas|Lab 05: Building a Complete Flutter App - Architecture to Logic