How to create an empty list in Dart

There are a few ways to create an empty list in Dart. If you want a growable list then use an empty list literal like this:

[]

Or this if you need to specify the type:

<String>[]

Or this if you want a non-growable (fixed-length) list:

List.empty()

Notes

  • In the past you could use List() but this is now deprecated. The reason is that List() did not initialize any members, and that isn’t compatible with null safe code. Read Understanding null safety: No unnamed List constructor for more.
  • Effective Dart Usage Guide

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)