Olá, boa noite. Os meus erros sempre voltar a mesma coisa. Eu vi que tinha tópico aberto de alguém com o mesmo erro, tentei a solução proposta e não funcionou. Por acaso alguém passou pela mesma coisa?
I/flutter ( 8682): ----------------FIREBASE CRASHLYTICS----------------
I/flutter ( 8682): NoSuchMethodError: Class 'TimeoutException' has no instance getter 'statusCode'.
I/flutter ( 8682): Receiver: Instance of 'TimeoutException'
I/flutter ( 8682): Tried calling: statusCode
I/flutter ( 8682): ----------------------------------------------------
E/flutter ( 8682): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: Invalid argument(s) (onError): The error handler of Future.catchError must return a value of the future's type
E/flutter ( 8682): #0 _FutureListener.handleError (dart:async/future_impl.dart:181:7)
E/flutter ( 8682): #1 Future._propagateToListeners.handleError (dart:async/future_impl.dart:778:47)
E/flutter ( 8682): #2 Future._propagateToListeners (dart:async/future_impl.dart:799:13)
E/flutter ( 8682): #3 Future._completeError (dart:async/future_impl.dart:574:5)
E/flutter ( 8682): #4 _completeOnAsyncError (dart:async-patch/async_patch.dart:287:13)
E/flutter ( 8682): #5 TransactionWebClient.save (package:bytebank/database/http/webclients/transaction_webclient.dart)
E/flutter ( 8682): <asynchronous suspension>
O meu código _send:
Future<Transaction> _send(Transaction transactionCreated, String password,
BuildContext context) async {
setState(() {
_sending = true;
});
final Transaction transaction =
await _webClient.save(transactionCreated, password).catchError((e) {
FirebaseCrashlytics.instance.setCustomKey('exception', e.toString());
FirebaseCrashlytics.instance
.setCustomKey('http_body', transactionCreated.toString());
FirebaseCrashlytics.instance.recordError(e, null);
_showFailureMessage(context, message: e.message);
}, test: (e) => e is HttpException).catchError((e) {
FirebaseCrashlytics.instance.setCustomKey('exception', e.toString());
FirebaseCrashlytics.instance.setCustomKey('http_code', e.statusCode);
FirebaseCrashlytics.instance
.setCustomKey('http_body', transactionCreated.toString());
FirebaseCrashlytics.instance.recordError(e, null);
_showFailureMessage(context,
message: 'timeout submitting the transaction');
}, test: (e) => e is TimeoutException).catchError((e) {
FirebaseCrashlytics.instance.setCustomKey('exception', e.toString());
FirebaseCrashlytics.instance
.setCustomKey('http_body', transactionCreated.toString());
FirebaseCrashlytics.instance.recordError(e, null);
_showFailureMessage(context);
}).whenComplete(() {
setState(() {
_sending = false;
});
});
return transaction;
}
O código do meu TransactionWebClient:
class TransactionWebClient {
Future<List<Transaction>> findAll() async {
final Response response = await client.get(Uri.parse(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(Uri.parse(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), response.statusCode);
}
String? _getMessage(int statusCode) {
if (_statusCodeResponses.containsKey(statusCode)) {
return _statusCodeResponses[statusCode];
}
return 'unknown error';
}
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;
final int? statusCode;
HttpException(this.message, this.statusCode);
}