Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@graphicbeacon
Last active April 21, 2018 20:01
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/7865fc2b94b8896d79699f6371963064 to your computer and use it in GitHub Desktop.
Save graphicbeacon/7865fc2b94b8896d79699f6371963064 to your computer and use it in GitHub Desktop.
Sample code for 'Learn Dart Before You Flutter' blog post on Medium (3)
class Order {
int _id;
String _reference;
DateTime _date;
String code; // public property
Order(this._id, this._reference, this._date);
Order.withDiscount(this._id, this._reference, {this.code}) {
_date = new DateTime.now();
}
// Shorthand methods FTW!!!
String getInfo() => 'Your order information:'
'\n-------------------------------'
'\n Id: $_id'
'\n Reference: $_reference'
'\n Date: $_date'
'\n-------------------------------';
void printInfo() => print(getInfo());
}
void main() {
Order order1 = new Order.withDiscount(1, 'ref1', code: 'LOVETHEWEEKEND');
order1.printInfo();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment