Skip to content

Destructuring Lists in Dart

Did you know?

Since Dart 3, you can easily destructure lists using the spread operator (…).

Very handy for getting the first and last value. 👌


Note that if the list has only one element, you’ll get a pattern matching error at runtime!

So make sure your assumptions are correct before using this. 👇


This example was taken from Pascal Welsch’s talk about “Exploring Records and Patterns” at FlutterCon.

Check the slides for many more tips about this topic:

Previous Next
Getting a Future from a FutureProvider with Riverpod Switch Matrix in Dart 3

Last update: 18 septembre 2023
Created: 18 septembre 2023