From 78179f14b5d057a3480ca53789f5f635ac42ac3c Mon Sep 17 00:00:00 2001 From: Nutcake Date: Mon, 15 May 2023 11:58:03 +0200 Subject: [PATCH] Fix some issues with parsing user profiles --- lib/models/personal_profile.dart | 14 +++++++------- lib/models/user_profile.dart | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/models/personal_profile.dart b/lib/models/personal_profile.dart index 443a661..be4f4c7 100644 --- a/lib/models/personal_profile.dart +++ b/lib/models/personal_profile.dart @@ -22,23 +22,23 @@ class PersonalProfile { }); factory PersonalProfile.fromMap(Map map) { - final banExp = map["publicBanExpiration"]; return PersonalProfile( - id: map["id"], - username: map["username"], - email: map["email"], - publicBanExpiration: banExp == null ? null : DateTime.parse(banExp), + id: map["id"] ?? "", + username: map["username"] ?? "", + email: map["email"] ?? "", + publicBanExpiration: DateTime.tryParse(map["publicBanExpiration"] ?? ""), publicBanType: map["publicBanType"], storageQuotas: (map["storageQuotas"] as List).map((e) => StorageQuotas.fromMap(e)).toList(), quotaBytesSource: (map["quotaBytesSources"] as Map).map((key, value) => MapEntry(key, value as int)), - usedBytes: map["usedBytes"], + usedBytes: map["usedBytes"] ?? 0, twoFactor: map["2fa_login"] ?? false, isPatreonSupporter: map["patreonData"]?["isPatreonSupporter"] ?? false, userProfile: UserProfile.fromMap(map["profile"]), ); } - int get maxBytes => (quotaBytesSource.values.maxOrNull ?? 0) + storageQuotas.map((e) => e.bytes).reduce((value, element) => value + element); + int get maxBytes => (quotaBytesSource.values.maxOrNull ?? 0) + + (storageQuotas.isEmpty ? 0 : storageQuotas.map((e) => e.bytes).reduce((value, element) => value + element)); } class StorageQuotas { diff --git a/lib/models/user_profile.dart b/lib/models/user_profile.dart index e0b645a..f78504a 100644 --- a/lib/models/user_profile.dart +++ b/lib/models/user_profile.dart @@ -5,8 +5,8 @@ class UserProfile { factory UserProfile.empty() => UserProfile(iconUrl: ""); - factory UserProfile.fromMap(Map map) { - return UserProfile(iconUrl: map["iconUrl"] ?? ""); + factory UserProfile.fromMap(Map? map) { + return UserProfile(iconUrl: map?["iconUrl"] ?? ""); } Map toMap() {