Skip to content

Latest commit

 

History

History
211 lines (170 loc) · 4.45 KB

README.md

File metadata and controls

211 lines (170 loc) · 4.45 KB

Flutter samples

GitHub: gerfalcon Twitter: GerfalconVogel

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.

Flutter Quiz

Given the code below, what will print out to the console?

DartPad

void main() {
  final x = 3.5;
  final y = double.infinity;

print('${y.ceil()}');
}
  • ✅ Uncaught Error: Unsupported operation
  • ❌ 3
  • ❌ 4
  • ❌ 'double.infinity'

2. String Breaking

DartPad

void main() {
  final maybeText = 'a'
    'b'
    'c';

  print(maybeText);
}
  • ❌ 'a\nb\nc'
  • ✅ 'abc'
  • ❌ 'a b c'
  • ❌ 'Compilation error'

3. Const DateTime

DartPad

void main() {
  const date = DateTime.now();
  print(date);
}
  • ❌ 'Prints compile-time DateTime'
  • ❌ 'Prints run-time DateTime'
  • ❌ 'Runtime Error'
  • ✅ 'Compilation Error'

4. Test assertion

void main() {
  test('My mom would be proud', () {
    print(expect(true, true));
  });
}
  • ❌ 'Test passed: 1'
  • ❌ 'Expected: , Actual: <'true'>'
  • ❌ 'Test failed'
  • ✅ 'Compilation Error'

DartPad

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 (...)'

DartPad

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'

DartPad

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

DartPad

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'

9. Lists

DartPad

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

10. Platform

❗❗❗❗ Given the code below, what couldn't print out to the console?

void main() {
    
  print(Platform.operatingSystem.toString());
  
}
  • ❌ fuchsia
  • ❌ windows
  • ❌ macos
  • ✅ iphone