This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
void main() { | |
for (int i = 0; i < 5; i++) { | |
print('hello ${i + 1}'); | |
} | |
} |
This file contains hidden or 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
class Bicycle { | |
int cadence; | |
int speed; | |
int gear; | |
Bicycle(this.cadence, this.speed, this.gear); | |
@override | |
String toString() => 'Bicycle: $speed mph'; | |
} |
This file contains hidden or 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
class Bicycle { | |
int cadence; | |
int _speed; | |
int gear; | |
Bicycle(this.cadence, this._speed, this.gear); | |
int get speed => _speed; | |
void applyBrake(int decrement) { |
This file contains hidden or 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 hidden or 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 { | |
Point origin; | |
int width; | |
int height; | |
Rectangle({this.origin = const Point(0, 0), this.width = 0, this.height = 0}); | |
@override |
This file contains hidden or 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'; | |
abstract class Shape { | |
num get area; | |
} | |
class Circle implements Shape { | |
final num radius; | |
Circle(this.radius); | |
num get area => PI * pow(radius, 2); |