In February '23, during the Flutter Forward Extended meetup of Flutter Abu Dhabi and Dubai, I gave the following technical quiz game activity for 50+ participants.
1. .ceil()
void main() {
final x = 3.5;
final y = double.infinity;
print('${y.ceil()}');
}
- ✅ Uncaught Error: Unsupported operation
- ❌ 3
- ❌ 4
- ❌ 'double.infinity'
void main() {
final maybeText = 'a'
'b'
'c';
print(maybeText);
}
- ❌ 'a\nb\nc'
- ✅ 'abc'
- ❌ 'a b c'
- ❌ 'Compilation error'
void main() {
const date = DateTime.now();
print(date);
}
- ❌ 'Prints compile-time DateTime'
- ❌ 'Prints run-time DateTime'
- ❌ 'Runtime Error'
- ✅ 'Compilation Error'
void main() {
test('My mom would be proud', () {
print(expect(true, true));
});
}
- ❌ 'Test passed: 1'
- ❌ 'Expected: , Actual: <'true'>'
- ❌ 'Test failed'
- ✅ 'Compilation Error'
Stream<int> streamGenerator() async* {
await Future.delayed(Duration(seconds: 1));
yield 0;
yield* streamGenerator();
}
void main() async {
await for (var value in streamGenerator()) {
print(value);
}
}
- ❌ 'Compilation Error'
- ❌ '0'
- ✅ '0 0 0 0 (...)'
- ❌ '0 1 2 3 (...)'
class ComplexUseCase {
Future<String> call(String text) async => text;
}
var useCase = ComplexUseCase();
var out = useCase("Hello world!");
void main() async => print(await out);
- ✅ 'Hello world'
- ❌ Instance of '_Future'
- ❌ 'ComplexUseCase("Hello world!")'
- ❌ 'out'
7. Future
void asyncFun() async {
try {
throw Exception("");
print("0");
} catch (e) {
print("1");
} finally {
await Future.delayed(Duration(seconds: 1));
print("2");
}
}
void main() {
asyncFun();
print("3");
}
- ❌ 0 1 2 3
- ❌ 1 2 3
- ✅ 1 3 2
- ❌ 3
8. TypeDef
typedef Animal = String;
typedef CuteFactor = int;
void main() {
const Map<Animal, CuteFactor> trend = {
'old grumpy cat': 4,
'dog': 100,
'tRex': 1
};
print(trend['dog'] as CuteFactor);
}
- ❌ trend['dog'] as CuteFactor
- ✅ 100
- ❌ dog
- ❌ 'Compilation Error'
void main() {
List<String> list1 = ['a', 'b', 'c'];
List<String> list2 = ['x', 'y'];
List<String>? listNullable = null;
List<String> lists = [
...list1,
if (false) ...list2,
...?listNullable,
];
print(lists);
}
- ❌ []
- ✅ [a, b, c]
- ❌ [a, b, c, x, y]
- ❌ null
❗❗❗❗ Given the code below, what couldn't print out to the console?
void main() {
print(Platform.operatingSystem.toString());
}
- ❌ fuchsia
- ❌ windows
- ❌ macos
- ✅ iphone