Skip to content

Instantly share code, notes, and snippets.

@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 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
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 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
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 October 5, 2015 17:23
optional_types_article
// This example, part of the
// https://www.dartlang.org/articles/optional-types
// article, demonstrates a static warning in Dart.
class Point {
final num x, y;
Point(this.x, this.y);
Point operator +(Point other) {
return new Point(x + other.x, y + other.y);
}
@Sfshaza
Sfshaza / index.html
Last active September 9, 2015 17:06
todo
<!DOCTYPE html>
<!--
Copyright (c) 2012, the Dart project authors.
Please see the AUTHORS file for details.
All rights reserved. Use of this source code
is governed by a BSD-style license that can be
found in the LICENSE file.
-->
@Sfshaza
Sfshaza / main.dart
Last active September 9, 2015 17:06
streams/simple_stream
// Copyright (c) 2015, the Dart project authors.
// Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed
// by a BSD-style license that can be found in the LICENSE file.
import 'dart:async';
Future<int> sumStream(Stream<int> stream) async {
var sum = 0;
await for (var value in stream) {
@Sfshaza
Sfshaza / main.dart
Last active September 9, 2015 17:06
streams/last_positive
// Copyright (c) 2015, the Dart project authors.
// Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed
// by a BSD-style license that can be found in the LICENSE file.
import 'dart:async';
Future<int> lastPositive(Stream<int> stream) async {
var lastValue = null;
await for (var value in stream) {
@Sfshaza
Sfshaza / index.html
Last active September 9, 2015 17:06
mini_with_style
<!DOCTYPE html>
<!--
Copyright (c) 2012, the Dart project authors.
Please see the AUTHORS file for details.
All rights reserved. Use of this source code is
governed by a BSD-style license that can be found
in the LICENSE file.
-->