Skip to content

Instantly share code, notes, and snippets.

@carzacc
Last active December 13, 2022 19:38
Show Gist options
  • Save carzacc/69e54a9dde9390421838268046ae411c to your computer and use it in GitHub Desktop.
Save carzacc/69e54a9dde9390421838268046ae411c to your computer and use it in GitHub Desktop.
Flutter Modena Dart Examples
// abstract classes and generics just like in any "real" OOP language
abstract class Accumulator<T> {
void add(T el);
void printState();
}
class ListAccumulator<T> extends Accumulator<T> {
// constructor with implicit initializers!
ListAccumulator({this.state = const []});
List<T> state;
@override
void add(T el) {
state.add(el);
}
@override
void printState() {
// iterate over arrays just like in any modern language
for (var el in state) {
print(el);
}
}
}
// first-class functions and variables just like in C, C++ or JS!
const evil = false;
void main() {
var acc1 = ListAccumulator<String>(
state: [
// if-else inside list literals!
if (!evil)
"Ciao"
else
"Odio",
"Flutter",
if (!evil)
"Modena",
]);
acc1.printState();
var acc2 = ListAccumulator<String>();
acc2.add("Ciao!!!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment