selfprivacy.org.app/lib/ui/pages/more/app_settings/app_setting.dart

221 lines
7.7 KiB
Dart
Raw Normal View History

2020-12-06 09:46:12 +02:00
import 'package:flutter/material.dart';
import 'package:selfprivacy/config/brand_colors.dart';
import 'package:selfprivacy/config/brand_theme.dart';
2020-12-08 21:26:51 +02:00
import 'package:selfprivacy/logic/cubit/app_settings/app_settings_cubit.dart';
2021-01-06 19:35:57 +02:00
import 'package:selfprivacy/logic/cubit/app_config/app_config_cubit.dart';
2021-02-15 20:58:29 +02:00
import 'package:selfprivacy/ui/components/action_button/action_button.dart';
import 'package:selfprivacy/ui/components/brand_alert/brand_alert.dart';
2020-12-06 09:46:12 +02:00
import 'package:selfprivacy/ui/components/brand_divider/brand_divider.dart';
import 'package:selfprivacy/ui/components/brand_header/brand_header.dart';
2021-08-29 12:50:24 +03:00
import 'package:selfprivacy/ui/components/brand_switch/brand_switch.dart';
2020-12-08 21:26:51 +02:00
import 'package:selfprivacy/ui/components/brand_text/brand_text.dart';
2021-01-06 19:35:57 +02:00
import 'package:selfprivacy/utils/named_font_weight.dart';
2021-03-18 09:26:54 +02:00
import 'package:easy_localization/easy_localization.dart';
2020-12-06 09:46:12 +02:00
2020-12-08 21:26:51 +02:00
class AppSettingsPage extends StatefulWidget {
2021-03-15 17:39:44 +02:00
const AppSettingsPage({Key? key}) : super(key: key);
2020-12-06 09:46:12 +02:00
2020-12-08 21:26:51 +02:00
@override
_AppSettingsPageState createState() => _AppSettingsPageState();
}
class _AppSettingsPageState extends State<AppSettingsPage> {
2020-12-06 09:46:12 +02:00
@override
Widget build(BuildContext context) {
2021-03-15 17:39:44 +02:00
var isDarkModeOn = context.watch<AppSettingsCubit>().state.isDarkModeOn;
2020-12-08 21:26:51 +02:00
2020-12-06 09:46:12 +02:00
return SafeArea(
2020-12-08 21:26:51 +02:00
child: Builder(builder: (context) {
return Scaffold(
appBar: PreferredSize(
2021-04-22 21:04:24 +03:00
child: BrandHeader(
title: 'more.settings.title'.tr(), hasBackButton: true),
2020-12-08 21:26:51 +02:00
preferredSize: Size.fromHeight(52),
),
body: ListView(
2021-05-26 00:53:54 +03:00
padding: paddingH15V0,
2020-12-08 21:26:51 +02:00
children: [
BrandDivider(),
Container(
padding: EdgeInsets.only(top: 20, bottom: 5),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(width: 1, color: BrandColors.dividerColor),
)),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: _TextColumn(
2021-03-25 10:32:00 +02:00
title: 'more.settings.1'.tr(),
value: 'more.settings.2'.tr(),
2020-12-08 21:26:51 +02:00
),
),
SizedBox(width: 5),
2021-08-29 12:50:24 +03:00
BrandSwitch(
2020-12-08 21:26:51 +02:00
value: Theme.of(context).brightness == Brightness.dark,
2021-03-15 17:39:44 +02:00
onChanged: (value) => context
.read<AppSettingsCubit>()
.updateDarkMode(isDarkModeOn: !isDarkModeOn),
2020-12-08 21:26:51 +02:00
),
],
),
2021-01-06 19:35:57 +02:00
),
Container(
padding: EdgeInsets.only(top: 20, bottom: 5),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(width: 1, color: BrandColors.dividerColor),
)),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: _TextColumn(
2021-03-25 10:32:00 +02:00
title: 'more.settings.3'.tr(),
value: 'more.settings.4'.tr(),
2021-01-06 19:35:57 +02:00
),
),
SizedBox(width: 5),
2021-03-14 20:44:35 +02:00
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: BrandColors.red1,
),
2021-01-06 19:35:57 +02:00
child: Text(
2021-03-25 10:32:00 +02:00
'basis.reset'.tr(),
2021-01-06 19:35:57 +02:00
style: TextStyle(
color: BrandColors.white,
fontWeight: NamedFontWeight.demiBold,
),
),
onPressed: () {
showDialog(
2021-02-15 20:58:29 +02:00
context: context,
2021-03-14 20:44:35 +02:00
builder: (_) {
return BrandAlert(
2021-03-23 21:57:44 +02:00
title: 'modals.3'.tr(),
contentText: 'modals.4'.tr(),
2021-03-14 20:44:35 +02:00
acitons: [
ActionButton(
2021-03-23 21:57:44 +02:00
text: 'modals.5'.tr(),
2021-03-14 20:44:35 +02:00
isRed: true,
onPressed: () {
context
.read<AppConfigCubit>()
.clearAppConfig();
Navigator.of(context).pop();
}),
ActionButton(
2021-03-23 21:57:44 +02:00
text: 'basis.cancel'.tr(),
2021-03-14 20:44:35 +02:00
),
],
);
},
2021-02-15 20:58:29 +02:00
);
2021-01-06 19:35:57 +02:00
},
2021-04-22 21:04:24 +03:00
),
],
),
),
2021-08-29 16:54:28 +03:00
// deleteServer(context)
2020-12-08 21:26:51 +02:00
],
),
);
}),
2020-12-06 09:46:12 +02:00
);
}
2021-08-29 16:54:28 +03:00
Widget deleteServer(BuildContext context) {
// todo: need to check
return Container(
padding: EdgeInsets.only(top: 20, bottom: 5),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(width: 1, color: BrandColors.dividerColor),
)),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: _TextColumn(
title: 'more.settings.5'.tr(),
value: 'more.settings.6'.tr(),
),
),
SizedBox(width: 5),
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: BrandColors.red1,
),
child: Text(
'basis.delete'.tr(),
style: TextStyle(
color: BrandColors.white,
fontWeight: NamedFontWeight.demiBold,
),
),
onPressed: () {
showDialog(
context: context,
builder: (_) {
return BrandAlert(
title: 'modals.3'.tr(),
contentText: 'modals.6'.tr(),
acitons: [
ActionButton(
text: 'modals.7'.tr(),
isRed: true,
onPressed: () async {
await context.read<AppConfigCubit>().serverDelete();
Navigator.of(context).pop();
}),
ActionButton(
text: 'basis.cancel'.tr(),
),
],
);
},
);
},
),
],
),
);
}
2020-12-06 09:46:12 +02:00
}
class _TextColumn extends StatelessWidget {
const _TextColumn({
2021-03-15 17:39:44 +02:00
Key? key,
required this.title,
required this.value,
2020-12-06 09:46:12 +02:00
this.hasWarning = false,
}) : super(key: key);
final String title;
final String value;
final bool hasWarning;
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2020-12-08 21:26:51 +02:00
BrandText.body1(
title,
style: TextStyle(color: hasWarning ? BrandColors.warning : null),
),
2020-12-06 09:46:12 +02:00
SizedBox(height: 5),
2020-12-08 21:26:51 +02:00
BrandText.body1(value,
style: TextStyle(
fontSize: 13,
height: 1.53,
color: BrandColors.gray1,
).merge(TextStyle(color: hasWarning ? BrandColors.warning : null))),
2020-12-06 09:46:12 +02:00
],
);
}
}