I am new to Flutter and I'd like to understand what's wrong with my error handler:
import 'package:http/http.dart' as http;
try {
var response = await client.get('$endpoint/users/$userId');
// Convert and return
return User.fromJson(json.decode(response.body));
} on HttpException catch (ex) {
print('http');
print(ex);
print('exception');
return null;
} on Error catch (error) {
// code will go here
print(error);
return null;
}
The result is:
I/flutter ( 3103): Invalid argument (onError): Error handler must accept one Object or one Object and a StackTrace as arguments.: Closure: (HttpException) => Null
It is exactly the same as if I didn't do any try/catch, could anyone advise how should I do the Error Handler? From my understanding (error) here should be the "one Object", please correct me if I'm wrong. TIA!