Após fazer as alterações no código mostradas no vídeo, meu Transaction feed não mostra mais nada, mas ao abrir no navegador todas as transações estão lá. E as transferências novas também não estão funcionando.
transaction_webclient.dart
class TransactionWebClient {
Future<List<Transaction>> findAll() async {
final Response response = await get(baseUrl).timeout(Duration(seconds: 5));
List<Transaction> transactions = _toTransactions(response);
return transactions;
}
Future<Transaction> save(Transaction transaction) async {
final String transactionJson = jsonEncode(transaction.toJson());
final Response response = await client.post(baseUrl,
headers: {'Content-type': 'application/json', 'password': '1000'},
body: transactionJson);
return _toTransaction(response);
}
List<Transaction> _toTransactions(Response response) {
final List<dynamic> decodedJson = jsonDecode(response.body);
final List<Transaction> transactions = [];
for (Map<String, dynamic> transactionJson in decodedJson) {
transactions.add(Transaction.fromJson(transactionJson));
}
return transactions;
}
Transaction _toTransaction(Response response) {
Map<String, dynamic> json = jsonDecode(response.body);
return Transaction.fromJson(json);
}
}
transaction.dart
class Transaction {
final double value;
final Contact contact;
Transaction(
this.value,
this.contact,
);
Transaction.fromJson(Map<String, dynamic> json) :
value = json['value'],
contact = Contact.fromJson(json['contact']);
Map<String, dynamic> toJson() =>
{
'value': value,
'contact': contact.toJson(),
};
@override
String toString() {
return 'Transaction{value: $value, contact: $contact}';
}
}
contact.dart
class Contact {
final int id;
final String name;
final int? accountNumber;
Contact(this.id, this.name, this.accountNumber);
@override
String toString() {
return 'Contact{id: $id, name: $name, accountNumber: $accountNumber}';
}
Contact.fromJson(Map<String, dynamic> json)
: id = json['id'],
name = json['name'],
accountNumber = json['accountNumber'];
Map<String, dynamic> toJson() => {
'name': name,
'accountNumber': accountNumber,
};
}