0

Create a list in my code of offset but show me an error with the below code

final List<Offset> p = List<Offset>(6);

Error:

The default 'List' constructor isn't available when null safety is enabled. (Documentation)
Try using a list literal, 'List.filled' or 'List.generate'.

But I can't convert it into literal with the (6) value because I have no knowledge of this!

krishnaacharyaa
  • 14,953
  • 4
  • 49
  • 88

1 Answers1

1

This type of initialization has become invalid because dart now supports null-safety.

Change the initialization to:

final List<Offset> p = List.filled(6, <Your Initial Offset Value Here>)
Example :
final List<Offset> p = List.filled(6, const Offset(0, 0));

Extra: You can even try the below code if you want empty list.

List<Offset> p = List<Offset>.empty(growable: true); // []

Further Reference:

krishnaacharyaa
  • 14,953
  • 4
  • 49
  • 88