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>{};
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。