retrofit_generator:retrofit crash after upgrade to Null Safe version on Flutter
414
This is a reported issue here.
It will be fixed in the next release.
For the temporary fix:
retrofit_generator:
git:
url: https://github.com/Chimerapps/retrofit.dart.git
ref: 9f90296751984b359937c38563da5b19db5550f5
path: generator
![Cosmin Constantin Firta](https://i.stack.imgur.com/gCBRU.jpg?s=256&g=1)
Author by
Cosmin Constantin Firta
Updated on November 23, 2022Comments
-
Cosmin Constantin Firta over 1 year
I am trying to upgrade my Flutter app to be Null Safe and I encountered a problem with the
retrofit
code generator.So I have a
RestAPI
abstract class declared like this:@RestApi(baseUrl: ApiConsts.authBaseURL) abstract class IAuthApi { factory IAuthApi(Dio dio) = _IAuthApi; @POST(ApiConsts.verifyPath) Future<AccessToken> verifyToken(@Body() VerifyBody body); }
and the data classes are as follows:
@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); }
When I run the command to generate my retrofit code
pub run build_runner build --delete-conflicting-outputs
I get the following error:
[SEVERE] retrofit_generator:retrofit on lib/services/api/AuthAPI.dart: type 'ExpandIterable<InterfaceType, MethodElement>' is not a subtype of type 'Iterable<MethodElementImpl>' of 'iterable'
Has anyone encountered something like this?