Talvez eu tenha escrito algum código errado e não percebi. Sempre aparece o Unknown error antes de aparecer outro erro. Por exemplo, Unknown error aparece antes de Authentication failed:
Código do transaction_webclient:
class TransactionWebClient {
Future<List<Transaction>> findAll() async {
final Response response = await get(baseUrl);
final List<dynamic> decodedJson = jsonDecode(response.body);
return decodedJson
.map((dynamic json) => Transaction.fromJson(json))
.toList();
}
Future<Transaction> save(Transaction transaction, String password) async {
final String transactionJson = jsonEncode(transaction.toJson());
await Future.delayed(Duration(seconds: 2));
final Response response = await client.post(baseUrl,
headers: {'Content-type': 'application/json', 'password': password},
body: transactionJson);
if(response.statusCode == 200) {
return Transaction.fromJson(jsonDecode(response.body));
}
throw HttpException(_getMessage(response.statusCode));
}
String? _getMessage(int statusCode) {
if(_statusCodeResponses.containsKey(statusCode)){
return _statusCodeResponses[statusCode];
}
return 'Unknown eror.';
}
static final Map<int, String> _statusCodeResponses = {
400 :'There was an error submitting transaction.',
401 : 'Authentication failed!',
409: 'Transaction already exists.'
};
}
class HttpException implements Exception {
final String? message;
HttpException(this.message);
}