getService<ServiceType extends ChopperService> method
ServiceType
getService<ServiceType extends ChopperService>()
Retrieve any service included in the ChopperClient
final chopper = ChopperClient(
baseUrl: Uri.parse('localhost:8000'),
services: [
// Add a generated service
TodosListService.create()
],
);
final todoService = chopper.getService<TodosListService>();
Implementation
ServiceType getService<ServiceType extends ChopperService>() {
if (ServiceType == dynamic || ServiceType == ChopperService) {
throw Exception(
'Service type should be provided, `dynamic` is not allowed.',
);
}
final ChopperService? service = _services[ServiceType];
if (service == null) {
throw Exception("Service of type '$ServiceType' not found.");
}
return service as ServiceType;
}