Skip to main content

prefer_collection_literals

Unnecessary constructor invocation.

Description

#

The analyzer produces this diagnostic when a constructor is used to create a list, map, or set, but a literal would produce the same result.

Example

#

The following code produces this diagnostic because the constructor for Map is being used to create a map that could also be created using a literal:

dart
var m = Map<String, String>();

Common fixes

#

Use the literal representation:

dart
var m = <String, String>{};