This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math'; | |
class Rectangle { | |
int width; | |
int height; | |
Point origin; | |
} | |
main() {} // Included main() to suppress uncaught exception. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
main() { | |
var list = ['apples', 'oranges', 'grapes', 'bananas', 'plums']; | |
list.forEach((i) { | |
print(list.indexOf(i).toString() + ': ' + i); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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. | |
--> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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. | |
--> |