Skip to content

Instantly share code, notes, and snippets.

@graphicbeacon
Created April 21, 2018 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graphicbeacon/bd7899cddbcf3726d8c01d8ee2d9ff5b to your computer and use it in GitHub Desktop.
Save graphicbeacon/bd7899cddbcf3726d8c01d8ee2d9ff5b to your computer and use it in GitHub Desktop.
Sample code for 'Learn Dart Before You Flutter' blog post on Medium (Complete)
class Order {
// private properties
int _id;
String _reference;
DateTime _date;
// public properties
String code;
String from;
List<String> bookings;
Order(this._id, this._reference, this._date);
Order.withDiscount(this._id, this._reference, {this.code}) {
_date = new DateTime.now();
}
// Using doc strings to save the multiple linebreaks(\n)
String getInfo() => '''
Your order information:
-------------------------------
Id: $_id
Reference: $_reference
Date: $_date
-------------------------------
''';
void printInfo() => print(getInfo());
}
void main() {
Order order1 = new Order.withDiscount(1, 'ref1', code: 'SPECIALDISCOUNT')
..from = 'Jermaine Oppong'
..bookings = ['booking1', 'booking2', 'booking3']
..printInfo();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment