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() { | |
print("Hello world!"); | |
} |
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() { | |
bool trueBoolean = true; | |
bool falseBoolean = false; | |
} |
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() { | |
dynamic dynamicVariable = "A string"; | |
dynamicVariable = 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 Point { | |
final int x; | |
final int y; | |
const Point(this.x, this.y); | |
Point operator +(Point other) { | |
return Point(x + other.x, y + other.y); | |
} | |
} |
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() { | |
var addition = 3 + 2; // 5 | |
var subtraction = 3 - 2; // 1 | |
var negation = -1; // -1 | |
var multiplication = 3 * 2; // 6 | |
var division = 3 / 2; // 1.5 | |
var integerDivision = 3 ~/ 2; // 1 | |
var modulo = 3 % 2; // 1 | |
modulo++; // 2 | |
modulo--; // 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
import 'package:collection/collection.dart'; | |
void main() { | |
var gt = 5 > 4; // true | |
var lt = 5 < 4; // false | |
var list1 = [1, 2, 3]; | |
var list2 = [1, 2, 3]; | |
var equality = list1 == list2; // false | |
var identity = identical(list1, list2); // false | |
var collectionEquality = IterableEquality().equals(list1, list2); // true |
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 'package:collection/collection.dart'; | |
void main() { | |
Iterable iterable1 = [1, 2, 3]; | |
Iterable iterable2 = {1, 2, 3}; | |
if (iterable1 is List && iterable2 is List) { | |
iterable1.shuffle(); // Smart cast from Iterable to List | |
print(ListEquality().equals(iterable1, iterable2)); | |
} else { | |
print(IterableEquality().equals(iterable1, iterable2)); |
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() { | |
int? nullableNumber = 1; | |
int number = nullableNumber!; | |
List<int>? myList; // null | |
print(myList?.length ?? 0); // 0 | |
myList ??= [1, 2, 3]; | |
print(myList.length); // 3 | |
} |
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() { | |
final score = 7; | |
final result = score >= 5 ? "Passed" : "Failed"; | |
String message; | |
switch (result) { | |
case "Passed": | |
message = "Congratulations!"; | |
break; | |
case "Failed": | |
message = "Keep trying!"; |
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 (var i = 5; i >= 0; i = i - 2) { | |
print(i); // 5 3 1 | |
} | |
for (var num in [1, 4, 5, 2]) { | |
print(num); // 1 4 5 2 | |
} | |
final set = {"A", "B", "C"}; | |
set.forEach((letter) { | |
print(letter); // A B C |