Search code examples
dartdart-null-safety

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


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>>