未处理的异常:不支持的操作:通用 DartType 的序列化:UnknownType(?) (UnknownType)

Unhandled exception: Unsupported operation: serialization of generic DartType: UnknownType(?) (UnknownType)

我一直收到这个错误

Unhandled exception: Unsupported operation: serialization of generic DartType: UnknownType(?) (UnknownType)

每次我尝试 运行 我的项目。 我 运行 flutter packages pub run build_runner build 我得到 pub finished with exit code 78

/// Something was unconfigured or mis-configured. const CONFIG = 78;

This is likely because the.dart_tool/build folder was deleted, or you are submitting generated files to your source repository. [SEVERE] Conflicting outputs were detected and the build is unable to prompt for permission to remove them. These outputs must be removed manually or the build can be run with `--delete-conflicting-outputs

然后我继续 运行 flutter packages pub run build_runner build --delete-conflicting-outputs 并得到

[INFO] Succeeded after 49.5s with 14 outputs (227 actions)

然后在 运行我的应用程序中,我们得到 the Dart compiler exited unexpectedly.

通过添加 build.yaml 解决了它 配置:

    targets:
  $default:
    builders:
      json_serializable:
        options:
          # Options configure how source code is generated for every
          # `@JsonSerializable`-annotated class in the package.
          #
          # The default value for each is listed.
          any_map: false
          checked: false
          create_factory: true
          create_to_json: true
          disallow_unrecognized_keys: false
          explicit_to_json: false
          field_rename: none
          ignore_unannotated: false
          include_if_null: true
          nullable: true

[INFO] Succeeded after 199ms with 0 outputs (0 actions)