Object Oriented Dart & Flutter. Koans way.

Classes and Objects

first OOP program

How it works

Person john = Person(name: 'John', gender: Gender.male, age: 20);

Try the code

place for our experiments
import 'package:flutter_test/flutter_test.dart';const ___ = "FILL ME IN";class Gender {  static const female = "woman";  static const male = "man";}class Person {  String name;  String gender;  int age;  Person({this.name, this.gender, this.age});  String bio() {    return "My name is $name. I'm a $age years old $gender";  }}void main() {  test('Object creation', () {      Person john = Person(name: 'John', gender: Gender.male, age: 20);      expect('My name is John. I\'m a 20 years old man', john.bio());  });}
run it!
Unit tests passed successfully, Koan is Green

What’s inside a class?

Green test after the modification
Green test after the modification
Red Koan after the modification
Person(name: 'John', gender: Gender.male, age: 20)
Person('John', Gender.male, 20)
Koan is Green again!

Final notes

Gender.male

Conclusion

--

--

Software Engineer, CTO at FlutLab

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store