sdk_version_set_literal
Set literals weren't supported until version 2.2, but this code is required to be able to run on earlier versions.
Description
#The analyzer produces this diagnostic when a set literal is found in code that has an SDK constraint whose lower bound is less than 2.2.0. Set literals weren't supported in earlier versions, so this code won't be able to run against earlier versions of the SDK.
Example
#Here's an example of a pubspec that defines an SDK constraint with a lower bound of less than 2.2.0:
environment:
sdk: '>=2.1.0 <2.4.0'
In the package that has that pubspec, code like the following produces this diagnostic:
var s = <int>{};
Common fixes
#If you don't need to support older versions of the SDK, then you can increase the SDK constraint to allow the syntax to be used:
environment:
sdk: '>=2.2.0 <2.4.0'
If you do need to support older versions of the SDK, then replace the set literal with code that creates the set without the use of a literal:
var s = new Set<int>();
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。