Skip to content

Instantly share code, notes, and snippets.

@Sfshaza
Sfshaza / main.dart
Last active September 12, 2016 23:43
anonymous functions
main() {
var list = ['apples', 'oranges', 'grapes', 'bananas', 'plums'];
list.forEach((i) {
print(list.indexOf(i).toString() + ': ' + i);
});
}
@Sfshaza
Sfshaza / main.dart
Last active December 13, 2016 16:48
Sound Dart Guide: unsound example
// The code passes static non-strong mode static analysis.
// Enable strong mode by clicking Strong mode checkbox in lower right.
// The code now raises a warning.
void fn(List<int> a) {
print(a);
}
main() {
var list = []; // Add <int> before the [] to pass strong mode
@Sfshaza
Sfshaza / main.dart
Created December 13, 2016 16:55
Sound Dart Guide: unsound example
// The code passes static non-strong mode static analysis.
// Enable strong mode by clicking Strong mode checkbox in lower right.
// The code now raises a warning.
void fn(List<int> a) {
print(a);
}
main() {
var list = []; // Add <int> before the [] to pass strong mode
@Sfshaza
Sfshaza / main.dart
Last active December 13, 2016 18:11
Sound Dart Guide: generic type assignment
// Enable strong mode by clicking Strong mode checkbox in lower right.
// The code passes strong mode static analysis.
// Follow the instructions in the generic type assignment below.
class Animal {
void feed() {}
}
class Alligator extends Animal {}
@Sfshaza
Sfshaza / main.dart
Last active June 2, 2023 04:49
Java-to-Dart codelab: Starting point
void main() {
for (int i = 0; i < 5; i++) {
print('hello ${i + 1}');
}
}
@Sfshaza
Sfshaza / main.dart
Last active December 28, 2022 12:11
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';
}
@Sfshaza
Sfshaza / main.dart
Last active May 3, 2018 21:58
Java-to-Dart codelab: Final Bicycle example
class Bicycle {
int cadence;
int _speed;
int gear;
Bicycle(this.cadence, this._speed, this.gear);
int get speed => _speed;
void applyBrake(int decrement) {
@Sfshaza
Sfshaza / main.dart
Last active April 26, 2017 23:56
Java-to-Dart codelab: Starting Rectangle example
import 'dart:math';
class Rectangle {
int width;
int height;
Point origin;
}
main() {} // Included main() to suppress uncaught exception.
@Sfshaza
Sfshaza / main.dart
Last active April 26, 2017 23:56
Java-to-Dart codelab: Final Rectangle example
import 'dart:math';
class Rectangle {
Point origin;
int width;
int height;
Rectangle({this.origin = const Point(0, 0), this.width = 0, this.height = 0});
@override
@Sfshaza
Sfshaza / main.dart
Last active May 3, 2018 22:04
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);