adguard-home-manager/lib/screens/settings/general_settings/general_settings.dart

265 lines
9.8 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2024-03-10 21:15:24 +01:00
import 'package:adguard_home_manager/screens/settings/settings.dart';
2024-02-07 19:46:35 +01:00
import 'package:adguard_home_manager/screens/settings/general_settings/top_items_list/top_items_list_settings.dart';
2023-09-09 23:30:53 +02:00
2022-10-21 02:06:53 +02:00
import 'package:adguard_home_manager/widgets/custom_list_tile.dart';
2023-05-25 21:14:26 +02:00
import 'package:adguard_home_manager/widgets/section_label.dart';
2023-10-29 02:47:14 +01:00
import 'package:adguard_home_manager/functions/desktop_mode.dart';
2023-05-25 21:14:26 +02:00
import 'package:adguard_home_manager/functions/snackbar.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart';
2023-05-17 21:50:13 +02:00
class GeneralSettings extends StatefulWidget {
final bool splitView;
const GeneralSettings({
super.key,
required this.splitView,
});
2023-05-17 21:50:13 +02:00
@override
State<GeneralSettings> createState() => _GeneralSettingsState();
}
enum AppUpdatesStatus { available, checking, recheck }
class _GeneralSettingsState extends State<GeneralSettings> {
AppUpdatesStatus appUpdatesStatus = AppUpdatesStatus.recheck;
@override
Widget build(BuildContext context) {
final appConfigProvider = Provider.of<AppConfigProvider>(context);
2023-10-29 02:47:14 +01:00
final width = MediaQuery.of(context).size.width;
2023-05-20 21:12:52 +02:00
Future updateSettings({
required bool newStatus,
required Future Function(bool) function
}) async {
final result = await function(newStatus);
if (!context.mounted) return;
if (result == true) {
2024-09-11 18:13:26 +02:00
showSnackbar(
2023-05-20 21:12:52 +02:00
appConfigProvider: appConfigProvider,
label: AppLocalizations.of(context)!.settingsUpdatedSuccessfully,
color: Colors.green
);
}
else {
2024-09-11 18:13:26 +02:00
showSnackbar(
2023-05-20 21:12:52 +02:00
appConfigProvider: appConfigProvider,
label: AppLocalizations.of(context)!.cannotUpdateSettings,
color: Colors.red
);
}
}
// Future checkUpdatesAvailable() async {
// setState(() => appUpdatesStatus = AppUpdatesStatus.checking);
2023-05-25 21:14:26 +02:00
// final res = await checkAppUpdates(
// currentBuildNumber: appConfigProvider.getAppInfo!.buildNumber,
// setUpdateAvailable: appConfigProvider.setAppUpdatesAvailable,
// installationSource: appConfigProvider.installationSource,
// isBeta: appConfigProvider.getAppInfo!.version.contains('beta'),
// );
2023-05-25 21:14:26 +02:00
// if (!mounted) return;
// if (res != null) {
// setState(() => appUpdatesStatus = AppUpdatesStatus.available);
// }
// else {
// setState(() => appUpdatesStatus = AppUpdatesStatus.recheck);
// }
// }
2023-05-17 21:50:13 +02:00
// Widget generateAppUpdateStatus() {
// if (appUpdatesStatus == AppUpdatesStatus.available) {
// return IconButton(
// onPressed: appConfigProvider.appUpdatesAvailable != null
// ? () async {
// final link = getAppUpdateDownloadLink(appConfigProvider.appUpdatesAvailable!);
// if (link != null) {
// openUrl(link);
// }
// }
// : null,
// icon: const Icon(Icons.download_rounded),
// tooltip: AppLocalizations.of(context)!.downloadUpdate,
// );
// }
// else if (appUpdatesStatus == AppUpdatesStatus.checking) {
// return const Padding(
// padding: EdgeInsets.only(right: 16),
// child: SizedBox(
// width: 24,
// height: 24,
// child: CircularProgressIndicator(
// strokeWidth: 3,
// )
// ),
// );
// }
// else {
// return IconButton(
// onPressed: checkUpdatesAvailable,
// icon: const Icon(Icons.refresh_rounded),
// tooltip: AppLocalizations.of(context)!.checkUpdates,
// );
// }
// }
2023-05-17 21:50:13 +02:00
return Scaffold(
2023-05-21 14:52:35 +02:00
appBar: AppBar(
title: Text(AppLocalizations.of(context)!.generalSettings),
2023-10-29 02:47:14 +01:00
surfaceTintColor: isDesktop(width) ? Colors.transparent : null,
2023-05-21 14:52:35 +02:00
),
2023-12-09 04:04:14 +01:00
body: SafeArea(
child: ListView(
children: [
SectionLabel(label: AppLocalizations.of(context)!.home),
CustomListTile(
icon: Icons.exposure_zero_rounded,
title: AppLocalizations.of(context)!.hideZeroValues,
subtitle: AppLocalizations.of(context)!.hideZeroValuesDescription,
trailing: Switch(
value: appConfigProvider.hideZeroValues,
onChanged: (value) => updateSettings(
newStatus: value,
function: appConfigProvider.setHideZeroValues
),
),
onTap: () => updateSettings(
newStatus: !appConfigProvider.hideZeroValues,
2023-05-21 14:52:35 +02:00
function: appConfigProvider.setHideZeroValues
),
2023-12-09 04:04:14 +01:00
padding: const EdgeInsets.only(
top: 10,
bottom: 10,
left: 16,
right: 10
)
2023-05-21 14:52:35 +02:00
),
2023-12-09 04:04:14 +01:00
CustomListTile(
icon: Icons.show_chart_rounded,
title: AppLocalizations.of(context)!.combinedChart,
subtitle: AppLocalizations.of(context)!.combinedChartDescription,
trailing: Switch(
value: appConfigProvider.combinedChartHome,
onChanged: (value) => updateSettings(
newStatus: value,
function: appConfigProvider.setCombinedChartHome
),
),
onTap: () => updateSettings(
newStatus: !appConfigProvider.combinedChartHome,
2023-05-21 14:52:35 +02:00
function: appConfigProvider.setCombinedChartHome
),
2023-12-09 04:04:14 +01:00
padding: const EdgeInsets.only(
top: 10,
bottom: 10,
left: 16,
right: 10
)
2023-05-21 14:52:35 +02:00
),
2023-12-09 04:04:14 +01:00
CustomListTile(
icon: Icons.remove_red_eye_rounded,
title: AppLocalizations.of(context)!.hideServerAddress,
subtitle: AppLocalizations.of(context)!.hideServerAddressDescription,
trailing: Switch(
value: appConfigProvider.hideServerAddress,
onChanged: (value) => updateSettings(
newStatus: value,
function: appConfigProvider.setHideServerAddress
),
),
onTap: () => updateSettings(
newStatus: !appConfigProvider.hideServerAddress,
2023-09-09 21:25:21 +02:00
function: appConfigProvider.setHideServerAddress
),
2023-12-09 04:04:14 +01:00
padding: const EdgeInsets.only(
top: 10,
bottom: 10,
left: 16,
right: 10
)
2023-09-09 21:25:21 +02:00
),
2023-12-09 04:04:14 +01:00
CustomListTile(
icon: Icons.reorder_rounded,
title: AppLocalizations.of(context)!.topItemsOrder,
subtitle: AppLocalizations.of(context)!.topItemsOrderDescription,
onTap: () => widget.splitView == true
2024-03-10 21:15:24 +01:00
? Navigator.of(settingsNavigatorKey.currentContext!).push(
MaterialPageRoute(builder: (ctx) => const TopItemsListSettings())
)
2023-12-09 04:04:14 +01:00
: Navigator.of(context).push(
MaterialPageRoute(
2024-02-07 19:46:35 +01:00
builder: (context) => const TopItemsListSettings()
2023-12-09 04:04:14 +01:00
)
)
2023-09-09 21:25:21 +02:00
),
2023-12-09 04:04:14 +01:00
SectionLabel(label: AppLocalizations.of(context)!.logs),
CustomListTile(
icon: Icons.timer_rounded,
title: AppLocalizations.of(context)!.timeLogs,
subtitle: AppLocalizations.of(context)!.timeLogsDescription,
trailing: Switch(
value: appConfigProvider.showTimeLogs,
onChanged: (value) => updateSettings(
newStatus: value,
function: appConfigProvider.setshowTimeLogs
),
),
onTap: () => updateSettings(
newStatus: !appConfigProvider.showTimeLogs,
2023-05-21 14:52:35 +02:00
function: appConfigProvider.setshowTimeLogs
),
2023-12-09 04:04:14 +01:00
padding: const EdgeInsets.only(
top: 10,
bottom: 10,
left: 16,
right: 10
)
2023-05-21 14:52:35 +02:00
),
2023-12-09 04:04:14 +01:00
CustomListTile(
icon: Icons.more,
title: AppLocalizations.of(context)!.ipLogs,
subtitle: AppLocalizations.of(context)!.ipLogsDescription,
trailing: Switch(
value: appConfigProvider.showIpLogs,
onChanged: (value) => updateSettings(
newStatus: value,
function: appConfigProvider.setShowIpLogs
),
),
onTap: () => updateSettings(
newStatus: !appConfigProvider.showIpLogs,
2023-05-21 14:52:35 +02:00
function: appConfigProvider.setShowIpLogs
),
2023-12-09 04:04:14 +01:00
padding: const EdgeInsets.only(
top: 10,
bottom: 10,
left: 16,
right: 10
)
2023-05-21 14:52:35 +02:00
),
// if (!(Platform.isAndroid || Platform.isIOS) || (Platform.isAndroid && (appConfigProvider.installationSource == InstallationAppReferrer.androidManually ))) ...[
// SectionLabel(label: AppLocalizations.of(context)!.application),
// CustomListTile(
// icon: Icons.system_update_rounded,
// title: AppLocalizations.of(context)!.appUpdates,
// subtitle: appConfigProvider.appUpdatesAvailable != null
// ? AppLocalizations.of(context)!.updateAvailable
// : AppLocalizations.of(context)!.usingLatestVersion,
// trailing: generateAppUpdateStatus()
// )
// ]
2023-12-09 04:04:14 +01:00
],
),
2023-05-18 13:54:50 +02:00
)
);
}
}