-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type cast error when using FactoryConverter #631
Comments
Hi, can you please provide an example / repo which reproduces this error? |
Hi. Unfortunately, I've already over-worked that code and I don't have any copies left. I'll try to investigate this further when I have more free time. |
I was able to reproduce this with the following code snippet import 'dart:async';
import 'package:chopper/chopper.dart';
part 'api.chopper.dart';
@ChopperApi()
abstract class ApiService extends ChopperService {
static ApiService create([ChopperClient? client]) =>
_$ApiService(client);
@FactoryConverter(response: convertResponse)
@GET(path: 'v2/breaches')
Future<Response<List<Map<String, dynamic>>>> fetch();
static FutureOr<Response<T>> convertResponse<T>(Response res) =>
const JsonConverter().convertResponse(res);
}
Future<void> main() async {
final chopper = ChopperClient(
baseUrl: Uri.parse('https://haveibeenpwned.com/api/'),
services: [
ApiService.create(ChopperClient()),
],
converter: JsonConverter(),
errorConverter: const JsonConverter(),
);
final apiService = chopper.getService<ApiService>();
final response = await apiService.fetch();
print(response.body);
chopper.dispose();
} Which throws
@TheLastFlame in order to fix it you have to provide the List's inner type static FutureOr<Response<T>> convertResponse<T>(Response res) =>
const JsonConverter().convertResponse<
T,
Map<String, dynamic> // <-- you need to provide the inner type
>(res); Which would then summount to @ChopperApi()
abstract class ApiService extends ChopperService {
static ApiService create([ChopperClient? client]) => _$ApiService(client);
@FactoryConverter(response: convertResponse)
@GET(path: 'v2/breaches')
Future<Response<List<Map<String, dynamic>>>> fetch();
static FutureOr<Response<T>> convertResponse<T, Q extends Map<String, dynamic>>(Response res) =>
const JsonConverter().convertResponse<T, Q>(res);
} |
Steps to Reproduce
Use FactoryConverter for a request with the specified response type.
Expected results:
Correct behavior similar to global converter usage
Actual results:
type 'List' is not a subtype of type 'Response<List<Map<String, dynamic>>>' in type cast
Code sample
Logs
The text was updated successfully, but these errors were encountered: