Skip to content

Instantly share code, notes, and snippets.

@georgesboris
Last active June 10, 2020 21:10
Show Gist options
  • Save georgesboris/a3ec3e46ea5a4de889c6a22f394dd11d to your computer and use it in GitHub Desktop.
Save georgesboris/a3ec3e46ea5a4de889c6a22f394dd11d to your computer and use it in GitHub Desktop.
Youse Dart DOJO - 2020.06.10 - Classes and Instances
import 'package:flutter/material.dart';
void main() {
// where the magic happens
Stack stack = Stack(title: "Magic ");
print(stack._list);
stack.push(1);
stack.push(2);
stack.push(3);
print(stack._list);
print(stack.status);
}
class Stack {
final String title;
final List<int> _list = [];
int get sum {
return _list.fold(0, (prev, element) => prev + element);
}
String get status {
return "$title has ${_list.length} and their sum is $sum 🚀";
}
Stack({@required this.title});
void push(int value) {
_list.add(value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment