In dart programming language we have mixins which basically are pack of reusable codes. like when we need to add a functionality to our class we use mixins. Imagine have a function like that:
void endSession {
print('end');
}
if we define this function in a file like end_session_handler.dart we can use this function all over the app in every classes. but with mixins in dart we basically do the same thing with lots of boilerplate codes! like that in end_session_mixin:
mixin CanEndSession {
void endSession{
print('end');
}
}
and in a class which we want use this code we write:
class Example with CanEndSession {
endSession();
}
Why we should use mixins rather than global functions in our apps?