Mobile Programming (MP)The Dart Event Loop manages the execution queue. It prioritizes Microtasks (internal quick ops) over Events (I/O, Timers, Gestures).
Rule: The Loop finishes the entire Microtask Queue before processing the first item in the Event Queue.
Mobile Programming (MP)void main() {
// 1. Add to Event Queue
Future(() => print("Event"));
// 2. Add to Microtask Queue
scheduleMicrotask(() {
print("Microtask");
});
print("Main");
}
Execution Flow:
Main (Synchronous code runs first)Microtask (Microtask Queue empties)Event (Event Queue processes)Why? Because Microtasks have higher priority.
Why This Matters:
If you queue 1,000 microtasks, you will block the UI (clicks, scrolling) until all 1,000 are finished, even if timers are firing.
Mobile Programming (MP)Serialization is the bridge between your code (Dart Objects) and the outside world (JSON strings/Maps). It converts structured data into a format your app can process.
Mobile Programming (MP)class User {
final int id;
final String name;
User({required this.id, required this.name});
// 1. Factory: Creates object from JSON
factory User.fromJson(Map<String, dynamic> json) {
return User(
id: json['id'],
name: json['name'],
);
}
// 2. Method: Creates JSON from object
Map<String, dynamic> toJson() =>
{'id': id, 'name': name};
}
Mobile Programming (MP)Engineering Rules (Best Practices):
final fields to prevent data corruption after creation.var or dynamic for model properties (e.g., use int, not var).String?) vs required (String).
Mobile Programming (MP)Avoid
Prefer
Mobile Programming (MP)Requirements
Task modelTaskRepository
Mobile Programming (MP)Implement
Focus
Mobile Programming (MP)Strong Dart engineers build scalable Flutter apps.
Mobile Programming (MP)
"Q: Why did the Java developer refuse to cross the street?
A: Because he was afraid of getting caught by the Garbage Collector while he was still referenced!"