flutter - 我如何在颤动中访问对象中的值
问题描述
`当我尝试打印来自快照的响应时,我得到了一个对象的实例。
如何访问对象内部的值?
这是存款中的代码示例
class Deposit {
String id;
String merchantId;
String accountId;
int amount;
bool ismarkedasPaid;
String paidAt;
String completedAt;
String status;
String createdAt;
String updatedAt;
Deposit(
{this.accountId,
this.merchantId,
this.amount,
this.completedAt,
this.createdAt,
this.ismarkedasPaid,
this.updatedAt,
this.paidAt,
this.status,
this.id});
factory Deposit.fromJson(Map<String, dynamic> json) {
return Deposit(
id: json['id'],
merchantId: json['merchant_id'],
accountId: json['account_id'],
amount: json['amount'],
ismarkedasPaid: json['is_marked_as_paid'],
paidAt: json['paid_at'],
completedAt: json['completed_at'],
status: json['completed'],
createdAt: json['created_at'],
updatedAt: json['updated_at'],
);
}
}
解决方案
利用snapshot.data.xxx
xxx
表示对象内部的值。
由于您已将 snapshot.data 分配给事务,因此您可以通过调用transaction.xxx
.
推荐阅读
- c# - How do I get data from a POST request on Nancy 2.0?
- java - 错误:类 X 是公共的,应在名为 X 的文件中声明
- javascript - 函数初始化位置之间的性能差异 [JavaScript]
- javascript - Javascript getter/setter 范围访问
- python - 如何在 Python 中使用并行处理过滤器?
- azure - Azure 命令行工具,无法导入 `cygrpc`
- excel - INDEX returns wrong value and no value
- javascript - setLocation should take two parameters, singlePerson and city. It should set a location property on the person to the city
- javascript - 在客户端的另一个变量上存储返回 JSON 数据时遇到问题
- sockets - Boost socket async_send:它如何处理 ewilldblock?