What’s New In Dart 2.3?

A quick walkthrough of the new features & changes in Dart 2.3!

Dart 2.3 is here! 🎉

With the new release of Dart 2.3, it comes with a set of new changes in both the library and the language. A majority of these changes are in Collections, since the goal of this release is to make Collections more declarative and expressive.

In this article, we’ll explore these changes in detail and talk about how to best utilise these new features of Dart.

Changelog

Here’s the list of the most important changes in Dart 2.3, in brief:

  1. The Spread operator ()
  2. Using if in a Collection
  3. Using for in a Collection

Let’s explore these one-by-one…

1. The Spread operator ()

Consider the following List of Text Widgets:

If we were to add all of these to a Row Widget, normally, we’d be doing something like this:

The problem with this is that if you wanted to add asianCountries first and then add northAmericanCountries, you’d have to include asianCountries first in the Row like so:

This requires you to re-order the addAll methods to your lists, which isn’t exactly convenient or ideal.

Enter, the new Spread operator! With the Spread operator, you can achieve the above result easily:

And this can be easily re-ordered like so:

2. Using if in a Collection

With the release of Dart 2.3, you can now also use if/else statements in your Collection literals.

Let’s consider the following “pre-Dart-2.3” example, where we display asianCountries only if the user belongs to an Asian country:

With Dart 2.3, this is how we’d go about doing it:

Doesn’t this look much cleaner and more readable? 😎

3. Using for in a Collection

Let’s say you want to modify your europeanCountries List before you use them anywhere. For the sake of demoing the new Dart 2.3 feature, let’s just prepend “New” before all the countries.

Before Dart 2.3, here’s how you’d go about doing it:

Here’s how you’d do it in Dart 2.3:

Conclusion

Of course, these aren’t all the changes in Dart 2.3. There are a few more in Dart’s core library, Dart VM, Dart for Web and other Dart tools which can be found here.

Upgrade your Dart SDK to get these features in your Flutter app today!


If you liked this article, click on the 👏 button (did you know you could go up to 50?), follow me here on Medium and share this article on your socials! You can also buy me coffee here.
Find me and all my socials here: