feat: rework personal_profile model + start testing new layouts for My Profile dialog
This commit is contained in:
parent
02f3514ad3
commit
85a3d65d23
3 changed files with 85 additions and 21 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:recon/auxiliary.dart';
|
import 'package:recon/auxiliary.dart';
|
||||||
import 'package:recon/models/users/entitlement.dart';
|
import 'package:recon/models/users/entitlement.dart';
|
||||||
import 'package:recon/models/users/user_profile.dart';
|
import 'package:recon/models/users/user_profile.dart';
|
||||||
|
@ -9,6 +10,7 @@ class PersonalProfile {
|
||||||
final DateTime? publicBanExpiration;
|
final DateTime? publicBanExpiration;
|
||||||
final String? publicBanType;
|
final String? publicBanType;
|
||||||
final bool twoFactor;
|
final bool twoFactor;
|
||||||
|
final List<String> tags;
|
||||||
final UserProfile userProfile;
|
final UserProfile userProfile;
|
||||||
final List<Entitlement> entitlements;
|
final List<Entitlement> entitlements;
|
||||||
final List<SupporterMetadata> supporterMetadata;
|
final List<SupporterMetadata> supporterMetadata;
|
||||||
|
@ -20,6 +22,7 @@ class PersonalProfile {
|
||||||
required this.publicBanExpiration,
|
required this.publicBanExpiration,
|
||||||
required this.publicBanType,
|
required this.publicBanType,
|
||||||
required this.twoFactor,
|
required this.twoFactor,
|
||||||
|
required this.tags,
|
||||||
required this.userProfile,
|
required this.userProfile,
|
||||||
required this.entitlements,
|
required this.entitlements,
|
||||||
required this.supporterMetadata,
|
required this.supporterMetadata,
|
||||||
|
@ -33,6 +36,7 @@ class PersonalProfile {
|
||||||
publicBanExpiration: DateTime.tryParse(map["publicBanExpiration"] ?? ""),
|
publicBanExpiration: DateTime.tryParse(map["publicBanExpiration"] ?? ""),
|
||||||
publicBanType: map["publicBanType"],
|
publicBanType: map["publicBanType"],
|
||||||
twoFactor: map["2fa_login"] ?? false,
|
twoFactor: map["2fa_login"] ?? false,
|
||||||
|
tags: (map["tags"] ?? []).cast<String>(),
|
||||||
userProfile: UserProfile.fromMap(map["profile"]),
|
userProfile: UserProfile.fromMap(map["profile"]),
|
||||||
entitlements: ((map["entitlements"] ?? []) as List).map((e) => Entitlement.fromMap(e)).toList(),
|
entitlements: ((map["entitlements"] ?? []) as List).map((e) => Entitlement.fromMap(e)).toList(),
|
||||||
supporterMetadata: ((map["supporterMetadata"] ?? []) as List).map((e) => SupporterMetadata.fromMap(e)).toList(),
|
supporterMetadata: ((map["supporterMetadata"] ?? []) as List).map((e) => SupporterMetadata.fromMap(e)).toList(),
|
||||||
|
@ -41,6 +45,34 @@ class PersonalProfile {
|
||||||
|
|
||||||
bool get isPatreonSupporter =>
|
bool get isPatreonSupporter =>
|
||||||
supporterMetadata.whereType<PatreonSupporter>().any((element) => element.isActiveSupporter);
|
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 {
|
class StorageQuota {
|
||||||
|
|
|
@ -1,17 +1,38 @@
|
||||||
class UserProfile {
|
class UserProfile {
|
||||||
final String iconUrl;
|
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) {
|
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() {
|
Map toMap() {
|
||||||
return {
|
return {
|
||||||
"iconUrl": iconUrl,
|
"iconUrl": iconUrl,
|
||||||
|
"tagline": tagline,
|
||||||
|
"description": description,
|
||||||
|
"displayBadges": displayBadges,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,24 +48,25 @@ class _MyProfileDialogState extends State<MyProfileDialog> {
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.end,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
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(
|
GenericAvatar(
|
||||||
imageUri: Aux.resdbToHttp(profile.userProfile.iconUrl),
|
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(
|
const SizedBox(
|
||||||
|
@ -85,10 +86,10 @@ class _MyProfileDialogState extends State<MyProfileDialog> {
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
"2FA: ",
|
"Email: ",
|
||||||
style: tt.labelLarge,
|
style: tt.labelLarge,
|
||||||
),
|
),
|
||||||
Text(profile.twoFactor ? "Enabled" : "Disabled")
|
Text(profile.email)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Row(
|
Row(
|
||||||
|
@ -101,6 +102,16 @@ class _MyProfileDialogState extends State<MyProfileDialog> {
|
||||||
Text(profile.isPatreonSupporter ? "Yes" : "No")
|
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)
|
if (profile.publicBanExpiration?.isAfter(DateTime.now()) ?? false)
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
|
Loading…
Reference in a new issue