List filled flutter

Flutter: List is deprecated?

Ok found it, it's just how to instantiate it:

List _files = [];

Edit: maybe the most common ones, a bit more detailed according to the docs:

Fixed-length list of size 0

List _list = List.empty[];

Growable list

List _list = []; //or List _list = List.empty[growable: true];

Fixed length with predefined fill

int length = 3; String fill = "test"; List _list = List.filled[length ,fill , growable: true]; // => ["test", "test", "test"]

List with generate function

int length = 3; MyClass myFun[int idx] => MyClass[id: idx]; List _list = List.generate[length, myFun, growable: true]; // => [Instance of 'MyClass', Instance of 'MyClass', Instance of 'MyClass']

Video liên quan

Chủ Đề