Skip to content

Commit 53faa33

Browse files
authored
[dart mdoe] Fix code example to compile and run with modern Dart versions
1 parent ee6a1d2 commit 53faa33

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

mode/dart/index.html

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,33 +29,33 @@ <h2>Dart mode</h2>
2929
import 'dart:math' show Random;
3030

3131
void main() {
32-
print(new Die(n: 12).roll());
32+
print(Die(n: 12).roll());
3333
}
3434

3535
// Define a class.
3636
class Die {
3737
// Define a class variable.
38-
static Random shaker = new Random();
38+
static final Random shaker = Random();
3939

4040
// Define instance variables.
41-
int sides, value;
42-
43-
// Define a method using shorthand syntax.
44-
String toString() => '$value';
41+
final int sides;
42+
int? lastRoll;
4543

4644
// Define a constructor.
47-
Die({int n: 6}) {
48-
if (4 <= n && n <= 20) {
49-
sides = n;
50-
} else {
45+
Die({int n = 6}) : sides = n {
46+
if (4 > n || n > 20) {
5147
// Support for errors and exceptions.
52-
throw new ArgumentError(/* */);
48+
throw ArgumentError(/* */);
5349
}
5450
}
5551

52+
// Define a method using shorthand syntax.
53+
@override
54+
String toString() => '$lastRoll';
55+
5656
// Define an instance method.
5757
int roll() {
58-
return value = shaker.nextInt(sides) + 1;
58+
return lastRoll = shaker.nextInt(sides) + 1;
5959
}
6060
}
6161
</textarea>

0 commit comments

Comments
 (0)