首页 > 解决方案 > 我如何在颤动中访问对象中的值

问题描述

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

使用提供者显示未来的建设者和未来的财产

存款实例

如何访问对象内部的值?

这是存款中的代码示例

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

标签: flutterdart

解决方案


利用snapshot.data.xxx

xxx表示对象内部的值。

由于您已将 snapshot.data 分配给事务,因此您可以通过调用transaction.xxx.


推荐阅读