jonataslaw / jonataslaw/get_cli
Unhandled Exception: type '(dynamic) => Object?' is not a subtype of type '((dynamic) => Todo)?' in type cast
- Dominant language
- Dart
- Stars
- 654
- Forks
- 193
- PR merge metrics
- No merged PRs in 30d
Description
I have generated model and provider by:
`get generate model from 'https://jsonplaceholder.typicode.com/todos/1'`
But when doing any request, it throws exception: _Unhandled Exception: type '(dynamic) => Object?' is not a subtype of type '((dynamic) => Todo)?' in type cast_
The generated provider code:
```
class TodoProvider extends GetConnect {
@override
void onInit() {
httpClient.defaultDecoder = (map) {
if (map is Map) return Todo.fromJson(map);
if (map is List) return map.map((item) => Todo.fromJson(item)).toList();
};
httpClient.baseUrl = 'https://jsonplaceholder.typicode.com/';
}
Future getTodo(int id) async {
final response = await get('$id');
return response.body;
}
Future> postTodo(Todo todo) async => await post('', todo);
Future deleteTodo(int id) async => await delete('$id');
}
```
If I change the `httpClient.defaultDecoder` to:
`httpClient.defaultDecoder = (map) {
return Todo.fromJson(map);
};`
works OK. But if I add a method to get the todo list, then does not because as you can see the list decoder is needed but is not provided anymore and throws:
`Unhandled Exception: type '(dynamic) => Todo' is not a subtype of type '((dynamic) => List)?' in type cast`
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.