You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter 3.13.1构建失败:ClassDeclaration无macroKeyword getter问题求助

解决build_runner构建错误:The getter 'macroKeyword' isn't defined for the class 'ClassDeclaration'

这个错误是依赖版本不兼容导致的:你当前使用的dart_style:2.3.5版本与analyzer:6.2.0版本存在API冲突——analyzer 6.x版本移除了ClassDeclaration类中的macroKeyword属性,但旧版dart_style仍在尝试调用这个已被移除的属性。

修复步骤:

  • 强制指定兼容的dart_style版本
    在项目的pubspec.yaml文件中添加配置:

    # 如果dart_style是直接依赖,在dev_dependencies下指定版本
    dev_dependencies:
      dart_style: ^2.3.6
    
    # 如果dart_style是间接依赖,使用dependency_overrides强制覆盖版本
    dependency_overrides:
      dart_style: ^2.3.6
    
  • 清理缓存并重新拉取依赖
    执行以下命令:

    flutter clean
    flutter pub get
    
  • 重新运行build_runner构建

    flutter pub run build_runner build
    

dart_style:2.3.6版本已经修复了对analyzer 6.x系列的兼容问题,移除了对macroKeyword属性的调用,因此升级后即可解决该构建错误。

内容的提问来源于stack exchange,提问作者Shweta Chauhan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 23:29:54