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

执行flutter pub run build_runner build生成JSON序列化器遇super-parameters错误

解决Flutter build_runner生成JSON序列化代码时的super-parameters错误

以下是针对问题的有效解决步骤:

  • 修正analysis_options.yml配置
    你之前添加的是lint规则,无法启用目标语言特性。需要在项目根目录的analysis_options.yml中添加语言特性启用配置:

    analyzer:
      language:
        enableSuperParameters: true
    
  • 完善序列化类代码
    你的HttpErrorResponse类缺少必要的序列化方法和构造函数,补全后才能让build_runner正确生成代码:

    import 'package:json_annotation/json_annotation.dart';
    part 'HttpErrorResponse.g.dart';
    
    @JsonSerializable()
    class HttpErrorResponse {
      late final String type;
      late final String title;
      late final int status;
      late final String detail;
      late final String instance;
    
      HttpErrorResponse();
    
      factory HttpErrorResponse.fromJson(Map<String, dynamic> json) => _$HttpErrorResponseFromJson(json);
      Map<String, dynamic> toJson() => _$HttpErrorResponseToJson(this);
    }
    
  • 清理缓存并重新生成
    执行以下命令彻底清理缓存、更新依赖并重新生成代码:

    flutter pub cache clean
    flutter pub get
    flutter pub run build_runner build --delete-conflicting-outputs
    
  • 确保依赖版本兼容
    更新pubspec.yml中的依赖版本,适配Flutter 3.7.0(Dart 2.19.0):

    dependencies:
      json_annotation: ^4.8.1
    dev_dependencies:
      json_serializable: ^6.7.0
    

    执行flutter pub upgrade完成版本更新。

内容的提问来源于stack exchange,提问作者Camilo Vasquez

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 10:45:28