Is it possible to initialize a List on one line in Dart? (it's called a collection initializer in c#)

Yes:

List<int> options = [1, 2, 5, 9];

I'd recommend reading:

  • https://v1-dartlang-org.firebaseapp.com/resources/dart-tips/dart-tips-ep-5
  • https://api.dartlang.org/stable/1.24.3/dart-core/List-class.html

Yes, you can do it using the List.unmodifiable constructor:

var options  = new List.unmodifiable([3,6,7,8]);

Or by using the List.from constructor:

var options  = new List.from([3,6,7,8]);

Or just like this:

var options  = [5,7,9,0];

Tags:

Dart