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
- extends and Method Overriding
- Calling super and Constructor Chaining
- Mixins With the with Keyword
- on Constraints and Mixin Order