2023-03-25 14:29:28 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2023-03-28 14:54:39 +02:00
|
|
|
import 'package:go_router/go_router.dart';
|
2023-03-25 14:29:28 +01:00
|
|
|
import 'package:outbag_app/backend/request.dart';
|
|
|
|
import 'package:outbag_app/backend/themes.dart';
|
|
|
|
import 'package:outbag_app/backend/user.dart';
|
|
|
|
import 'package:outbag_app/screens/settings/dialogs/password.dart';
|
|
|
|
import 'package:outbag_app/tools/fetch_wrapper.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
class SettingsPage extends StatefulWidget {
|
|
|
|
const SettingsPage({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() => _SettingsPageState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SettingsPageState extends State<SettingsPage> {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final textTheme = Theme.of(context)
|
2023-03-25 17:18:46 +01:00
|
|
|
.textTheme
|
|
|
|
.apply(displayColor: Theme.of(context).colorScheme.onSurface);
|
|
|
|
|
|
|
|
final user = context.watch<User>();
|
|
|
|
final meta = context.watch<AccountMeta?>();
|
2023-03-25 14:29:28 +01:00
|
|
|
|
|
|
|
return Scaffold(
|
2023-03-25 17:18:46 +01:00
|
|
|
appBar: AppBar(
|
|
|
|
title: const Text('Settings'),
|
2023-03-25 14:29:28 +01:00
|
|
|
),
|
2023-03-25 17:18:46 +01:00
|
|
|
body: SingleChildScrollView(
|
|
|
|
child: Center(
|
|
|
|
child: Column(children: [
|
|
|
|
// uswer information widget
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(14),
|
|
|
|
child: Card(
|
2023-03-25 14:29:28 +01:00
|
|
|
child: Padding(
|
2023-03-25 17:18:46 +01:00
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
child: Text(user.humanReadable,
|
|
|
|
style: textTheme.titleLarge)),
|
|
|
|
ListTile(
|
|
|
|
title: const Text('Room count limit:'),
|
|
|
|
subtitle: const Text(
|
|
|
|
'How many rooms you are allowed to own'),
|
|
|
|
trailing: Text('${meta?.maxRoomCount ?? ""}'),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: const Text('Room size limit:'),
|
|
|
|
subtitle: const Text(
|
|
|
|
'How many items/products/categories each room may contain'),
|
|
|
|
trailing: Text('${meta?.maxRoomSize ?? ""}'),
|
|
|
|
),
|
|
|
|
ListTile(
|
|
|
|
title: const Text('Room member limit:'),
|
|
|
|
subtitle: const Text(
|
|
|
|
'How many members each of your rooms may have'),
|
|
|
|
trailing:
|
|
|
|
Text('${meta?.maxRoomMemberCount ?? ""}')),
|
|
|
|
ListTile(
|
|
|
|
title: const Text('Discoverable'),
|
|
|
|
subtitle: const Text(
|
|
|
|
'Determines if your account can be discovered by users from other servers'),
|
|
|
|
trailing: Checkbox(
|
|
|
|
tristate: true,
|
|
|
|
value: meta?.discoverable,
|
|
|
|
onChanged: (_) {},
|
|
|
|
))
|
|
|
|
],
|
|
|
|
)))),
|
2023-03-25 14:29:28 +01:00
|
|
|
|
2023-03-25 17:18:46 +01:00
|
|
|
// change theme button
|
|
|
|
ListTile(
|
|
|
|
title: const Text('Change Theme'),
|
|
|
|
subtitle: const Text(
|
|
|
|
'You can change between a light theme, a dark theme and automatic theme selection'),
|
|
|
|
trailing: const Icon(Icons.chevron_right),
|
|
|
|
onTap: () {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
|
|
|
title: const Text('Change Theme'),
|
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: Column(children: [
|
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.all(8),
|
|
|
|
child: Text('Choose your preferred theme'),
|
|
|
|
),
|
|
|
|
SegmentedButton<AppTheme>(
|
|
|
|
selected: {context.watch<AppTheme>()},
|
|
|
|
selectedIcon: Icon(context.watch<AppTheme>().icon),
|
|
|
|
showSelectedIcon: true,
|
|
|
|
multiSelectionEnabled: false,
|
|
|
|
emptySelectionAllowed: false,
|
|
|
|
segments: AppTheme.list().map((item) {
|
|
|
|
return ButtonSegment<AppTheme>(
|
|
|
|
value: item,
|
|
|
|
icon: Icon(item.icon),
|
|
|
|
label: Text(item.name));
|
|
|
|
}).toList(),
|
|
|
|
onSelectionChanged: (item) async {
|
|
|
|
try {
|
|
|
|
await item.first.toDisk();
|
|
|
|
} catch (_) {}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
])),
|
|
|
|
actions: [
|
|
|
|
FilledButton(
|
|
|
|
child: const Text('Close'),
|
|
|
|
onPressed: () {
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
));
|
|
|
|
},
|
|
|
|
),
|
2023-03-25 14:29:28 +01:00
|
|
|
|
2023-03-25 17:18:46 +01:00
|
|
|
// change password button
|
|
|
|
ListTile(
|
|
|
|
title: const Text('Change password'),
|
|
|
|
subtitle: const Text('Choose a new password for your account'),
|
|
|
|
onTap: () {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => const ChangePasswordDialog());
|
|
|
|
},
|
|
|
|
trailing: const Icon(Icons.chevron_right),
|
|
|
|
),
|
2023-03-25 14:29:28 +01:00
|
|
|
|
2023-03-25 17:18:46 +01:00
|
|
|
// export account to json
|
|
|
|
ListTile(
|
|
|
|
title: const Text('Export account'),
|
|
|
|
subtitle: const Text('Export account data'),
|
|
|
|
onTap: () {
|
|
|
|
// TODO: show confirm dialog
|
|
|
|
// NOTE: json dump the localstore
|
|
|
|
// including users and rooms
|
|
|
|
// NOTE: feature not confirmed
|
|
|
|
},
|
|
|
|
trailing: const Icon(Icons.chevron_right),
|
|
|
|
),
|
2023-03-25 14:29:28 +01:00
|
|
|
|
2023-03-25 17:18:46 +01:00
|
|
|
// delete account button
|
|
|
|
ListTile(
|
|
|
|
title: const Text('Delete account'),
|
|
|
|
subtitle: const Text('Delete your account from your homeserver'),
|
|
|
|
onTap: () {
|
|
|
|
// show confirm dialog
|
|
|
|
// NOTE: same as logout
|
|
|
|
// and performs a network request
|
|
|
|
// but deletes account beforehand
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (ctx) => AlertDialog(
|
|
|
|
title: const Text('Delete account'),
|
|
|
|
content: const Text(
|
|
|
|
'Do you really want to delete your account?'),
|
2023-03-25 14:29:28 +01:00
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
// close popup
|
|
|
|
Navigator.of(ctx).pop();
|
|
|
|
},
|
|
|
|
child: const Text('Cancel'),
|
|
|
|
),
|
|
|
|
FilledButton(
|
|
|
|
onPressed: () async {
|
|
|
|
// send request
|
2023-03-25 17:18:46 +01:00
|
|
|
final scaffMgr = ScaffoldMessenger.of(ctx);
|
|
|
|
final nav = Navigator.of(ctx);
|
2023-03-28 14:54:39 +02:00
|
|
|
final router = GoRouter.of(ctx);
|
2023-03-25 14:29:28 +01:00
|
|
|
|
2023-03-25 17:18:46 +01:00
|
|
|
doNetworkRequest(scaffMgr,
|
|
|
|
req: () => postWithCreadentials(
|
|
|
|
path: 'deleteAccount',
|
|
|
|
target: user.server,
|
|
|
|
body: {},
|
|
|
|
credentials: user),
|
|
|
|
onOK: (_) async {
|
|
|
|
// delete everything
|
|
|
|
// delete user data (meta)
|
|
|
|
try {
|
|
|
|
await User.removeDisk();
|
|
|
|
} catch (_) {}
|
|
|
|
// TODO: delete all rooms
|
2023-03-25 14:29:28 +01:00
|
|
|
|
2023-03-25 17:18:46 +01:00
|
|
|
// go back home
|
2023-03-28 14:54:39 +02:00
|
|
|
router.pushReplacementNamed('home');
|
2023-03-25 17:18:46 +01:00
|
|
|
},
|
|
|
|
after: () {
|
|
|
|
// close popup
|
|
|
|
nav.pop();
|
|
|
|
});
|
2023-03-25 14:29:28 +01:00
|
|
|
},
|
2023-03-25 17:18:46 +01:00
|
|
|
child: const Text('Delete Account'),
|
2023-03-25 14:29:28 +01:00
|
|
|
)
|
|
|
|
],
|
2023-03-25 17:18:46 +01:00
|
|
|
));
|
|
|
|
},
|
|
|
|
trailing: const Icon(Icons.chevron_right),
|
|
|
|
),
|
|
|
|
|
|
|
|
// logout button
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
child: FilledButton.tonal(
|
|
|
|
child: const Text('Log out'),
|
|
|
|
onPressed: () {
|
|
|
|
// show confirm dialog
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (ctx) => AlertDialog(
|
|
|
|
title: const Text('Log out'),
|
|
|
|
content:
|
|
|
|
const Text('Do you really want to log out?'),
|
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
// close popup
|
|
|
|
Navigator.of(ctx).pop();
|
|
|
|
},
|
|
|
|
child: const Text('Cancel'),
|
|
|
|
),
|
|
|
|
FilledButton(
|
|
|
|
onPressed: () async {
|
|
|
|
// send request
|
2023-03-28 14:54:39 +02:00
|
|
|
final router = GoRouter.of(ctx);
|
2023-03-25 17:18:46 +01:00
|
|
|
|
|
|
|
// delete everything
|
|
|
|
// delete user data (meta)
|
|
|
|
try {
|
|
|
|
await User.removeDisk();
|
|
|
|
} catch (_) {}
|
|
|
|
// TODO: delete all rooms
|
|
|
|
|
|
|
|
// go back home
|
2023-03-28 14:54:39 +02:00
|
|
|
router.pushReplacementNamed('home');
|
2023-03-25 17:18:46 +01:00
|
|
|
},
|
|
|
|
child: const Text('Log out'),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
));
|
|
|
|
},
|
2023-03-25 14:29:28 +01:00
|
|
|
))
|
2023-03-25 17:18:46 +01:00
|
|
|
]))));
|
2023-03-25 14:29:28 +01:00
|
|
|
}
|
|
|
|
}
|