Dart Cheat Sheet
Dart Cheat Sheet
Dart Cheat Sheet
Rev 1.1.1 © Wei-Meng Lee , Developer Learning Solutions, http://calendar.learn2develop.net All rights reserved.
} }
Iterations } double area() {
for (int i=0;i<5; i++) { return this.length * this.width;
print(i); var loc1 = new MyLocation(); }
} // prints 0 to 4 var loc2 = new }
MyLocation.withPosition(
var list = [1,2,3,4,5]; 57.123,37.22); class Rectangle extends Shape {
for (final i in list) { Rectangle() {}
print(i); Rectangle.withDimension(
} // prints 1 to 5 Getters and Setters double length, double width):
class MyLocation { super.withDimension(
int i=0; double _lat; length, width);
while (i < 5) { double _lng; }
print(i); double get lat => _lat;
i++; set lat (double value) {
} // prints 0 to 4 if (value > 90 || value < -90) { Final Class
throw("Invalid latitude"); // Square cannot be extended (it
i = 0; } // does not have a zero-argument
do { _lat = value; // constructor)
print(i); } class Square extends Rectangle {
i++; Square(double length):
} while (i<5); double get lng => _lng; super.withDimension(
// prints 0 to 4 set lng (double value) { length, length);
if (value > 180 || }
value < -180) {
Class throw("Invalid longitude"); Square s = new Square(5);
class MyLocation { } print(s.area()); // 25
} _lng = value; print(s.perimeter()); // 20
}
// type inference
var loc1 = new MyLocation(); // read-only property Overriding
final arrived = false; class Circle extends Shape {
// declare and initialize Circle(double radius):
MyLocation loc2 = new MyLocation(); // unnamed constructor super.withDimension(
MyLocation() { radius, radius);
double area() {
Properties this.lat = 0;
this.lng = 0; return 3.14 * this.length *
class MyLocation { } this.length;
// read/write properties }
var lat; // named constructor double perimeter() {
var lng; MyLocation.withPosition( return (2 * 3.14 * this.length);
var lat, var lng) { }
// read-only property this.lat = lat; // overloading of methods not
final arrived = false; this.lng = lng; // supported in Dart
} } }
Rev 1.1.1 © Wei-Meng Lee , Developer Learning Solutions, http://calendar.learn2develop.net All rights reserved.