2024-11-08 16:09:46 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2024-11-09 11:32:21 +00:00
|
|
|
import 'package:gap/gap.dart';
|
2024-11-09 10:28:45 +00:00
|
|
|
import 'package:go_router/go_router.dart';
|
2024-11-09 11:32:21 +00:00
|
|
|
import 'package:material_symbols_icons/symbols.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:styled_widget/styled_widget.dart';
|
2024-12-07 17:01:20 +00:00
|
|
|
import 'package:surface/providers/sn_network.dart';
|
2024-11-09 11:32:21 +00:00
|
|
|
import 'package:surface/providers/userinfo.dart';
|
|
|
|
import 'package:surface/widgets/account/account_image.dart';
|
2024-12-05 14:22:38 +00:00
|
|
|
import 'package:surface/widgets/app_bar_leading.dart';
|
2024-11-09 11:32:21 +00:00
|
|
|
import 'package:surface/widgets/dialog.dart';
|
2024-11-08 16:09:46 +00:00
|
|
|
|
2024-11-09 11:32:21 +00:00
|
|
|
class AccountScreen extends StatelessWidget {
|
2024-11-08 16:09:46 +00:00
|
|
|
const AccountScreen({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-11-09 11:32:21 +00:00
|
|
|
final ua = context.watch<UserProvider>();
|
|
|
|
|
2024-11-14 14:21:13 +00:00
|
|
|
return Scaffold(
|
2024-11-08 16:09:46 +00:00
|
|
|
appBar: AppBar(
|
2024-12-05 14:22:38 +00:00
|
|
|
leading: AutoAppBarLeading(),
|
2024-11-09 10:28:45 +00:00
|
|
|
title: Text("screenAccount").tr(),
|
2024-11-10 13:48:42 +00:00
|
|
|
actions: [
|
|
|
|
IconButton(
|
|
|
|
icon: const Icon(Symbols.settings, fill: 1),
|
|
|
|
onPressed: () {
|
|
|
|
GoRouter.of(context).pushNamed('settings');
|
|
|
|
},
|
|
|
|
),
|
2024-11-24 12:23:06 +00:00
|
|
|
const Gap(8),
|
2024-11-10 13:48:42 +00:00
|
|
|
],
|
2024-11-09 10:28:45 +00:00
|
|
|
),
|
2024-11-09 11:32:21 +00:00
|
|
|
body: SingleChildScrollView(
|
|
|
|
child: ua.isAuthorized
|
|
|
|
? _AuthorizedAccountScreen()
|
|
|
|
: _UnauthorizedAccountScreen(),
|
2024-11-08 16:09:46 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-11-09 11:32:21 +00:00
|
|
|
|
|
|
|
class _AuthorizedAccountScreen extends StatelessWidget {
|
2024-11-09 13:47:40 +00:00
|
|
|
const _AuthorizedAccountScreen();
|
2024-11-09 11:32:21 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final ua = context.watch<UserProvider>();
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
Card(
|
|
|
|
child: Builder(builder: (context) {
|
|
|
|
if (ua.user == null) {
|
|
|
|
return SizedBox(
|
|
|
|
width: double.infinity,
|
|
|
|
height: 120,
|
|
|
|
child: CircularProgressIndicator().center(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SizedBox(
|
|
|
|
width: double.infinity,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
AccountImage(content: ua.user!.avatar, radius: 28),
|
|
|
|
const Gap(8),
|
|
|
|
Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.baseline,
|
|
|
|
textBaseline: TextBaseline.alphabetic,
|
|
|
|
children: [
|
|
|
|
Text(ua.user!.nick)
|
|
|
|
.textStyle(Theme.of(context).textTheme.titleLarge!),
|
|
|
|
const Gap(4),
|
|
|
|
Text('@${ua.user!.name}')
|
|
|
|
.textStyle(Theme.of(context).textTheme.bodySmall!),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Text(ua.user!.description)
|
|
|
|
.textStyle(Theme.of(context).textTheme.bodyMedium!),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).padding(all: 20),
|
|
|
|
).padding(horizontal: 8, top: 16, bottom: 4),
|
2024-11-09 17:04:39 +00:00
|
|
|
ListTile(
|
|
|
|
title: Text('accountProfileEdit').tr(),
|
|
|
|
subtitle: Text('accountProfileEditSubtitle').tr(),
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
leading: const Icon(Symbols.contact_page),
|
2024-11-10 10:37:34 +00:00
|
|
|
trailing: const Icon(Symbols.chevron_right),
|
2024-11-09 17:04:39 +00:00
|
|
|
onTap: () {
|
|
|
|
GoRouter.of(context).pushNamed('accountProfileEdit');
|
|
|
|
},
|
|
|
|
),
|
2024-11-09 11:32:21 +00:00
|
|
|
ListTile(
|
|
|
|
title: Text('accountPublishers').tr(),
|
|
|
|
subtitle: Text('accountPublishersSubtitle').tr(),
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
leading: const Icon(Symbols.face),
|
2024-11-10 10:37:34 +00:00
|
|
|
trailing: const Icon(Symbols.chevron_right),
|
2024-11-09 13:47:40 +00:00
|
|
|
onTap: () {
|
|
|
|
GoRouter.of(context).pushNamed('accountPublishers');
|
|
|
|
},
|
2024-11-09 11:32:21 +00:00
|
|
|
),
|
2024-12-07 17:01:20 +00:00
|
|
|
ListTile(
|
|
|
|
title: Text('abuseReport').tr(),
|
|
|
|
subtitle: Text('abuseReportActionDescription').tr(),
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
leading: const Icon(Symbols.flag),
|
|
|
|
trailing: const Icon(Symbols.chevron_right),
|
|
|
|
onTap: () {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => _AbuseReportDialog(),
|
|
|
|
).then((value) {
|
|
|
|
if (value == true && context.mounted) {
|
|
|
|
context.showSnackbar('abuseReportSubmitted'.tr());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
2024-11-09 11:32:21 +00:00
|
|
|
ListTile(
|
|
|
|
title: Text('accountLogout').tr(),
|
|
|
|
subtitle: Text('accountLogoutSubtitle').tr(),
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
leading: const Icon(Symbols.logout),
|
2024-11-10 10:37:34 +00:00
|
|
|
trailing: const Icon(Symbols.chevron_right),
|
2024-11-09 11:32:21 +00:00
|
|
|
onTap: () {
|
|
|
|
context
|
|
|
|
.showConfirmDialog(
|
|
|
|
'accountLogoutConfirmTitle'.tr(),
|
|
|
|
'accountLogoutConfirm'.tr(),
|
|
|
|
)
|
|
|
|
.then((value) {
|
|
|
|
if (value) ua.logoutUser();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _UnauthorizedAccountScreen extends StatelessWidget {
|
2024-11-09 13:47:40 +00:00
|
|
|
const _UnauthorizedAccountScreen();
|
2024-11-09 11:32:21 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
Card(
|
|
|
|
child: SizedBox(
|
|
|
|
width: double.infinity,
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
2024-11-09 13:47:40 +00:00
|
|
|
const CircleAvatar(
|
|
|
|
radius: 28,
|
|
|
|
child: Icon(Symbols.waving_hand, size: 28),
|
|
|
|
),
|
2024-11-09 11:32:21 +00:00
|
|
|
const Gap(8),
|
|
|
|
Text('accountIntroTitle')
|
|
|
|
.tr()
|
|
|
|
.textStyle(Theme.of(context).textTheme.titleLarge!),
|
|
|
|
Text('accountIntroSubtitle').tr(),
|
|
|
|
],
|
|
|
|
).padding(all: 20),
|
|
|
|
),
|
|
|
|
).padding(horizontal: 8, top: 16, bottom: 4),
|
|
|
|
ListTile(
|
|
|
|
title: Text('screenAuthLogin').tr(),
|
|
|
|
subtitle: Text('screenAuthLoginSubtitle').tr(),
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
leading: const Icon(Symbols.login),
|
2024-11-10 10:37:34 +00:00
|
|
|
trailing: const Icon(Symbols.chevron_right),
|
2024-11-09 11:32:21 +00:00
|
|
|
onTap: () {
|
2024-12-02 14:42:31 +00:00
|
|
|
GoRouter.of(context).pushNamed('authLogin').then((value) {
|
|
|
|
if (value == true && context.mounted) {
|
|
|
|
final ua = context.read<UserProvider>();
|
|
|
|
context.showSnackbar('loginSuccess'.tr(args: [
|
|
|
|
'@${ua.user?.name} (${ua.user?.nick})',
|
|
|
|
]));
|
|
|
|
}
|
|
|
|
});
|
2024-11-09 11:32:21 +00:00
|
|
|
},
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: Text('screenAuthRegister').tr(),
|
|
|
|
subtitle: Text('screenAuthRegisterSubtitle').tr(),
|
|
|
|
contentPadding: const EdgeInsets.symmetric(horizontal: 24),
|
|
|
|
leading: const Icon(Symbols.person_add),
|
2024-11-10 10:37:34 +00:00
|
|
|
trailing: const Icon(Symbols.chevron_right),
|
2024-11-09 11:32:21 +00:00
|
|
|
onTap: () {
|
|
|
|
GoRouter.of(context).pushNamed('authRegister');
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-12-07 17:01:20 +00:00
|
|
|
|
|
|
|
class _AbuseReportDialog extends StatefulWidget {
|
|
|
|
const _AbuseReportDialog({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<_AbuseReportDialog> createState() => _AbuseReportDialogState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _AbuseReportDialogState extends State<_AbuseReportDialog> {
|
|
|
|
bool _isBusy = false;
|
|
|
|
|
|
|
|
final _resourceController = TextEditingController();
|
|
|
|
final _reasonController = TextEditingController();
|
|
|
|
|
|
|
|
@override
|
|
|
|
dispose() {
|
|
|
|
_resourceController.dispose();
|
|
|
|
_reasonController.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _performAction() async {
|
|
|
|
setState(() => _isBusy = true);
|
|
|
|
try {
|
|
|
|
final sn = context.read<SnNetworkProvider>();
|
|
|
|
await sn.client.request(
|
|
|
|
'/cgi/id/reports/abuse',
|
|
|
|
data: {
|
|
|
|
'resource': _resourceController.text,
|
|
|
|
'reason': _reasonController.text,
|
|
|
|
},
|
|
|
|
);
|
|
|
|
if (!mounted) return;
|
|
|
|
Navigator.pop(context, true);
|
|
|
|
} catch (err) {
|
|
|
|
if (!mounted) return;
|
|
|
|
context.showErrorDialog(err);
|
|
|
|
} finally {
|
|
|
|
setState(() => _isBusy = false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return AlertDialog(
|
|
|
|
title: Text('abuseReport'.tr()),
|
|
|
|
content: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text('abuseReportDescription'.tr()),
|
|
|
|
const Gap(12),
|
|
|
|
TextField(
|
|
|
|
controller: _resourceController,
|
|
|
|
maxLength: null,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: const UnderlineInputBorder(),
|
|
|
|
labelText: 'abuseReportResource'.tr(),
|
|
|
|
),
|
|
|
|
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
|
|
|
|
),
|
|
|
|
const Gap(4),
|
|
|
|
TextField(
|
|
|
|
controller: _reasonController,
|
|
|
|
maxLength: null,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
border: const UnderlineInputBorder(),
|
|
|
|
labelText: 'abuseReportReason'.tr(),
|
|
|
|
),
|
|
|
|
onTapOutside: (_) => FocusManager.instance.primaryFocus?.unfocus(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: _isBusy ? null : () => Navigator.pop(context),
|
|
|
|
child: Text('dialogDismiss').tr(),
|
|
|
|
),
|
|
|
|
TextButton(
|
|
|
|
onPressed: _isBusy ? null : _performAction,
|
|
|
|
child: Text('submit').tr(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|