Better Programming

Advice for programmers.

Follow publication

7 Cool Features of Dart Language

Mixins, Cascade notation, and more

Dedan Ndungu
Better Programming
Published in
2 min readApr 28, 2022
Photo by AltumCode on Unsplash

Today’s article is a short revelation of the cool features that the dart language offers. More often these options are not necessary for simple apps but are a lifesaver when you want to improve your code by making it simple, clear, and concise.

With that in mind let’s go.

Cascade notation

Cascades (.., ?..) allow you to make a sequence of operations on the same object. This often saves you the step of creating a temporary variable and allows you to write more fluid code.

Abstract classes

Use the abstract modifier to define an abstract class (a class that can’t be instantiated). Abstract classes are useful for defining interfaces, often with some implementation.

Factory constructors

Use the factory keyword when implementing a constructor that doesn’t always create a new instance of its class.

Named constructors

Use named constructors to implement multiple constructors for a class or to provide extra clarity:

Mixins

Mixins are a way of reusing a class’s code in multiple class hierarchies.

To implement a mixin, create a class that declares no constructors. Unless you want your mixin to be usable as a regular class, use the mixin keyword instead of class.

To use a mixin, use the with keyword followed by one or more mixin names.

To restrict the types that can use a mixin use the on keyword to specify the required superclass.

Typedefs

A type alias — is a concise way to refer to a type. Commonly used to create a custom type that is used a lot in the project.

Extension methods

Extension methods, introduced in Dart 2.7, are a way to add functionality to existing libraries and code.

Optional positional parameters

You can make positional parameters optional by wrapping them in brackets. Optional positional parameters are always last in a function’s parameter list. Their default value is null unless you provide another default value.

unawaited_futures

When you want to start a fire-and-forget Future, the recommended way is to use unawaited

If you come across another cool feature, please let me know so that I can top it up on this list.

That’s all for today.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Dedan Ndungu
Dedan Ndungu

Written by Dedan Ndungu

Senior Mobile Engineer || Flutter Enthusiast || Technical Writer

Responses (3)

Write a response