Skip to content

Instantly share code, notes, and snippets.

View kwalrath's full-sized avatar

Kathy Walrath kwalrath

View GitHub Profile

Want to contribute? Great! First, read this page (including the small print at the end).

Ways you can contribute

You can help the Dart project in many ways, in addition to contributing code. For example, you can report bugs, ask and answer Dart questions on StackOverflow, and improve the documentation.

If you'd like to improve the documentation, you have three options:

  • Give us feedback:
  • If you're looking at a page with a bug icon at the upper right,
@kwalrath
kwalrath / main.dart
Last active August 9, 2022 05:41
Java-to-Dart codelab: Final Bicycle example
class Bicycle {
int cadence;
int _speed = 0;
int get speed => _speed;
int gear;
Bicycle(this.cadence, this.gear);
void applyBrake(int decrement) {
_speed -= decrement;
@kwalrath
kwalrath / main.dart
Last active June 11, 2018 18:20
Java-to-Dart codelab: Final Rectangle example
import 'dart:math';
class Rectangle {
int width;
int height;
Point origin;
Rectangle({this.origin = const Point(0, 0), this.width = 0, this.height = 0});
@override
@kwalrath
kwalrath / main.dart
Last active November 5, 2022 04:01
Java-to-Dart codelab: Starting Shapes example
import 'dart:math';
abstract class Shape {
num get area;
}
class Circle implements Shape {
final num radius;
Circle(this.radius);
num get area => pi * pow(radius, 2);
@kwalrath
kwalrath / main.dart
Last active November 5, 2022 04:10
Java-to-Dart codelab: Top-level factory function
import 'dart:math';
abstract class Shape {
num get area;
}
class Circle implements Shape {
final num radius;
Circle(this.radius);
num get area => pi * pow(radius, 2);
@kwalrath
kwalrath / main.dart
Last active November 5, 2022 04:13
Java-to-Dart codelab: Factory constructor
import 'dart:math';
abstract class Shape {
factory Shape(String type) {
if (type == 'circle') return Circle(2);
if (type == 'square') return Square(2);
throw 'Can\'t create $type.';
}
num get area;
}
@kwalrath
kwalrath / main.dart
Last active March 11, 2021 18:53
Java-to-Dart codelab: CircleMock example
import 'dart:math';
abstract class Shape {
factory Shape(String type) {
if (type == 'circle') return Circle(2);
if (type == 'square') return Square(2);
throw 'Can\'t create $type.';
}
num get area;
}
@kwalrath
kwalrath / main.dart
Created May 3, 2018 23:48
Java-to-Dart codelab: Scream example - imperative code
String scream(int length) => "A${'a' * length}h!";
main() {
final values = [1, 2, 3, 5, 10, 50];
for (var length in values) {
print(scream(length));
}
}
@kwalrath
kwalrath / main.dart
Created May 3, 2018 23:51
Java-to-Dart codelab: Scream example - functional code
String scream(int length) => "A${'a' * length}h!";
main() {
final values = [1, 2, 3, 5, 10, 50];
values.map(scream).forEach(print);
}
@kwalrath
kwalrath / main.dart
Created May 3, 2018 23:56
Java-to-Dart codelab: Scream example - functional code with more Iterable API
String scream(int length) => "A${'a' * length}h!";
main() {
final values = [1, 2, 3, 5, 10, 50];
values.skip(1).take(3).map(scream).forEach(print);
}