🎛️ Mixin

Use mixins to extend specific behaviors to classes

What are mixins?

A mixin is just like a class, it can have methods and properties, but it can’t be instantiated.

file_type_dartlang mixins.dart
mixin Strong {
  bool doesLift = true;

  void benchPress() {
    print('doing bench press...');

mixin Fast {
  bool doesRun = true;

  void sprint() {
    print('running fast...');

What are mixins used for?

Mixins are used to extend specific behaviors to classes with the with keyword. Certain Flutter libaries use mixins to extend shared behaviors to classes.

file_type_dartlang mixins.dart
class Human {}

class SuperHuman extends Human with Strong, Fast {}

Questions? Let's chat

Open Discord