non_constant_map_key工具 chevron_right诊断 chevron_rightnon_constant_map_key 目录描述示例常见修复方法const map 字面量中的键必须是常量。描述#当常量 map 字面量中的键不是常量值时,分析器会产生此诊断信息。示例#以下代码会产生此诊断信息,因为 a 不是常量dartvar a = 'a'; var m = const {a: 0};常见修复方法#如果 map 需要是常量 map,则将键设为常量dartconst a = 'a'; var m = const {a: 0};如果 map 不需要是常量 map,则删除 const 关键词dartvar a = 'a'; var m = {a: 0};本页面内容是否有帮助?thumb_up thumb_down感谢您的反馈! feedback 提供详细信息感谢您的反馈!请告诉我们如何改进。 bug_report 提供详细信息除非另有说明,本网站上的文档反映 Dart 3.8.1。页面最后更新于 2025-05-08。 查看源文件 或 报告问题。