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:
var m = Map<String, String>();
Common fixes
#Use the literal representation:
var m = <String, String>{};
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.