Dart Analyze logoDart Analyze/
DRT-W1516

The keys in a const map literal must be constantDRT-W1516

Major severityMajor
Bug Risk categoryBug Risk

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:

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:

const a = 'a';
var m = const {a: 0};

If the map doesn't need to be a constant map, then remove the const keyword:

var a = 'a';
var m = {a: 0};