2
respostas

unhandled exception: invalid argument(s) (onerror): the error handler of future.catcherror must return a value of the future's type

Substituindo o then por await incluindo os catchErro acontece o erro =unhandled exception: invalid argument(s) (onerror): the error handler of future.catcherror must return a value of the future's type. Versão do flutter 2.5.1

Metodo abaixo criado no curso de "Comunicação HTTP: Flutter com web API"

Future _send(Transaction transactionCreated, String password, BuildContext context) async { final Transaction transaction = await _client.save(transactionCreated, password).catchError((e) { _showFailureMessage(context, message: e.message); }, test: (e) => e is HttpException).catchError((e) { _showFailureMessage(context, message: 'timeout submittring the transaction'); }, test: (e) => e is TimeoutException).catchError((e) { _showFailureMessage(context); }, test: (e) => e is Exception);

return transaction;

}

Qual seria a solução para corrigir esse erro?

2 respostas

Estou com o mesmo problema e gostaria de saber a solução, já descobriu?

A documentação do Dart recomenda colocar a chamada do método dentro de um try-catch ao invés de usar o onError quando usando async-await (https://dart.dev/codelabs/async-await) :

Exemplo:

try {
  print('Awaiting user order...');
  var order = await fetchUserOrder();
} catch (err) {
  print('Caught error: $err');
}

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software