Introduction to Mixins

This lesson introduces the concept of mixins in Dart. In addition, you will learn to create mixins.

Introduction

Mixins allow Dart code to be reusable across separate classes. It is more efficient to reuse common code from multiple classes that share common behaviors.

A mixin class contains methods used by other classes without being their parent. It allows us to use a class’ code without having to inherit from it. This is how mixins differ from interfaces and abstract classes.

Declaring Mixins

Mixins are declared using the keyword mixin like below:

mixin SharedBehavior {

}

Get hands-on with 1200+ tech skills courses.