我可以从 get 请求接收数据,但数据没有显示。我不知道为什么我收到这个错误。是因为我转换 JSON 文件的方式还是我比较日期的方式。有什么方法可以将数据JSON文件转换为对象列表? 错误
I/flutter ( 5931): Exception: NoSuchMethodError: Class 'String' has no instance method 'toInt'.
I/flutter ( 5931): Receiver: "2020-01-31"
I/flutter ( 5931): Tried calling: toInt()
class Transaction {
final String to;
final DateTime date;
final String amount;
final String category;
Transaction({this.to, this.date, this.amount, this.category});
factory Transaction.fromJson(Map<dynamic, dynamic> json) {
return Transaction(
to: json["to"] as String,
date: json['date'],
amount: json["amount"] as String,
category: json["category"] as String);
}
}```
This block is in a function to compare date with a range of date
```if (t.millisecondsSinceEpoch >= from.millisecondsSinceEpoch && t.millisecondsSinceEpoch <= to.millisecondsSinceEpoch){
trans.add(trans[i]); }```
A function that will convert a response body into a List<Transaction>
```List<Transaction> parseDataBudget(String responseBody) {
final parsed = json.decode(responseBody).cast<Map<String, dynamic>>();
return parsed.map<Transaction>((json) => new Transaction.fromJson(json)).toList();}```