I am using VS code when I create List without assigning values …the compiler throw Error: Couldn’t find constructor ‘List’:
I tried to declare fixed length List but error occurs .please one can fix this I am beginner.
2
It’s not the correct syntax for the dart.
Here is the way you do this:
void main() { List<int?> lst = List<int?>.filled(3, null); lst[0]=1; lst[1]=2; lst[2]=3; print(lst.runtimeType); print(lst); }
For more read documentation.
you implement wrong syntax in dart so correct syntax way is.
void main() { List<int> list = []; list.add(11); list.add(12); list.add(13); print('list: $list'); } o/p: list: [11, 12, 13]
2nd way is
List mList = List.filled(5, null, growable: false); mList[0] = 12; mList[1] = 22; mList[2] = 33 ; print(mList) o/p: [12, 22, 33, null, null]
Click here to cancel reply.
2
Answers
It’s not the correct syntax for the dart.
Here is the way you do this:
For more read documentation.
you implement wrong syntax in dart so correct syntax way is.
2nd way is