Metadata.fromJson constructor

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

convert from json (all Metadata fields)

Implementation

Metadata.fromJson(Map<String, dynamic> json) {
  pubKey = json['pubKey'] as String? ?? '';

  // Restore content and update cached known properties
  if (json['content'] != null) {
    content = Map<String, dynamic>.from(json['content'] as Map);
    _name = content['name'] as String?;
    _displayName = content['display_name'] as String?;
    _picture = content['picture'] as String?;
    _banner = content['banner'] as String?;
    _website = content['website'] as String?;
    _about = content['about'] as String?;
    try {
      _nip05 = content['nip05'] as String?;
    } catch (e) {
      // sometimes people put maps in here
    }
    _lud16 = content['lud16'] as String?;
    _lud06 = content['lud06'] as String?;
  }

  // Restore tags
  if (json['tags'] != null) {
    tags = (json['tags'] as List)
        .map((t) => (t as List).map((e) => e as String).toList())
        .toList();
  }

  refreshedTimestamp = json['refreshedTimestamp'] as int?;

  if (json['sources'] != null) {
    sources = (json['sources'] as List).map((e) => e as String).toList();
  }

  updatedAt = json['updatedAt'] as int?;
}