2024-05-18 10:17:16 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-09-13 15:19:33 +00:00
|
|
|
import 'package:gap/gap.dart';
|
2024-05-18 16:56:32 +00:00
|
|
|
import 'package:get/get.dart';
|
2024-06-03 15:36:46 +00:00
|
|
|
import 'package:solian/models/account.dart';
|
2024-05-18 16:56:32 +00:00
|
|
|
import 'package:solian/providers/auth.dart';
|
2024-06-26 17:33:03 +00:00
|
|
|
import 'package:solian/providers/account_status.dart';
|
2024-08-02 15:15:28 +00:00
|
|
|
import 'package:solian/providers/relation.dart';
|
2024-05-18 16:56:32 +00:00
|
|
|
import 'package:solian/router.dart';
|
2024-06-03 15:36:46 +00:00
|
|
|
import 'package:solian/widgets/account/account_heading.dart';
|
2024-07-13 10:54:08 +00:00
|
|
|
import 'package:solian/widgets/sized_container.dart';
|
2024-08-02 15:15:28 +00:00
|
|
|
import 'package:badges/badges.dart' as badges;
|
2024-05-18 10:17:16 +00:00
|
|
|
|
2024-05-18 16:56:32 +00:00
|
|
|
class AccountScreen extends StatefulWidget {
|
2024-05-18 10:17:16 +00:00
|
|
|
const AccountScreen({super.key});
|
|
|
|
|
2024-05-18 16:56:32 +00:00
|
|
|
@override
|
|
|
|
State<AccountScreen> createState() => _AccountScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AccountScreenState extends State<AccountScreen> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final actionItems = [
|
2024-05-22 15:18:01 +00:00
|
|
|
(
|
2024-09-13 15:19:33 +00:00
|
|
|
const Icon(Icons.face),
|
|
|
|
'accountProfile'.tr,
|
|
|
|
'accountProfile',
|
2024-08-02 15:15:28 +00:00
|
|
|
),
|
|
|
|
(
|
|
|
|
Obx(() {
|
|
|
|
final RelationshipProvider relations = Get.find();
|
|
|
|
return badges.Badge(
|
|
|
|
badgeContent: Text(
|
|
|
|
relations.friendRequestCount.value.toString(),
|
|
|
|
style: const TextStyle(color: Colors.white),
|
|
|
|
),
|
|
|
|
showBadge: relations.friendRequestCount.value > 0,
|
|
|
|
position: badges.BadgePosition.topEnd(
|
|
|
|
top: -12,
|
|
|
|
end: -8,
|
|
|
|
),
|
|
|
|
child: const Icon(Icons.diversity_1),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
'accountFriend'.tr,
|
|
|
|
'accountFriend',
|
2024-05-22 15:18:01 +00:00
|
|
|
),
|
2024-05-18 16:56:32 +00:00
|
|
|
];
|
|
|
|
|
2024-07-24 17:18:47 +00:00
|
|
|
final AuthProvider auth = Get.find();
|
2024-05-18 16:56:32 +00:00
|
|
|
|
2024-10-06 15:06:33 +00:00
|
|
|
return SafeArea(
|
|
|
|
child: Obx(() {
|
|
|
|
if (auth.isAuthorized.isFalse) {
|
|
|
|
return Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
_ActionCard(
|
|
|
|
icon: Icon(
|
|
|
|
Icons.login,
|
|
|
|
color: Theme.of(context).colorScheme.onPrimary,
|
2024-07-24 17:18:47 +00:00
|
|
|
),
|
2024-10-06 15:06:33 +00:00
|
|
|
title: 'signin'.tr,
|
|
|
|
caption: 'signinCaption'.tr,
|
|
|
|
onTap: () {
|
|
|
|
AppRouter.instance.pushNamed('signin').then((val) async {
|
|
|
|
if (val == true) {
|
|
|
|
await auth.refreshUserProfile();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
_ActionCard(
|
|
|
|
icon: Icon(
|
|
|
|
Icons.add,
|
|
|
|
color: Theme.of(context).colorScheme.onPrimary,
|
2024-05-18 16:56:32 +00:00
|
|
|
),
|
2024-10-06 15:06:33 +00:00
|
|
|
title: 'signup'.tr,
|
|
|
|
caption: 'signupCaption'.tr,
|
|
|
|
onTap: () {
|
|
|
|
AppRouter.instance.pushNamed('signup').then((_) {
|
|
|
|
setState(() {});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
const Gap(4),
|
|
|
|
TextButton(
|
|
|
|
style: const ButtonStyle(
|
|
|
|
visualDensity: VisualDensity(
|
|
|
|
horizontal: -4,
|
|
|
|
vertical: -2,
|
2024-09-13 15:19:33 +00:00
|
|
|
),
|
|
|
|
),
|
2024-10-06 15:06:33 +00:00
|
|
|
onPressed: () {
|
|
|
|
AppRouter.instance.pushNamed('settings');
|
|
|
|
},
|
|
|
|
child: Text('settings'.tr),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2024-07-24 17:18:47 +00:00
|
|
|
|
2024-10-06 15:06:33 +00:00
|
|
|
return CenteredContainer(
|
|
|
|
child: ListView(
|
|
|
|
children: [
|
|
|
|
if (auth.userProfile.value != null)
|
|
|
|
const AccountHeading().paddingOnly(bottom: 8, top: 16),
|
|
|
|
...(actionItems.map(
|
|
|
|
(x) => ListTile(
|
2024-09-13 15:19:33 +00:00
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 34),
|
2024-10-06 15:06:33 +00:00
|
|
|
leading: x.$1,
|
|
|
|
title: Text(x.$2),
|
2024-09-13 15:19:33 +00:00
|
|
|
onTap: () {
|
2024-10-06 15:06:33 +00:00
|
|
|
AppRouter.instance
|
|
|
|
.pushNamed(x.$3)
|
|
|
|
.then((_) => setState(() {}));
|
2024-09-13 15:19:33 +00:00
|
|
|
},
|
|
|
|
),
|
2024-10-06 15:06:33 +00:00
|
|
|
)),
|
|
|
|
const Divider(thickness: 0.3, height: 1)
|
|
|
|
.paddingSymmetric(vertical: 4),
|
|
|
|
ListTile(
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 34),
|
|
|
|
leading: const Icon(Icons.settings),
|
|
|
|
title: Text('settings'.tr),
|
|
|
|
onTap: () {
|
|
|
|
AppRouter.instance.pushNamed('settings');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
if (auth.isAuthorized.value)
|
2024-07-24 17:18:47 +00:00
|
|
|
ListTile(
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 34),
|
2024-10-06 15:06:33 +00:00
|
|
|
leading: const Icon(Icons.edit_notifications),
|
|
|
|
title: Text('notificationPreferences'.tr),
|
2024-07-24 17:18:47 +00:00
|
|
|
onTap: () {
|
2024-10-06 15:06:33 +00:00
|
|
|
AppRouter.instance.pushNamed('notificationPreferences');
|
2024-07-24 17:18:47 +00:00
|
|
|
},
|
|
|
|
),
|
2024-10-06 15:06:33 +00:00
|
|
|
const Divider(thickness: 0.3, height: 1)
|
|
|
|
.paddingSymmetric(vertical: 4),
|
|
|
|
ListTile(
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 34),
|
|
|
|
leading: const Icon(Icons.logout),
|
|
|
|
title: Text('signout'.tr),
|
|
|
|
onTap: () {
|
|
|
|
auth.signout();
|
|
|
|
setState(() {});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}),
|
2024-05-18 16:56:32 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-26 17:33:03 +00:00
|
|
|
class AccountHeading extends StatefulWidget {
|
2024-06-03 15:36:46 +00:00
|
|
|
const AccountHeading({super.key});
|
2024-05-18 16:56:32 +00:00
|
|
|
|
2024-06-26 17:33:03 +00:00
|
|
|
@override
|
|
|
|
State<AccountHeading> createState() => _AccountHeadingState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AccountHeadingState extends State<AccountHeading> {
|
|
|
|
late Future<Response> _status;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
_status = Get.find<StatusProvider>().getCurrentStatus();
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2024-05-18 16:56:32 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-07-24 17:18:47 +00:00
|
|
|
final AuthProvider auth = Get.find();
|
|
|
|
|
|
|
|
final prof = auth.userProfile.value!;
|
2024-07-26 06:21:00 +00:00
|
|
|
|
2024-07-24 17:18:47 +00:00
|
|
|
return AccountHeadingWidget(
|
|
|
|
avatar: prof['avatar'],
|
|
|
|
banner: prof['banner'],
|
|
|
|
name: prof['name'],
|
|
|
|
nick: prof['nick'],
|
|
|
|
desc: prof['description'],
|
|
|
|
status: _status,
|
|
|
|
badges: prof['badges']
|
|
|
|
?.map((e) => AccountBadge.fromJson(e))
|
|
|
|
.toList()
|
|
|
|
.cast<AccountBadge>(),
|
|
|
|
onEditStatus: () {
|
|
|
|
setState(() {
|
|
|
|
_status = Get.find<StatusProvider>().getCurrentStatus();
|
|
|
|
});
|
2024-05-18 16:56:32 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-09-13 15:19:33 +00:00
|
|
|
class _ActionCard extends StatelessWidget {
|
2024-05-18 16:56:32 +00:00
|
|
|
final Widget icon;
|
|
|
|
final String title;
|
|
|
|
final String caption;
|
|
|
|
final Function onTap;
|
|
|
|
|
2024-09-13 15:19:33 +00:00
|
|
|
const _ActionCard({
|
2024-05-18 16:56:32 +00:00
|
|
|
required this.onTap,
|
|
|
|
required this.title,
|
|
|
|
required this.caption,
|
|
|
|
required this.icon,
|
|
|
|
});
|
|
|
|
|
2024-05-18 10:17:16 +00:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-05-18 16:56:32 +00:00
|
|
|
return Card(
|
|
|
|
child: InkWell(
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
onTap: () => onTap(),
|
|
|
|
child: Container(
|
|
|
|
width: 320,
|
|
|
|
padding: const EdgeInsets.all(20),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
CircleAvatar(
|
2024-08-01 16:29:51 +00:00
|
|
|
backgroundColor: Theme.of(context).colorScheme.primary,
|
2024-05-18 16:56:32 +00:00
|
|
|
child: icon,
|
|
|
|
).paddingOnly(bottom: 12),
|
|
|
|
Text(
|
|
|
|
title,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 18,
|
|
|
|
fontWeight: FontWeight.w900,
|
|
|
|
overflow: TextOverflow.clip,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Text(
|
|
|
|
caption,
|
|
|
|
style: const TextStyle(overflow: TextOverflow.clip),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2024-05-18 10:17:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|