It is really important to understand the language in-dept in order to become a pro developer.

Dart is a programming language for Flutter and just like other project languages, Dart also has many more cool features. Today i would like to give you some tips about MIXIN feature.

Mixin is one of the powerful feature in the dart. It will help you to reuse code accross multiple classess and helps you to reduce most boilerplate codes.

Flutter uses this feature heavily in the framework itself. If you check the AnimatedController class you can understand.

I would like to produce a simple example here to quickly understant the concept.


void main() {
  final musician = Musician();
  print(musician.canSing());
  //returns true
}


mixin Feature {
  bool canSingNow = false;

  bool canSing() {
    return canSingNow;
  }
}

class Musician with Feature {

  Musician() {
    canSingNow = true;
  }
}

Let me know if you have any questions.

Thanks