Last active
January 27, 2023 12:30
-
-
Save exoad/31baa4301d8ba4e0c8709d9b04475ab1 to your computer and use it in GitHub Desktop.
Dart Tutorials from Google
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
class Bicycle | |
{ | |
Bicycle(this.cadence, this.gear); | |
int cadence; | |
int gear; | |
int _speed = 0; | |
int get speed => _speed; | |
// fat arrow notation "=>" are only used when the return type or the statement can | |
// be fit into one line, thus eliminating "return" | |
void applyBrake(int decrement) => _speed -= decrement; | |
void speedUp(int increment) { _speed += increment; } | |
@override String toString() => "Bicycle speed: $speed mph"; | |
} | |
void main(List<String> args) | |
{ | |
var x = Bicycle(3, 4); | |
print(x.toString()); | |
} |
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 'dart:math'; | |
class Rectangle { | |
int width; | |
int height; | |
Point origin; | |
Rectangle({this.width = 0, this.height = 0, this.origin = const Point(0,0)}); | |
@override String toString() => "Origin: (${origin.x}, ${origin.y}), width: $width, height: $height"; | |
} | |
main() { | |
// specify the attribute u want to provide and the ones not provided by the programmer | |
// will be provided by the optional default parameter. very clever way to make overloading | |
// much more concise. this feature is like always having a "master" constructor in java | |
// where this constructor has all of the necessary parameters (max parameters needed) | |
print(Rectangle(origin: const Point(10, 20), width: 100, height: 200)); | |
print(Rectangle(origin: const Point(10, 10))); | |
print(Rectangle(width: 200)); | |
print(Rectangle()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment