0

i'm having a problem do declare a List<> in Dart.

Here is my code:

final lockers = List<Locker>();

for (Map map in listaResponse) {
      Locker l = Locker.fromJson(map);
      lockers.add(l);
}

And this is how it looks like:

What could be de cause?

I have no idea about what could possibly be the cause for that.

julemand101
  • 28,470
  • 5
  • 52
  • 48

1 Answers1

6

The zero-argument version of the List constructor is deprecated when null-safety is enabled. From its documentation:

NOTICE: This constructor cannot be used in null-safe code. Use List.filled to create a non-empty list. This requires a fill value to initialize the list elements with. To create an empty list, use [] for a growable list or List.empty for a fixed length list (or where growability is determined at run-time).

In your case, you should use a literal:

final lockers = <Locker>[];
jamesdlin
  • 81,374
  • 13
  • 159
  • 204