2024-01-27 10:55:55 -04:00
|
|
|
import 'package:flutter/material.dart';
|
2024-03-09 00:03:46 -04:00
|
|
|
import 'package:flutter/services.dart';
|
2024-01-27 10:55:55 -04:00
|
|
|
import 'package:intl/intl.dart';
|
2023-10-03 13:00:59 -04:00
|
|
|
import 'package:recon/apis/user_api.dart';
|
|
|
|
import 'package:recon/auxiliary.dart';
|
|
|
|
import 'package:recon/client_holder.dart';
|
|
|
|
import 'package:recon/models/personal_profile.dart';
|
2024-03-09 00:03:46 -04:00
|
|
|
import 'package:recon/widgets/blend_mask.dart';
|
2023-10-03 13:00:59 -04:00
|
|
|
import 'package:recon/widgets/default_error_widget.dart';
|
|
|
|
import 'package:recon/widgets/generic_avatar.dart';
|
2023-05-05 09:05:06 -04:00
|
|
|
|
2023-05-17 02:10:52 -04:00
|
|
|
class MyProfileDialog extends StatefulWidget {
|
|
|
|
const MyProfileDialog({super.key});
|
2023-05-05 09:05:06 -04:00
|
|
|
|
2023-05-17 02:10:52 -04:00
|
|
|
@override
|
|
|
|
State<MyProfileDialog> createState() => _MyProfileDialogState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _MyProfileDialogState extends State<MyProfileDialog> {
|
|
|
|
ClientHolder? _clientHolder;
|
|
|
|
Future<PersonalProfile>? _personalProfileFuture;
|
2023-10-10 04:33:51 -04:00
|
|
|
Future<StorageQuota>? _storageQuotaFuture;
|
2023-05-17 02:10:52 -04:00
|
|
|
|
|
|
|
@override
|
|
|
|
void didChangeDependencies() async {
|
|
|
|
super.didChangeDependencies();
|
|
|
|
final clientHolder = ClientHolder.of(context);
|
|
|
|
if (_clientHolder != clientHolder) {
|
|
|
|
_clientHolder = clientHolder;
|
|
|
|
final apiClient = _clientHolder!.apiClient;
|
|
|
|
_personalProfileFuture = UserApi.getPersonalProfile(apiClient);
|
2023-10-10 04:33:51 -04:00
|
|
|
_storageQuotaFuture = UserApi.getStorageQuota(apiClient);
|
2023-05-17 02:10:52 -04:00
|
|
|
}
|
|
|
|
}
|
2023-05-05 09:05:06 -04:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-02-16 11:39:59 -04:00
|
|
|
final textTheme = Theme.of(context).textTheme;
|
2023-05-05 09:05:06 -04:00
|
|
|
DateFormat dateFormat = DateFormat.yMd();
|
|
|
|
return Dialog(
|
2024-02-16 11:39:59 -04:00
|
|
|
clipBehavior: Clip.antiAlias,
|
|
|
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
|
|
|
backgroundColor: const Color(0xFF11151D),
|
2023-05-17 02:10:52 -04:00
|
|
|
child: FutureBuilder(
|
|
|
|
future: _personalProfileFuture,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (snapshot.hasData) {
|
|
|
|
final profile = snapshot.data as PersonalProfile;
|
|
|
|
return Padding(
|
2024-02-16 11:39:59 -04:00
|
|
|
padding: const EdgeInsets.only(bottom: 16),
|
2023-05-17 02:10:52 -04:00
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2024-02-16 11:39:59 -04:00
|
|
|
Container(
|
|
|
|
padding: const EdgeInsets.all(16),
|
|
|
|
decoration: const BoxDecoration(
|
|
|
|
color: Color(0x6611151D),
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
GenericAvatar(
|
|
|
|
imageUri: Aux.resdbToHttp(profile.userProfile.iconUrl),
|
|
|
|
radius: 32,
|
|
|
|
),
|
2024-02-23 17:34:22 -04:00
|
|
|
const SizedBox(
|
|
|
|
width: 12,
|
|
|
|
),
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(profile.username, style: textTheme.titleLarge),
|
|
|
|
Text(
|
|
|
|
profile.accountType.label,
|
|
|
|
style: textTheme.labelMedium?.copyWith(color: profile.accountType.color),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2024-02-16 11:39:59 -04:00
|
|
|
],
|
|
|
|
),
|
2023-05-17 02:10:52 -04:00
|
|
|
),
|
2024-01-27 10:55:55 -04:00
|
|
|
const SizedBox(
|
2024-02-16 11:39:59 -04:00
|
|
|
height: 12,
|
2023-05-17 02:10:52 -04:00
|
|
|
),
|
2024-02-16 11:39:59 -04:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Account Info",
|
|
|
|
style: textTheme.titleMedium,
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 8,
|
|
|
|
),
|
|
|
|
ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
|
|
|
child: Container(
|
|
|
|
width: double.infinity,
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
|
|
color: const Color(0x6611151D),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.start,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2024-03-09 00:03:46 -04:00
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
2024-02-16 11:39:59 -04:00
|
|
|
children: [
|
2024-03-09 00:03:46 -04:00
|
|
|
Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"User ID",
|
|
|
|
style: textTheme.titleSmall,
|
|
|
|
),
|
|
|
|
Text(profile.id,
|
|
|
|
style: textTheme.bodySmall?.copyWith(color: const Color(0xFFE1E1E0)))
|
|
|
|
],
|
2024-02-16 11:39:59 -04:00
|
|
|
),
|
2024-03-09 00:03:46 -04:00
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
Clipboard.setData(ClipboardData(text: profile.id));
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
|
|
|
content: Text("User ID copied to clipboard"),
|
|
|
|
behavior: SnackBarBehavior.floating));
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.copy_outlined))
|
2024-02-16 11:39:59 -04:00
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 8,
|
|
|
|
),
|
2024-03-09 00:03:46 -04:00
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
2024-02-16 11:39:59 -04:00
|
|
|
children: [
|
2024-03-09 00:03:46 -04:00
|
|
|
Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Email",
|
|
|
|
style: textTheme.titleSmall,
|
|
|
|
),
|
|
|
|
Text(profile.email,
|
|
|
|
style: textTheme.bodySmall?.copyWith(color: const Color(0xFFE1E1E0)))
|
|
|
|
],
|
2024-02-16 11:39:59 -04:00
|
|
|
),
|
2024-03-09 00:03:46 -04:00
|
|
|
IconButton(
|
|
|
|
onPressed: () {
|
|
|
|
Clipboard.setData(ClipboardData(text: profile.email));
|
|
|
|
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
|
|
|
|
content: Text("Email copied to clipboard"),
|
|
|
|
behavior: SnackBarBehavior.floating));
|
|
|
|
},
|
|
|
|
icon: const Icon(Icons.copy_outlined))
|
2024-02-16 11:39:59 -04:00
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 8,
|
|
|
|
),
|
|
|
|
Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Patreon Supporter",
|
|
|
|
style: textTheme.titleSmall,
|
|
|
|
),
|
|
|
|
Text(profile.isPatreonSupporter ? "Yes" : "No",
|
|
|
|
style: textTheme.bodySmall?.copyWith(color: const Color(0xFFE1E1E0)))
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(
|
|
|
|
height: 8,
|
|
|
|
),
|
|
|
|
Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Two Factor Authentication",
|
|
|
|
style: textTheme.titleSmall,
|
|
|
|
),
|
|
|
|
Text(profile.twoFactor ? "Enabled" : "Disabled",
|
|
|
|
style: textTheme.bodySmall?.copyWith(color: const Color(0xFFE1E1E0)))
|
|
|
|
],
|
|
|
|
),
|
|
|
|
])),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2024-02-15 16:10:25 -04:00
|
|
|
),
|
2023-05-17 02:10:52 -04:00
|
|
|
if (profile.publicBanExpiration?.isAfter(DateTime.now()) ?? false)
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
2024-01-27 10:55:55 -04:00
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"Ban Expiration: ",
|
2024-02-16 11:39:59 -04:00
|
|
|
style: textTheme.labelLarge,
|
2024-01-27 10:55:55 -04:00
|
|
|
),
|
|
|
|
Text(dateFormat.format(profile.publicBanExpiration!))
|
|
|
|
],
|
2023-05-17 02:10:52 -04:00
|
|
|
),
|
2024-02-16 11:39:59 -04:00
|
|
|
const SizedBox(
|
|
|
|
height: 12,
|
|
|
|
),
|
2023-10-10 04:33:51 -04:00
|
|
|
FutureBuilder(
|
2024-01-27 10:55:55 -04:00
|
|
|
future: _storageQuotaFuture,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
final storage = snapshot.data;
|
|
|
|
return StorageIndicator(
|
|
|
|
usedBytes: storage?.usedBytes ?? 0,
|
|
|
|
maxBytes: storage?.fullQuotaBytes ?? 1,
|
|
|
|
);
|
|
|
|
}),
|
2023-05-17 02:10:52 -04:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
2024-01-27 10:55:55 -04:00
|
|
|
} else if (snapshot.hasError) {
|
2023-05-17 02:10:52 -04:00
|
|
|
return Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
DefaultErrorWidget(
|
|
|
|
message: snapshot.error.toString(),
|
|
|
|
onRetry: () {
|
|
|
|
setState(() {
|
2024-01-27 10:55:55 -04:00
|
|
|
_personalProfileFuture = UserApi.getPersonalProfile(ClientHolder.of(context).apiClient);
|
2023-05-17 02:10:52 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return const Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
2023-05-05 09:05:06 -04:00
|
|
|
children: [
|
2023-05-17 02:10:52 -04:00
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.symmetric(vertical: 96, horizontal: 64),
|
|
|
|
child: CircularProgressIndicator(),
|
2023-05-05 09:05:06 -04:00
|
|
|
),
|
|
|
|
],
|
2023-05-17 02:10:52 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2023-05-05 09:05:06 -04:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class StorageIndicator extends StatelessWidget {
|
|
|
|
const StorageIndicator({required this.usedBytes, required this.maxBytes, super.key});
|
|
|
|
|
|
|
|
final int usedBytes;
|
|
|
|
final int maxBytes;
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-01-27 10:55:55 -04:00
|
|
|
final value = usedBytes / maxBytes;
|
2023-05-05 09:05:06 -04:00
|
|
|
return Padding(
|
2024-02-16 11:39:59 -04:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
2023-05-05 09:05:06 -04:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2024-02-16 11:39:59 -04:00
|
|
|
Text("Storage", style: Theme.of(context).textTheme.titleMedium),
|
2024-01-27 10:55:55 -04:00
|
|
|
const SizedBox(
|
|
|
|
height: 8,
|
|
|
|
),
|
2023-05-05 09:05:06 -04:00
|
|
|
ClipRRect(
|
|
|
|
borderRadius: BorderRadius.circular(8),
|
2024-02-16 11:39:59 -04:00
|
|
|
child: Stack(children: [
|
|
|
|
LinearProgressIndicator(
|
|
|
|
value: value,
|
|
|
|
minHeight: 48,
|
|
|
|
color: value > 0.95 ? Theme.of(context).colorScheme.error : const Color(0xFF61D1FA),
|
|
|
|
backgroundColor: const Color(0xFF284C5D),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
height: 48,
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
|
|
|
alignment: Alignment.center,
|
2024-02-23 17:34:22 -04:00
|
|
|
child: BlendMask(
|
2024-03-09 00:03:46 -04:00
|
|
|
blendMode: BlendMode.srcATop,
|
2024-02-23 17:34:22 -04:00
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
"${(value * 100).toStringAsFixed(0)}%",
|
|
|
|
style: Theme.of(context).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold),
|
|
|
|
),
|
|
|
|
Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
// Displayed in GiB instead of GB for consistency with Resonite
|
|
|
|
Text(
|
|
|
|
"${(usedBytes * 9.3132257461548e-10).toStringAsFixed(2)} GB of ${(maxBytes * 9.3132257461548e-10).toStringAsFixed(2)} GB"),
|
|
|
|
Text("Storage Space Used",
|
|
|
|
style: Theme.of(context).textTheme.labelSmall?.copyWith(fontSize: 10)),
|
|
|
|
]),
|
|
|
|
],
|
|
|
|
),
|
2024-02-16 11:39:59 -04:00
|
|
|
)),
|
|
|
|
]),
|
2023-05-05 09:05:06 -04:00
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2024-01-27 10:55:55 -04:00
|
|
|
}
|