non_constant_map_pattern_key工具 chevron_right诊断 chevron_rightnon_constant_map_pattern_key 目录描述示例常见修复方法Map 模式中的键表达式必须是常量。描述#当 Map 模式中的键不是常量表达式时,分析器会产生此诊断。示例#以下代码会产生此诊断,因为键 A() 不是常量dartvoid f(Object x) { if (x case {A(): 0}) {} } class A { const A(); }常见修复方法#使用常量作为键dartvoid f(Object x) { if (x case {const A(): 0}) {} } class A { const A(); }本页面内容有帮助吗?thumb_up thumb_down感谢您的反馈! feedback 提供详细信息感谢您的反馈!请告诉我们如何改进。 bug_report 提供详细信息除非另有说明,本网站上的文档反映了 Dart 3.8.1。页面最后更新于 2025-05-08。 查看源代码 或 报告问题。