Account.fromJson constructor

Account.fromJson(
  1. Map<String, dynamic> json
)

Deserializes the specified Json into an object of the Account object. This account object may include a list of Mechanism

Implementation

factory Account.fromJson(Map<String, dynamic> json) {
  Account account = Account(
      json['id'],
      json['issuer'],
      json['displayIssuer'],
      json['accountName'],
      json['displayAccountName'],
      json['imageURL'] == 'null' ? null : json['imageURL'],
      json['backgroundColor'] == 'null' ? null : json['backgroundColor'],
      json['timeAdded']);

  if (json['mechanismList'] != null) {
    List? toParseList;
    if (json['mechanismList'] is String) {
      toParseList = jsonDecode(json['mechanismList']);
    } else {
      toParseList = json['mechanismList'];
    }

    List<Mechanism> mechanismList = [];
    for (final element in toParseList!) {
      if (element is String) {
        mechanismList.add(Mechanism.fromJson(jsonDecode(element), account));
      } else if (element is Map<String, dynamic>) {
        mechanismList.add(Mechanism.fromJson(element, account));
      } else {
        var tmp = Map<String, dynamic>.from(element);
        mechanismList.add(Mechanism.fromJson(tmp, account));
      }
    }
    account.mechanismList = mechanismList;
  }

  return account;
}