Dart Mixins : Mixin in Code

Dart Mixins : Mixin in Code

·

1 min read

Mixin in code :

  • A mixin is a class with methods and properties utilized by other classes in Dart.

  • It is a way to reuse code and write code clean.

mixin Fly {
  void fly() {
    print("Flying...");
  }
}

class Bird with Fly {
  // Bird class can now fly using the fly() method from the Fly mixin
}

void main() {
  var bird = Bird();
  bird.fly(); // Output: Flying...
}