Traditional Ways
Top Level Functions
→ They exist outside of classes, directly at the file level.
Anonymous Functions
Lambda
→ Lambda functions are – nameless, one-liner heroes who simplify code with concise power.
Closures
→ It is a magician with a photographic memory.
→ A function that magically remembers its surrounding environment, even after the party's over.
Extensions
→ It infuses existing classes with extra powers, making them even more versatile.
Modern Ways
→ These are introduced in Dart v3
Records
→ Records are like Lego for data: lightweight, flexible, and perfect for crafting concise and efficient data models.
Multiple Return Value
(String, String) getName() {
var firstName = 'John';
var lastName = 'Smith';
return (firstName, lastName);
}
void main() {
final name = getName();
print('${name.$1} ${name.$2}'); // John Smith
}
Destructing
(String, String) getName() {
var firstName = 'John';
var lastName = 'Smith';
return (firstName, lastName);
}
void main() {
final (firstName, lastName) = getName();
print('$lastName $firstName'); // Smith John
}
Functional Programming
→ dartz
→ fpdart
Immutability
→ kt_dart
→ freezed