Null Safety equivalent of "List<List<T>>()"?

Issue

My old working code:
List<List<T>> pages = List<List<T>>();

Now doesn’t work with null safety:

The default ‘List’ constructor isn’t available when null safety is enabled.
Try using a list literal, ‘List.filled’ or ‘List.generate’.dartdefault_list_constructor
‘List’ is deprecated and shouldn’t be used. Use a list literal, [], or the List.filled constructor instead.

Solution

// @dart=2.12
void doSomething<T>() {
  List<List<T>> pages = [];
  print(pages.runtimeType.toString());
}

void main() {
  doSomething<String>();
}

Result

JSArray<List<String>>

Answered By – Ουιλιαμ Αρκευα

Answer Checked By – Candace Johnson (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *