0Pricing
Dart Academy · Lesson

on Constraints and Mixin Order

Restrict and stack mixins correctly.

Mixins With Requirements

Sometimes a mixin only makes sense on certain classes. Dart lets you set that rule with an on constraint, so misuse is caught early. 🔒

The on Keyword

Adding on SomeType restricts where a mixin can be applied. Only classes that extend or implement that type may use it.

mixin Walker on Animal {
  void walk() => print('Walking');
}

All lessons in this course

  1. extends and Method Overriding
  2. Calling super and Constructor Chaining
  3. Mixins With the with Keyword
  4. on Constraints and Mixin Order
← Back to Dart Academy