feat: rework personal_profile model + start testing new layouts for My Profile dialog

This commit is contained in:
Garrett Watson 2024-02-15 15:10:25 -05:00
parent 02f3514ad3
commit 85a3d65d23
3 changed files with 85 additions and 21 deletions

View file

@ -1,3 +1,4 @@
import 'package:flutter/material.dart';
import 'package:recon/auxiliary.dart';
import 'package:recon/models/users/entitlement.dart';
import 'package:recon/models/users/user_profile.dart';
@ -9,6 +10,7 @@ class PersonalProfile {
final DateTime? publicBanExpiration;
final String? publicBanType;
final bool twoFactor;
final List<String> tags;
final UserProfile userProfile;
final List<Entitlement> entitlements;
final List<SupporterMetadata> supporterMetadata;
@ -20,6 +22,7 @@ class PersonalProfile {
required this.publicBanExpiration,
required this.publicBanType,
required this.twoFactor,
required this.tags,
required this.userProfile,
required this.entitlements,
required this.supporterMetadata,
@ -33,6 +36,7 @@ class PersonalProfile {
publicBanExpiration: DateTime.tryParse(map["publicBanExpiration"] ?? ""),
publicBanType: map["publicBanType"],
twoFactor: map["2fa_login"] ?? false,
tags: (map["tags"] ?? []).cast<String>(),
userProfile: UserProfile.fromMap(map["profile"]),
entitlements: ((map["entitlements"] ?? []) as List).map((e) => Entitlement.fromMap(e)).toList(),
supporterMetadata: ((map["supporterMetadata"] ?? []) as List).map((e) => SupporterMetadata.fromMap(e)).toList(),
@ -41,6 +45,34 @@ class PersonalProfile {
bool get isPatreonSupporter =>
supporterMetadata.whereType<PatreonSupporter>().any((element) => element.isActiveSupporter);
static final List<AccountType> accountTypes = [
AccountType(label: "Standard Account", color: const Color(0xFF86888B)),
AccountType(label: "Patreon Supporter", color: const Color(0xFFFF7676)),
AccountType(label: "Resonite Mentor", color: const Color(0xFF59EB5C)),
AccountType(label: "Resonite Moderator", color: const Color(0xFF61D1FA)),
AccountType(label: "Resonite Team", color: const Color.fromARGB(255, 255, 230, 0)),
];
AccountType get accountType => tags.contains("team member")
? accountTypes[4]
: tags.contains("moderator")
? accountTypes[3]
: tags.contains("mentor")
? accountTypes[2]
: isPatreonSupporter
? accountTypes[1]
: accountTypes[0];
}
class AccountType {
final String label;
final Color color;
AccountType({
required this.label,
required this.color,
});
}
class StorageQuota {

View file

@ -1,17 +1,38 @@
class UserProfile {
final String iconUrl;
final String tagline;
final String description;
final List<String> displayBadges;
UserProfile({required this.iconUrl});
UserProfile({
required this.iconUrl,
required this.tagline,
required this.description,
required this.displayBadges,
});
factory UserProfile.empty() => UserProfile(iconUrl: "");
factory UserProfile.empty() => UserProfile(
iconUrl: "",
tagline: "",
description: "",
displayBadges: [],
);
factory UserProfile.fromMap(Map? map) {
return UserProfile(iconUrl: map?["iconUrl"] ?? "");
return UserProfile(
iconUrl: map?["iconUrl"] ?? "",
tagline: map?["tagline"] ?? "",
description: map?["description"] ?? "",
displayBadges: map?["displayBadges"]?.cast<String>() ?? [],
);
}
Map toMap() {
return {
"iconUrl": iconUrl,
"tagline": tagline,
"description": description,
"displayBadges": displayBadges,
};
}
}

View file

@ -48,24 +48,25 @@ class _MyProfileDialogState extends State<MyProfileDialog> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(profile.username, style: tt.titleLarge),
Text(
profile.email,
style:
tt.labelMedium?.copyWith(color: Theme.of(context).colorScheme.onSurface.withAlpha(150)),
)
],
),
GenericAvatar(
imageUri: Aux.resdbToHttp(profile.userProfile.iconUrl),
radius: 24,
)
radius: 32,
),
Padding(
padding: const EdgeInsets.only(left: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(profile.username, style: tt.titleLarge),
Text(
profile.accountType.label,
style: tt.labelMedium?.copyWith(color: profile.accountType.color),
),
],
)),
],
),
const SizedBox(
@ -85,10 +86,10 @@ class _MyProfileDialogState extends State<MyProfileDialog> {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"2FA: ",
"Email: ",
style: tt.labelLarge,
),
Text(profile.twoFactor ? "Enabled" : "Disabled")
Text(profile.email)
],
),
Row(
@ -101,6 +102,16 @@ class _MyProfileDialogState extends State<MyProfileDialog> {
Text(profile.isPatreonSupporter ? "Yes" : "No")
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"2FA: ",
style: tt.labelLarge,
),
Text(profile.twoFactor ? "Enabled" : "Disabled")
],
),
if (profile.publicBanExpiration?.isAfter(DateTime.now()) ?? false)
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,