2024-05-18 10:17:16 +00:00
|
|
|
import 'package:flutter/material.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';
|
|
|
|
import 'package:solian/router.dart';
|
2024-05-23 15:54:05 +00:00
|
|
|
import 'package:solian/screens/auth/signin.dart';
|
|
|
|
import 'package:solian/screens/auth/signup.dart';
|
2024-06-03 15:36:46 +00:00
|
|
|
import 'package:solian/widgets/account/account_heading.dart';
|
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
|
|
|
(
|
|
|
|
const Icon(Icons.color_lens),
|
|
|
|
'accountPersonalize'.tr,
|
|
|
|
'accountPersonalize'
|
|
|
|
),
|
|
|
|
(const Icon(Icons.diversity_1), 'accountFriend'.tr, 'accountFriend'),
|
2024-05-18 16:56:32 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
final AuthProvider provider = Get.find();
|
|
|
|
|
|
|
|
return Material(
|
2024-05-21 16:05:03 +00:00
|
|
|
color: Theme.of(context).colorScheme.surface,
|
2024-06-03 15:36:46 +00:00
|
|
|
child: SafeArea(
|
|
|
|
child: FutureBuilder(
|
|
|
|
future: provider.isAuthorized,
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (!snapshot.hasData || snapshot.data == false) {
|
|
|
|
return Center(
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
ActionCard(
|
|
|
|
icon: const Icon(Icons.login, color: Colors.white),
|
|
|
|
title: 'signin'.tr,
|
|
|
|
caption: 'signinCaption'.tr,
|
|
|
|
onTap: () {
|
|
|
|
showModalBottomSheet(
|
|
|
|
useRootNavigator: true,
|
|
|
|
isDismissible: false,
|
|
|
|
isScrollControlled: true,
|
|
|
|
context: context,
|
|
|
|
builder: (context) => const SignInPopup(),
|
|
|
|
).then((_) async {
|
|
|
|
await provider.getProfile(noCache: true);
|
|
|
|
setState(() {});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ActionCard(
|
|
|
|
icon: const Icon(Icons.add, color: Colors.white),
|
|
|
|
title: 'signup'.tr,
|
|
|
|
caption: 'signupCaption'.tr,
|
|
|
|
onTap: () {
|
|
|
|
showModalBottomSheet(
|
|
|
|
useRootNavigator: true,
|
|
|
|
isDismissible: false,
|
|
|
|
isScrollControlled: true,
|
|
|
|
context: context,
|
|
|
|
builder: (context) => const SignUpPopup(),
|
|
|
|
).then((_) {
|
|
|
|
setState(() {});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
const AccountHeading().paddingOnly(bottom: 8),
|
|
|
|
...(actionItems.map(
|
|
|
|
(x) => ListTile(
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 34),
|
|
|
|
leading: x.$1,
|
|
|
|
title: Text(x.$2),
|
2024-05-18 16:56:32 +00:00
|
|
|
onTap: () {
|
2024-06-03 15:36:46 +00:00
|
|
|
AppRouter.instance
|
|
|
|
.pushNamed(x.$3)
|
|
|
|
.then((_) => setState(() {}));
|
2024-05-18 16:56:32 +00:00
|
|
|
},
|
|
|
|
),
|
2024-06-03 15:36:46 +00:00
|
|
|
)),
|
|
|
|
ListTile(
|
2024-05-18 16:56:32 +00:00
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 34),
|
2024-06-03 15:36:46 +00:00
|
|
|
leading: const Icon(Icons.logout),
|
|
|
|
title: Text('signout'.tr),
|
2024-05-18 16:56:32 +00:00
|
|
|
onTap: () {
|
2024-06-03 15:36:46 +00:00
|
|
|
provider.signout();
|
|
|
|
setState(() {});
|
2024-05-18 16:56:32 +00:00
|
|
|
},
|
|
|
|
),
|
2024-06-03 15:36:46 +00:00
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2024-05-18 16:56:32 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-03 15:36:46 +00:00
|
|
|
class AccountHeading extends StatelessWidget {
|
|
|
|
const AccountHeading({super.key});
|
2024-05-18 16:56:32 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final AuthProvider provider = Get.find();
|
|
|
|
|
|
|
|
return FutureBuilder(
|
|
|
|
future: provider.getProfile(),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
if (!snapshot.hasData) {
|
2024-05-23 14:11:42 +00:00
|
|
|
return Container();
|
2024-05-18 16:56:32 +00:00
|
|
|
}
|
|
|
|
|
2024-05-23 14:11:42 +00:00
|
|
|
final prof = snapshot.data!;
|
2024-06-03 15:36:46 +00:00
|
|
|
return AccountHeadingWidget(
|
|
|
|
avatar: prof.body['avatar'],
|
|
|
|
banner: prof.body['banner'],
|
|
|
|
name: prof.body['name'],
|
|
|
|
nick: prof.body['nick'],
|
|
|
|
desc: prof.body['description'],
|
|
|
|
badges: prof.body['badges']
|
|
|
|
?.map((e) => AccountBadge.fromJson(e))
|
|
|
|
.toList()
|
|
|
|
.cast<AccountBadge>(),
|
2024-05-18 16:56:32 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ActionCard extends StatelessWidget {
|
|
|
|
final Widget icon;
|
|
|
|
final String title;
|
|
|
|
final String caption;
|
|
|
|
final Function onTap;
|
|
|
|
|
|
|
|
const ActionCard({
|
|
|
|
super.key,
|
|
|
|
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(
|
|
|
|
backgroundColor: Colors.indigo,
|
|
|
|
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
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|