【问题标题】:retrofit_generator:retrofit crash after upgrade to Null Safe version on Flutterretrofit_generator:在 Flutter 上升级到 Null Safe 版本后改造崩溃
【发布时间】:2021-08-16 15:35:21
【问题描述】:

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

所以我有一个 RestAPI 抽象类声明如下:


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

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

数据类如下:

@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'

有人遇到过这种情况吗?

【问题讨论】:

    标签: flutter dart retrofit dart-null-safety


    【解决方案1】:

    这是一个报告的问题here

    下个版本会修复。

    对于临时修复:

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

    【讨论】:

    • 这行得通。惊人的。非常感谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-05-12
    • 1970-01-01
    • 2013-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多