Skip to content

Instantly share code, notes, and snippets.

@raviyadav5951
Last active February 14, 2019 13:03
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 raviyadav5951/fa24165e39abfa66e7663ea7e5f81125 to your computer and use it in GitHub Desktop.
Save raviyadav5951/fa24165e39abfa66e7663ea7e5f81125 to your computer and use it in GitHub Desktop.
My First Dart code
class Bicycle {
int cadence;
int _speed = 0;
//we have made speed as read only so we will just use get below to read its value.
//we will update its value using _speed variable.(work as setter)
// and to print the speed value (use _speed which always gets the latest speed value)
int get speed => _speed;
int gear;
Bicycle(this.cadence, this.gear);
void applyBrake(int decrement) {
_speed -= decrement;
}
void speedUp(int increment) {
_speed += increment;
}
@override
String toString() => 'Bicycle: $_speed mph';
}
void main() {
var bike = Bicycle(2, 1);
print(bike);
bike._speed=100;
print(bike);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment