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';
|
2023-03-29 15:14:27 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
2023-03-25 14:29:28 +01:00
|
|
|
|
|
|
|
class SettingsPage extends StatefulWidget {
|
2023-03-29 18:02:00 +02:00
|
|
|
Function refreshTheme;
|
2023-03-29 18:23:46 +02:00
|
|
|
Function refreshUser;
|
|
|
|
SettingsPage(
|
|
|
|
{super.key, required this.refreshTheme, required this.refreshUser});
|
2023-03-25 14:29:28 +01:00
|
|
|
|
|
|
|
@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(
|
2023-03-29 15:14:27 +02:00
|
|
|
title: Text(AppLocalizations.of(context)!.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(
|
2023-03-29 15:14:27 +02:00
|
|
|
title: Text(
|
|
|
|
AppLocalizations.of(context)!.limitRoomCount),
|
|
|
|
subtitle: Text(AppLocalizations.of(context)!
|
|
|
|
.limitRoomCountSubtitle),
|
2023-03-25 17:18:46 +01:00
|
|
|
trailing: Text('${meta?.maxRoomCount ?? ""}'),
|
|
|
|
),
|
|
|
|
ListTile(
|
2023-03-29 15:14:27 +02:00
|
|
|
title: Text(
|
|
|
|
AppLocalizations.of(context)!.limitRoomSize),
|
|
|
|
subtitle: Text(AppLocalizations.of(context)!
|
|
|
|
.limitRoomSizeSubtitle),
|
2023-03-25 17:18:46 +01:00
|
|
|
trailing: Text('${meta?.maxRoomSize ?? ""}'),
|
|
|
|
),
|
|
|
|
ListTile(
|
2023-03-29 15:14:27 +02:00
|
|
|
title: Text(AppLocalizations.of(context)!
|
|
|
|
.limitRoomMemberCount),
|
|
|
|
subtitle: Text(AppLocalizations.of(context)!
|
|
|
|
.limitRoomMemberCountSubtitle),
|
2023-03-25 17:18:46 +01:00
|
|
|
trailing:
|
|
|
|
Text('${meta?.maxRoomMemberCount ?? ""}')),
|
|
|
|
ListTile(
|
2023-03-29 15:14:27 +02:00
|
|
|
title: Text(AppLocalizations.of(context)!
|
|
|
|
.userDiscoverable),
|
|
|
|
subtitle: Text(AppLocalizations.of(context)!
|
|
|
|
.userDiscoverableSubtitle),
|
2023-03-25 17:18:46 +01:00
|
|
|
trailing: Checkbox(
|
|
|
|
tristate: true,
|
|
|
|
value: meta?.discoverable,
|
2023-03-29 15:14:27 +02:00
|
|
|
onChanged: (_) {
|
|
|
|
// TODO: implement changeVisibility
|
|
|
|
},
|
2023-03-25 17:18:46 +01:00
|
|
|
))
|
|
|
|
],
|
|
|
|
)))),
|
2023-03-25 14:29:28 +01:00
|
|
|
|
2023-03-25 17:18:46 +01:00
|
|
|
// change theme button
|
|
|
|
ListTile(
|
2023-03-29 15:14:27 +02:00
|
|
|
title: Text(AppLocalizations.of(context)!.changeThemeTitle),
|
|
|
|
subtitle: Text(AppLocalizations.of(context)!.changeThemeSubtitle),
|
2023-03-25 17:18:46 +01:00
|
|
|
trailing: const Icon(Icons.chevron_right),
|
|
|
|
onTap: () {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (context) => AlertDialog(
|
2023-03-29 15:14:27 +02:00
|
|
|
title: Text(
|
|
|
|
AppLocalizations.of(context)!.changeThemeTitle),
|
2023-03-25 17:18:46 +01:00
|
|
|
content: SingleChildScrollView(
|
|
|
|
child: Column(children: [
|
2023-03-29 15:14:27 +02:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(8),
|
|
|
|
child: Text(AppLocalizations.of(context)!
|
|
|
|
.changeThemeSubtitle),
|
2023-03-25 17:18:46 +01:00
|
|
|
),
|
|
|
|
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),
|
2023-03-29 15:14:27 +02:00
|
|
|
label: Text(item.name(context)));
|
2023-03-25 17:18:46 +01:00
|
|
|
}).toList(),
|
|
|
|
onSelectionChanged: (item) async {
|
|
|
|
try {
|
|
|
|
await item.first.toDisk();
|
2023-03-29 18:02:00 +02:00
|
|
|
widget.refreshTheme();
|
2023-03-25 17:18:46 +01:00
|
|
|
} catch (_) {}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
])),
|
|
|
|
actions: [
|
|
|
|
FilledButton(
|
2023-03-29 15:14:27 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.close),
|
2023-03-25 17:18:46 +01:00
|
|
|
onPressed: () {
|
2023-03-29 15:14:27 +02:00
|
|
|
context.pop();
|
2023-03-25 17:18:46 +01:00
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
));
|
|
|
|
},
|
|
|
|
),
|
2023-03-25 14:29:28 +01:00
|
|
|
|
2023-03-25 17:18:46 +01:00
|
|
|
// change password button
|
|
|
|
ListTile(
|
2023-03-29 15:14:27 +02:00
|
|
|
title: Text(AppLocalizations.of(context)!.changePasswordTitle),
|
|
|
|
subtitle:
|
|
|
|
Text(AppLocalizations.of(context)!.changePasswordSubtitle),
|
2023-03-25 17:18:46 +01:00
|
|
|
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(
|
2023-03-29 15:14:27 +02:00
|
|
|
title: Text(AppLocalizations.of(context)!.exportAccountTitle),
|
|
|
|
subtitle: Text(AppLocalizations.of(context)!.exportAccountSubtitle),
|
2023-03-25 17:18:46 +01:00
|
|
|
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(
|
2023-03-29 15:14:27 +02:00
|
|
|
title: Text(AppLocalizations.of(context)!.deleteAccountTitle),
|
|
|
|
subtitle: Text(AppLocalizations.of(context)!.deleteAccountSubtitle),
|
2023-03-25 17:18:46 +01:00
|
|
|
onTap: () {
|
|
|
|
// show confirm dialog
|
|
|
|
// NOTE: same as logout
|
|
|
|
// and performs a network request
|
|
|
|
// but deletes account beforehand
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (ctx) => AlertDialog(
|
2023-03-29 15:14:27 +02:00
|
|
|
title: Text(
|
|
|
|
AppLocalizations.of(context)!.deleteAccountTitle),
|
|
|
|
content: Text(
|
|
|
|
AppLocalizations.of(context)!.deleteAccountConfirm),
|
2023-03-25 14:29:28 +01:00
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
// close popup
|
|
|
|
Navigator.of(ctx).pop();
|
|
|
|
},
|
2023-03-29 15:14:27 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.cancel),
|
2023-03-25 14:29:28 +01:00
|
|
|
),
|
|
|
|
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-29 18:23:46 +02:00
|
|
|
widget.refreshUser();
|
2023-03-25 17:18:46 +01:00
|
|
|
},
|
|
|
|
after: () {
|
|
|
|
// close popup
|
|
|
|
nav.pop();
|
|
|
|
});
|
2023-03-25 14:29:28 +01:00
|
|
|
},
|
2023-03-29 15:14:27 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.yes),
|
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(
|
2023-03-29 15:14:27 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.logOut),
|
2023-03-25 17:18:46 +01:00
|
|
|
onPressed: () {
|
|
|
|
// show confirm dialog
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (ctx) => AlertDialog(
|
2023-03-29 15:14:27 +02:00
|
|
|
title: Text(AppLocalizations.of(context)!.logOut),
|
|
|
|
content: Text(
|
|
|
|
AppLocalizations.of(context)!.logOutConfirm),
|
2023-03-25 17:18:46 +01:00
|
|
|
actions: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () {
|
|
|
|
// close popup
|
|
|
|
Navigator.of(ctx).pop();
|
|
|
|
},
|
2023-03-29 15:14:27 +02:00
|
|
|
child:
|
|
|
|
Text(AppLocalizations.of(context)!.cancel),
|
2023-03-25 17:18:46 +01:00
|
|
|
),
|
|
|
|
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-29 18:23:46 +02:00
|
|
|
widget.refreshUser();
|
2023-03-25 17:18:46 +01:00
|
|
|
},
|
2023-03-29 15:14:27 +02:00
|
|
|
child: Text(AppLocalizations.of(context)!.yes),
|
2023-03-25 17:18:46 +01:00
|
|
|
)
|
|
|
|
],
|
|
|
|
));
|
|
|
|
},
|
2023-03-25 14:29:28 +01:00
|
|
|
))
|
2023-03-25 17:18:46 +01:00
|
|
|
]))));
|
2023-03-25 14:29:28 +01:00
|
|
|
}
|
|
|
|
}
|