2020-12-06 07:46:12 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:selfprivacy/config/brand_colors.dart';
|
|
|
|
import 'package:selfprivacy/config/brand_theme.dart';
|
2020-12-08 19:26:51 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/app_settings/app_settings_cubit.dart';
|
2022-05-17 13:31:34 +00:00
|
|
|
import 'package:selfprivacy/logic/cubit/server_installation/server_installation_cubit.dart';
|
2021-02-15 18:58:29 +00:00
|
|
|
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
|
|
|
|
import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart';
|
2020-12-06 07:46:12 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
|
2021-08-29 09:50:24 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_switch/brand_switch.dart';
|
2020-12-08 19:26:51 +00:00
|
|
|
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
|
2021-01-06 17:35:57 +00:00
|
|
|
import 'package:selfprivacy/utils/named_font_weight.dart';
|
2021-03-18 07:26:54 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2020-12-06 07:46:12 +00:00
|
|
|
|
2020-12-08 19:26:51 +00:00
|
|
|
class AppSettingsPage extends StatefulWidget {
|
2022-06-05 22:40:34 +00:00
|
|
|
const AppSettingsPage({final super.key});
|
2020-12-06 07:46:12 +00:00
|
|
|
|
2020-12-08 19:26:51 +00:00
|
|
|
@override
|
2022-05-25 12:21:56 +00:00
|
|
|
State<AppSettingsPage> createState() => _AppSettingsPageState();
|
2020-12-08 19:26:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _AppSettingsPageState extends State<AppSettingsPage> {
|
2020-12-06 07:46:12 +00:00
|
|
|
@override
|
2022-06-05 19:36:32 +00:00
|
|
|
Widget build(final BuildContext context) {
|
2022-06-05 22:40:34 +00:00
|
|
|
final bool isDarkModeOn =
|
|
|
|
context.watch<AppSettingsCubit>().state.isDarkModeOn;
|
2020-12-08 19:26:51 +00:00
|
|
|
|
2020-12-06 07:46:12 +00:00
|
|
|
return SafeArea(
|
2022-06-05 22:40:34 +00:00
|
|
|
child: Builder(
|
|
|
|
builder: (final context) => Scaffold(
|
2020-12-08 19:26:51 +00:00
|
|
|
appBar: PreferredSize(
|
2022-05-24 18:55:39 +00:00
|
|
|
preferredSize: const Size.fromHeight(52),
|
2021-04-22 18:04:24 +00:00
|
|
|
child: BrandHeader(
|
2022-06-05 22:40:34 +00:00
|
|
|
title: 'more.settings.title'.tr(),
|
|
|
|
hasBackButton: true,
|
|
|
|
),
|
2020-12-08 19:26:51 +00:00
|
|
|
),
|
|
|
|
body: ListView(
|
2021-05-25 21:53:54 +00:00
|
|
|
padding: paddingH15V0,
|
2020-12-08 19:26:51 +00:00
|
|
|
children: [
|
2022-09-14 13:37:29 +00:00
|
|
|
const Divider(height: 1),
|
2020-12-08 19:26:51 +00:00
|
|
|
Container(
|
2022-09-14 13:37:29 +00:00
|
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
2020-12-08 19:26:51 +00:00
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Flexible(
|
|
|
|
child: _TextColumn(
|
2021-03-25 08:32:00 +00:00
|
|
|
title: 'more.settings.1'.tr(),
|
|
|
|
value: 'more.settings.2'.tr(),
|
2022-05-25 12:21:56 +00:00
|
|
|
hasWarning: false,
|
2020-12-08 19:26:51 +00:00
|
|
|
),
|
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(width: 5),
|
2021-08-29 09:50:24 +00:00
|
|
|
BrandSwitch(
|
2020-12-08 19:26:51 +00:00
|
|
|
value: Theme.of(context).brightness == Brightness.dark,
|
2022-06-05 19:36:32 +00:00
|
|
|
onChanged: (final value) => context
|
2021-03-15 15:39:44 +00:00
|
|
|
.read<AppSettingsCubit>()
|
|
|
|
.updateDarkMode(isDarkModeOn: !isDarkModeOn),
|
2020-12-08 19:26:51 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2021-01-06 17:35:57 +00:00
|
|
|
),
|
2022-09-14 13:37:29 +00:00
|
|
|
const Divider(height: 0),
|
2021-01-06 17:35:57 +00:00
|
|
|
Container(
|
2022-09-14 13:37:29 +00:00
|
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
2021-01-06 17:35:57 +00:00
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Flexible(
|
|
|
|
child: _TextColumn(
|
2021-03-25 08:32:00 +00:00
|
|
|
title: 'more.settings.3'.tr(),
|
|
|
|
value: 'more.settings.4'.tr(),
|
2022-05-25 12:21:56 +00:00
|
|
|
hasWarning: false,
|
2021-01-06 17:35:57 +00:00
|
|
|
),
|
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(width: 5),
|
2021-03-14 18:44:35 +00:00
|
|
|
ElevatedButton(
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
primary: BrandColors.red1,
|
|
|
|
),
|
2021-01-06 17:35:57 +00:00
|
|
|
child: Text(
|
2021-03-25 08:32:00 +00:00
|
|
|
'basis.reset'.tr(),
|
2022-05-24 18:55:39 +00:00
|
|
|
style: const TextStyle(
|
2021-01-06 17:35:57 +00:00
|
|
|
color: BrandColors.white,
|
|
|
|
fontWeight: NamedFontWeight.demiBold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
onPressed: () {
|
|
|
|
showDialog(
|
2021-02-15 18:58:29 +00:00
|
|
|
context: context,
|
2022-06-05 19:36:32 +00:00
|
|
|
builder: (final _) => BrandAlert(
|
2022-06-05 22:40:34 +00:00
|
|
|
title: 'modals.3'.tr(),
|
|
|
|
contentText: 'modals.4'.tr(),
|
|
|
|
actions: [
|
|
|
|
ActionButton(
|
|
|
|
text: 'modals.5'.tr(),
|
|
|
|
isRed: true,
|
|
|
|
onPressed: () {
|
|
|
|
context
|
|
|
|
.read<ServerInstallationCubit>()
|
|
|
|
.clearAppConfig();
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ActionButton(
|
|
|
|
text: 'basis.cancel'.tr(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2021-02-15 18:58:29 +00:00
|
|
|
);
|
2021-01-06 17:35:57 +00:00
|
|
|
},
|
2021-04-22 18:04:24 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2022-09-14 13:37:29 +00:00
|
|
|
const Divider(height: 0),
|
2022-09-15 16:57:26 +00:00
|
|
|
_deleteServer(context)
|
2020-12-08 19:26:51 +00:00
|
|
|
],
|
|
|
|
),
|
2022-06-05 22:40:34 +00:00
|
|
|
),
|
|
|
|
),
|
2020-12-06 07:46:12 +00:00
|
|
|
);
|
|
|
|
}
|
2021-08-29 13:54:28 +00:00
|
|
|
|
2022-09-15 16:57:26 +00:00
|
|
|
Widget _deleteServer(final BuildContext context) {
|
2022-06-05 19:36:32 +00:00
|
|
|
final bool isDisabled =
|
2022-05-17 13:31:34 +00:00
|
|
|
context.watch<ServerInstallationCubit>().state.serverDetails == null;
|
2021-08-29 13:54:28 +00:00
|
|
|
return Container(
|
2022-09-14 13:37:29 +00:00
|
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
2021-08-29 13:54:28 +00:00
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Flexible(
|
|
|
|
child: _TextColumn(
|
|
|
|
title: 'more.settings.5'.tr(),
|
|
|
|
value: 'more.settings.6'.tr(),
|
2022-05-25 12:21:56 +00:00
|
|
|
hasWarning: false,
|
2021-08-29 13:54:28 +00:00
|
|
|
),
|
|
|
|
),
|
2022-05-24 18:55:39 +00:00
|
|
|
const SizedBox(width: 5),
|
2021-08-29 13:54:28 +00:00
|
|
|
ElevatedButton(
|
|
|
|
style: ElevatedButton.styleFrom(
|
|
|
|
primary: BrandColors.red1,
|
|
|
|
),
|
2021-10-11 21:10:04 +00:00
|
|
|
onPressed: isDisabled
|
|
|
|
? null
|
|
|
|
: () {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
2022-06-05 19:36:32 +00:00
|
|
|
builder: (final _) => BrandAlert(
|
2022-06-05 22:40:34 +00:00
|
|
|
title: 'modals.3'.tr(),
|
|
|
|
contentText: 'modals.6'.tr(),
|
|
|
|
actions: [
|
|
|
|
ActionButton(
|
|
|
|
text: 'modals.7'.tr(),
|
|
|
|
isRed: true,
|
|
|
|
onPressed: () async {
|
|
|
|
showDialog(
|
|
|
|
context: context,
|
|
|
|
builder: (final context) => Container(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: const CircularProgressIndicator(),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
await context
|
|
|
|
.read<ServerInstallationCubit>()
|
|
|
|
.serverDelete();
|
|
|
|
if (!mounted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
ActionButton(
|
|
|
|
text: 'basis.cancel'.tr(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2021-10-11 21:10:04 +00:00
|
|
|
);
|
|
|
|
},
|
2022-05-24 18:55:39 +00:00
|
|
|
child: Text(
|
|
|
|
'basis.delete'.tr(),
|
|
|
|
style: const TextStyle(
|
|
|
|
color: BrandColors.white,
|
|
|
|
fontWeight: NamedFontWeight.demiBold,
|
|
|
|
),
|
|
|
|
),
|
2021-08-29 13:54:28 +00:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2020-12-06 07:46:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class _TextColumn extends StatelessWidget {
|
|
|
|
const _TextColumn({
|
2021-03-15 15:39:44 +00:00
|
|
|
required this.title,
|
|
|
|
required this.value,
|
2020-12-06 07:46:12 +00:00
|
|
|
this.hasWarning = false,
|
2022-06-05 19:36:32 +00:00
|
|
|
});
|
2020-12-06 07:46:12 +00:00
|
|
|
|
|
|
|
final String title;
|
|
|
|
final String value;
|
|
|
|
final bool hasWarning;
|
|
|
|
@override
|
2022-06-05 19:36:32 +00:00
|
|
|
Widget build(final BuildContext context) => Column(
|
2022-06-05 22:40:34 +00:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
BrandText.body1(
|
|
|
|
title,
|
|
|
|
style: TextStyle(color: hasWarning ? BrandColors.warning : null),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 5),
|
|
|
|
BrandText.body1(
|
|
|
|
value,
|
2022-05-24 18:55:39 +00:00
|
|
|
style: const TextStyle(
|
2020-12-08 19:26:51 +00:00
|
|
|
fontSize: 13,
|
|
|
|
height: 1.53,
|
|
|
|
color: BrandColors.gray1,
|
2022-06-05 22:40:34 +00:00
|
|
|
).merge(TextStyle(color: hasWarning ? BrandColors.warning : null)),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
2020-12-06 07:46:12 +00:00
|
|
|
}
|