retrofit_generator:retrofit 在 Flutter 上升级到 Null Safe 版本后崩溃

retrofit_generator:retrofit crash after upgrade to Null Safe version on Flutter

我正在尝试将我的 Flutter 应用程序升级为 Null Safe,但我遇到了 retrofit 代码生成器的问题。

所以我有一个 RestAPI 摘要 class 声明如下:


@RestApi(baseUrl: ApiConsts.authBaseURL)
abstract class IAuthApi {
  factory IAuthApi(Dio dio) = _IAuthApi;

  @POST(ApiConsts.verifyPath)
  Future<AccessToken> verifyToken(@Body() VerifyBody body);
}

和数据class如下:

@JsonSerializable(includeIfNull: false)
class VerifyBody {
  @JsonKey(name: 'grant_type')
  String grantType;
  @JsonKey(name: 'client_id')
  String clientId;
  String username;
  String otp;
  String realm;
  String audience;
  String scope;

  VerifyBody(this.username, this.otp,
      {this.grantType = ApiConsts.GRANT_TYPE,
      this.clientId = ApiConsts.CLIENT_ID,
      this.realm = ApiConsts.SMS,
      this.audience = ApiConsts.AUDIENCE,
      this.scope = ApiConsts.AUTH_SCOPE});
  factory VerifyBody.fromJson(Map<String, dynamic> json) => _$VerifyBodyFromJson(json);
  Map<String, dynamic> toJson() => _$VerifyBodyToJson(this);
}

@JsonSerializable(includeIfNull: false)
class AccessToken {
  @JsonKey(name: 'access_token')
  String accessToken;
  @JsonKey(name: 'refresh_token')
  String refreshToken;
  @JsonKey(name: 'id_token')
  String idToken;
  String scope;
  @JsonKey(name: 'expires_in')
  int expiresIn;
  @JsonKey(name: 'token_type')
  String tokenType;

  AccessToken(this.accessToken, this.refreshToken, this.idToken, this.scope, this.expiresIn,
      this.tokenType);
  factory AccessToken.fromJson(Map<String, dynamic> json) => _$AccessTokenFromJson(json);
  Map<String, dynamic> toJson() => _$AccessTokenToJson(this);
}

当我运行命令生成我的改装代码pub run build_runner build --delete-conflicting-outputs

我收到以下错误:

[SEVERE] retrofit_generator:retrofit on lib/services/api/AuthAPI.dart:

type 'ExpandIterable<InterfaceType, MethodElement>' is not a subtype of type 'Iterable<MethodElementImpl>' of 'iterable'

有人遇到过这样的事情吗?

这是一个已报告的问题 here

下个版本会修复

对于临时修复:

retrofit_generator:
  git:
    url: https://github.com/Chimerapps/retrofit.dart.git
    ref: 9f90296751984b359937c38563da5b19db5550f5
    path: generator