Skip to content

Instantly share code, notes, and snippets.

@flutterdevrelgists
flutterdevrelgists / main.dart
Created November 5, 2022 04:19 — forked from kwalrath/main.dart
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;
}
@flutterdevrelgists
flutterdevrelgists / main.dart
Created November 5, 2022 04:13 — forked from kwalrath/main.dart
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;
}
@flutterdevrelgists
flutterdevrelgists / main.dart
Created November 5, 2022 04:10 — forked from kwalrath/main.dart
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);
@override
@flutterdevrelgists
flutterdevrelgists / main.dart
Created November 5, 2022 04:07 — forked from kwalrath/main.dart
Java-to-Dart codelab: Using a try-catch statement
import 'dart:math';
abstract class Shape {
factory Shape(String type) {
if (type == 'circle') return Circle(2);
if (type == 'square') return Square(2);
// To trigger exception, don't implement a check for 'triangle'.
throw 'Can\'t create $type.';
}
num get area;
@flutterdevrelgists
flutterdevrelgists / main.dart
Created November 5, 2022 04:01 — forked from kwalrath/main.dart
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);
@override
@flutterdevrelgists
flutterdevrelgists / main.dart
Created November 5, 2022 02:35 — forked from Sfshaza/main.dart
Java-to-Dart codelab: Basic bicycle example
class Bicycle {
int cadence;
int speed;
int gear;
Bicycle(this.cadence, this.speed, this.gear);
@override
String toString() => 'Bicycle: $speed mph';
}