#Flutter Friday №3

The Dart Edition

Maksim Lin
2 min readMar 20, 2020
Photo by Marc A on Unsplash

The Dart language is at the heart of Flutter. This weeks edition looks at some less well known features of the language, recently added features, as well as some exciting new features coming to Dart in the future.

DSL’s

Domain specific languages have been popular in languages like Ruby for a while now and are gaining popularity in mobile development with the powerful features present in Kotlin. But Dart itself also has some powerful features that can lend themselves well to implement DSL’s. One such less well known feature is Callable Classes, which means that instances of a class can be called as if they are a function, by implementing a call() method.

A not so recent feature that helps with creating DSLs in Dart is the removal of the need to use the new keyword to instantiate new instances of a class, which along with named constructor parameters, gives a nice way to create DSL syntax, which of course can be seen in great use within Flutters ubiquitous Widget classes. With the recent addition in Dart 2.3 of the spread operator and conditional lists, the “UI DSL” that is Flutter becomes even nicer.

Better Enums

Recently released in Dart 2.7, extension functions mean not only that you can add static methods to Classes (as is common in Kotlin) but you can also do so for Enums! While this is not quite as powerful as Kotlin’s sealed classes, super charging Darts anaemic Enums to be able to have all sorts of data attached. This then allows the us developers to make use of the analysers very nice functionality of warning when not all Enum cases are covered in a switch statement.

Null Safety

The previous point about using Enum’s with switch statements is a little bit defeated by still needing to have a defaultcase to cover the possibility of null values as I found out. But coming soon,though not yet announced in which upcoming version of Dart, is the new null-safety feature (previously called NNBD: non-null by default) which will bring non-nullable types to Dart, which will not only solve this issue, but really bring Dart to a whole new level. While it’s not clear when this new feature will be available for use in Flutter, it is already possible to test it out using the null-safety enabled Dart pad.

Well that’s all for another edition, I’ll be back with another edition next week, but for now hope you have a good weekend! ⛱️

--

--

Maksim Lin

Long time Android Developer now doing Flutter. Co-organiser of Flutter Melbourne.