我如何在颤振中访问对象中的值

时间:2021-07-21 03:11:54

标签: flutter dart

`当我尝试从快照打印响应时,我得到一个对象的实例。

Shows a future builder and a future property using a provider

instance of Deposit

如何访问对象内部的值?

这是存款中的代码示例

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'],
    );
  }
}

1 个答案:

答案 0 :(得分:0)

使用snapshot.data.xxx

xxx 代表对象内部的值。

既然你已经为事务分配了snapshot.data,你可以通过调用transaction.xxx来获取对象值。