7 Cool Features of Dart Language. Mixins, Cascade notation, and more | by Dedan Ndungu | Apr, 2022

Mixins, Cascade notation, and extra

Photograph by AltumCode on Unsplash

In the present day’s article is a brief revelation of the cool options that the dart language provides. Extra typically these choices will not be crucial for easy apps however are a lifesaver while you need to enhance your code by making it easy, clear, and concise.

With that in thoughts let’s go.

Cascades (.., ?..) assist you to make a sequence of operations on the identical object. This typically saves you the step of making a short lived variable and means that you can write extra fluid code.

Use the summary modifier to outline an summary class (a category that may’t be instantiated). Summary courses are helpful for outlining interfaces, typically with some implementation.

Manufacturing unit constructors

Use the manufacturing unit key phrase when implementing a constructor that doesn’t all the time create a brand new occasion of its class.

Named constructors

Use named constructors to implement a number of constructors for a category or to offer additional readability:

Mixins are a means of reusing a category’s code in a number of class hierarchies.

To implement a mixin, create a category that declares no constructors. Until you need your mixin to be usable as a daily class, use the mixin key phrase as a substitute of class.

To use a mixin, use the with key phrase adopted by a number of mixin names.

To limit the kinds that may use a mixin use the on key phrase to specify the required superclass.

A kind alias — is a concise approach to confer with a sort. Generally used to create a customized sort that’s used rather a lot within the mission.

Extension strategies, launched in Dart 2.7, are a means so as to add performance to current libraries and code.

You may make positional parameters non-obligatory by wrapping them in brackets. Elective positional parameters are all the time final in a operate’s parameter checklist. Their default worth is null except you present one other default worth.

If you need to begin a fire-and-forget Future, the beneficial means is to make use of unawaited

For those who come throughout one other cool function, please let me know in order that I can high it up on this checklist.

That’s all for at the moment.

More Posts