Last active
June 10, 2020 21:10
-
-
Save georgesboris/a3ec3e46ea5a4de889c6a22f394dd11d to your computer and use it in GitHub Desktop.
Youse Dart DOJO - 2020.06.10 - Classes and Instances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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