I am using chopper in my flutter project like this.
AuthRestService class:
import 'package:chopper/chopper.dart';
import 'package:flutter_meal_app/utils/constants.dart';
import 'package:injectable/injectable.dart';
part 'auth_rest_service.chopper.dart';
@prod
@singleton
@ChopperApi()
abstract class AuthRestService extends ChopperService {
@Post(path: '/accounts:signUp?key={authKey}')
Future<Response> signup(@Path('authKey') String authKey, @Body() Map<String, dynamic> body);
@Post(path: '/accounts:signInWithPassword?key={authKey}')
Future<Response> login(@Path('authKey') String authKey, @Body() Map<String, dynamic> body);
@factoryMethod
static AuthRestService create() {
final client = ChopperClient(
baseUrl: Constants.AUTH_BASE_URL,
converter: JsonConverter(),
services: [_$AuthRestService()],
interceptors: [HttpLoggingInterceptor()]);
return _$AuthRestService(client);
}
}
The way I use signup call..
final response = await _authRestService.signup(AUTH_KEY,
{'email': email, 'password': password, 'returnSecureToken': true});
Here is the log of webcall (both success and failure)..
--> POST https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=yourauthkey
content-type: application/json; charset=utf-8
{"email":"[email protected]","password":"123456","returnSecureToken":true}
--> END POST (78-byte body)
Success:
{
"idToken":"....",
........
}
Failure:
<-- 400 https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=yourauthkey
cache-control: no-cache, no-store, max-age=0, must-revalidate
date: Sat, 17 Oct 2020 09:10:32 GMT
transfer-encoding: chunked
content-encoding: gzip
vary: Origin,X-Origin,Referer
content-type: application/json; charset=UTF-8
pragma: no-cache
x-xss-protection: 0
server: ESF
alt-svc: h3-Q050=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-27=":443"; ma=2592000,h3-T051=":443"; ma=2592000,h3-T050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
expires: Mon, 01 Jan 1990 00:00:00 GMT
{
"error": {
"code": 400,
"message": "EMAIL_EXISTS",
"errors": [
{
"message": "EMAIL_EXISTS",
"domain": "global",
"reason": "invalid"
}
]
}
}
--> END POST
And The error I got in my logs is:
error is Instance of 'Response<dynamic>'
I used the same type of RestService in my project which is pointed to another server and It works, this AuthRestService is exact copy of restservice for firebase authentication. The error that I got in my logs is from the line where we call "signup" API, which makes me curious about my ChopperClient.
Do you guys know what is going wrong?? Please help. Thanks.
Maybe you can parse error response like this
SignUpResponse