fromJson static method

MyAccountDetails? fromJson(
  1. dynamic value
)

Returns a new MyAccountDetails instance and imports its values from value if it's a Map, null otherwise.

Implementation

// ignore: prefer_constructors_over_static_methods
static MyAccountDetails? fromJson(dynamic value) {
  if (value is Map) {
    final json = value.cast<String, dynamic>();

    // Ensure that the map contains the required keys.
    // Note 1: the values aren't checked for validity beyond being non-null.
    // Note 2: this code is stripped in release mode!
    assert(() {
      assert(json.containsKey(r'username'),
          'Required key "MyAccountDetails[username]" is missing from JSON.');
      assert(json[r'username'] != null,
          'Required key "MyAccountDetails[username]" has a null value in JSON.');
      assert(json.containsKey(r'email'),
          'Required key "MyAccountDetails[email]" is missing from JSON.');
      assert(json[r'email'] != null,
          'Required key "MyAccountDetails[email]" has a null value in JSON.');
      assert(json.containsKey(r'member'),
          'Required key "MyAccountDetails[member]" is missing from JSON.');
      assert(json[r'member'] != null,
          'Required key "MyAccountDetails[member]" has a null value in JSON.');
      assert(json.containsKey(r'status'),
          'Required key "MyAccountDetails[status]" is missing from JSON.');
      assert(json[r'status'] != null,
          'Required key "MyAccountDetails[status]" has a null value in JSON.');
      assert(json.containsKey(r'skins'),
          'Required key "MyAccountDetails[skins]" is missing from JSON.');
      assert(json[r'skins'] != null,
          'Required key "MyAccountDetails[skins]" has a null value in JSON.');
      assert(json.containsKey(r'gems'),
          'Required key "MyAccountDetails[gems]" is missing from JSON.');
      assert(json[r'gems'] != null,
          'Required key "MyAccountDetails[gems]" has a null value in JSON.');
      assert(json.containsKey(r'achievements_points'),
          'Required key "MyAccountDetails[achievements_points]" is missing from JSON.');
      assert(json[r'achievements_points'] != null,
          'Required key "MyAccountDetails[achievements_points]" has a null value in JSON.');
      assert(json.containsKey(r'banned'),
          'Required key "MyAccountDetails[banned]" is missing from JSON.');
      assert(json[r'banned'] != null,
          'Required key "MyAccountDetails[banned]" has a null value in JSON.');
      return true;
    }());

    return MyAccountDetails(
      username: mapValueOfType<String>(json, r'username')!,
      email: mapValueOfType<String>(json, r'email')!,
      member: mapValueOfType<bool>(json, r'member')!,
      memberExpiration: mapDateTime(json, r'member_expiration', r''),
      status: AccountStatus.fromJson(json[r'status'])!,
      badges: json[r'badges'] is Iterable
          ? (json[r'badges'] as Iterable)
              .cast<String>()
              .toList(growable: false)
          : const [],
      skins: json[r'skins'] is Iterable
          ? (json[r'skins'] as Iterable)
              .cast<String>()
              .toList(growable: false)
          : const [],
      gems: mapValueOfType<int>(json, r'gems')!,
      memberToken: mapValueOfType<int>(json, r'member_token') ?? 0,
      achievementsPoints: mapValueOfType<int>(json, r'achievements_points')!,
      banned: mapValueOfType<bool>(json, r'banned')!,
      banReason: mapValueOfType<String>(json, r'ban_reason'),
    );
  }
  return null;
}