Aqui esta a classe, em um primeiro momento, ele descreve que no return da _getMessage, precisa declarar que pode receber um null, quando voce declara, da forma que esta na classe abaixo, ele aparece esse erro! Alguem me da um ajuda?
import 'dart:convert';
import 'package:bytebank/http/webclient.dart';
import 'package:bytebank/models/transaction.dart';
import 'package:http/http.dart';
class TransactionWebClient {
Future<List<Transaction>> findAll() async {
final Response response =
await client.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 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;
HttpException(this.message);
}