non_constant_map_key
The keys in a const map literal must be constant.
Description
#The analyzer produces this diagnostic when a key in a constant map literal isn't a constant value.
Example
#The following code produces this diagnostic because a
isn't a constant:
dart
var a = 'a';
var m = const {a: 0};
Common fixes
#If the map needs to be a constant map, then make the key a constant:
dart
const a = 'a';
var m = const {a: 0};
If the map doesn't need to be a constant map, then remove the const
keyword:
dart
var a = 'a';
var m = {a: 0};
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。