non_ constant_ map_ value
The values in a const map literal must be constant.
Description
#The analyzer produces this diagnostic when a value 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 {0: a};
Common fixes
#If the map needs to be a constant map, then make the key a constant:
const a = 'a';
var m = const {0: a};
If the map doesn't need to be a constant map, then remove the
const
keyword:
var a = 'a';
var m = {0: a};
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.