2023-04-30 23:39:56 +02:00
|
|
|
import 'dart:io';
|
|
|
|
|
2022-09-26 13:51:18 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-09-27 15:43:52 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2022-10-04 16:09:50 +02:00
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
2022-09-27 15:43:52 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
|
2022-10-10 01:26:33 +02:00
|
|
|
import 'package:adguard_home_manager/screens/settings/server_info/server_info.dart';
|
2022-10-22 23:06:27 +02:00
|
|
|
import 'package:adguard_home_manager/screens/settings/encryption/encryption.dart';
|
2024-01-24 13:55:15 +01:00
|
|
|
import 'package:adguard_home_manager/screens/settings/logs_settings/logs_settings.dart';
|
2022-10-10 01:26:33 +02:00
|
|
|
import 'package:adguard_home_manager/screens/settings/access_settings/access_settings.dart';
|
2022-10-26 14:26:09 +02:00
|
|
|
import 'package:adguard_home_manager/screens/settings/customization/customization.dart';
|
2022-10-12 03:58:17 +02:00
|
|
|
import 'package:adguard_home_manager/screens/settings/dhcp/dhcp.dart';
|
2024-01-28 20:39:42 +01:00
|
|
|
import 'package:adguard_home_manager/screens/settings/statistics_settings/statistics_settings.dart';
|
2023-04-14 01:40:40 +02:00
|
|
|
import 'package:adguard_home_manager/screens/settings/safe_search_settings.dart';
|
2024-02-21 02:34:36 +01:00
|
|
|
import 'package:adguard_home_manager/screens/settings/update_server/update_screen.dart';
|
2022-10-19 14:12:53 +02:00
|
|
|
import 'package:adguard_home_manager/screens/settings/dns/dns.dart';
|
2022-10-15 14:47:32 +02:00
|
|
|
import 'package:adguard_home_manager/screens/settings/dns_rewrites/dns_rewrites.dart';
|
2022-09-27 18:06:49 +02:00
|
|
|
import 'package:adguard_home_manager/screens/servers/servers.dart';
|
2022-10-04 15:43:16 +02:00
|
|
|
import 'package:adguard_home_manager/screens/settings/advanced_setings.dart';
|
2023-09-09 23:30:53 +02:00
|
|
|
import 'package:adguard_home_manager/screens/settings/general_settings/general_settings.dart';
|
2022-09-27 15:43:52 +02:00
|
|
|
|
2023-04-30 22:54:39 +02:00
|
|
|
import 'package:adguard_home_manager/widgets/custom_settings_tile.dart';
|
|
|
|
import 'package:adguard_home_manager/widgets/section_label.dart';
|
2022-10-22 23:06:27 +02:00
|
|
|
import 'package:adguard_home_manager/widgets/custom_list_tile.dart';
|
|
|
|
|
2023-10-29 02:19:00 +01:00
|
|
|
import 'package:adguard_home_manager/functions/desktop_mode.dart';
|
2022-10-04 16:09:50 +02:00
|
|
|
import 'package:adguard_home_manager/constants/strings.dart';
|
2023-04-06 22:56:32 +02:00
|
|
|
import 'package:adguard_home_manager/functions/open_url.dart';
|
2022-10-04 16:09:50 +02:00
|
|
|
import 'package:adguard_home_manager/constants/urls.dart';
|
2023-05-24 13:51:22 +02:00
|
|
|
import 'package:adguard_home_manager/providers/status_provider.dart';
|
2022-09-27 18:06:49 +02:00
|
|
|
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
2022-09-27 15:43:52 +02:00
|
|
|
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
2023-05-02 13:42:01 +02:00
|
|
|
|
2024-03-10 21:15:24 +01:00
|
|
|
final settingsNavigatorKey = GlobalKey<NavigatorState>();
|
|
|
|
|
2022-09-26 13:51:18 +02:00
|
|
|
class Settings extends StatelessWidget {
|
2023-12-01 02:03:13 +01:00
|
|
|
const Settings({super.key});
|
2022-09-26 13:51:18 +02:00
|
|
|
|
2023-04-30 22:54:39 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-10-29 02:19:00 +01:00
|
|
|
return LayoutBuilder(
|
|
|
|
builder: (context, constraints) {
|
|
|
|
if (constraints.maxWidth > 900) {
|
2024-03-10 21:15:24 +01:00
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
const Expanded(
|
|
|
|
flex: 1,
|
|
|
|
child: _SettingsWidget(
|
|
|
|
twoColumns: true,
|
|
|
|
)
|
2023-05-02 13:42:01 +02:00
|
|
|
),
|
2024-03-10 21:15:24 +01:00
|
|
|
Expanded(
|
|
|
|
flex: 2,
|
|
|
|
child: Navigator(
|
|
|
|
key: settingsNavigatorKey,
|
|
|
|
onGenerateRoute: (settings) => MaterialPageRoute(builder: (ctx) => const SizedBox()),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
2023-10-29 02:19:00 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
2023-12-01 02:03:13 +01:00
|
|
|
return const _SettingsWidget(
|
2023-10-29 02:19:00 +01:00
|
|
|
twoColumns: false,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
2023-04-30 22:54:39 +02:00
|
|
|
}
|
|
|
|
}
|
2023-12-01 02:03:13 +01:00
|
|
|
class _SettingsWidget extends StatefulWidget {
|
2023-10-29 02:19:00 +01:00
|
|
|
final bool twoColumns;
|
|
|
|
|
2023-12-01 02:03:13 +01:00
|
|
|
const _SettingsWidget({
|
2023-10-29 02:19:00 +01:00
|
|
|
required this.twoColumns,
|
2023-12-01 02:03:13 +01:00
|
|
|
});
|
2023-04-30 22:54:39 +02:00
|
|
|
|
2023-10-29 15:38:17 +01:00
|
|
|
@override
|
2023-12-01 02:03:13 +01:00
|
|
|
State<_SettingsWidget> createState() => _SettingsWidgetState();
|
2023-10-29 15:38:17 +01:00
|
|
|
}
|
|
|
|
|
2023-12-01 02:03:13 +01:00
|
|
|
class _SettingsWidgetState extends State<_SettingsWidget> {
|
2024-02-29 14:44:10 +01:00
|
|
|
final _scaffoldMessengerKey = GlobalKey<ScaffoldMessengerState>();
|
2024-02-09 03:00:42 +01:00
|
|
|
|
2023-10-29 15:38:17 +01:00
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
Provider.of<AppConfigProvider>(context, listen: false).setSelectedSettingsScreen(screen: null);
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
2022-09-26 13:51:18 +02:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-09-27 18:06:49 +02:00
|
|
|
final serversProvider = Provider.of<ServersProvider>(context);
|
2023-05-24 13:51:22 +02:00
|
|
|
final statusProvider = Provider.of<StatusProvider>(context);
|
|
|
|
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
2022-09-27 15:43:52 +02:00
|
|
|
|
2023-04-30 22:54:39 +02:00
|
|
|
final width = MediaQuery.of(context).size.width;
|
|
|
|
|
2023-10-29 15:38:17 +01:00
|
|
|
if (!widget.twoColumns && appConfigProvider.selectedSettingsScreen != null) {
|
2023-05-02 13:42:01 +02:00
|
|
|
appConfigProvider.setSelectedSettingsScreen(screen: null);
|
|
|
|
}
|
|
|
|
|
2024-01-29 15:04:52 +01:00
|
|
|
return ScaffoldMessenger(
|
2024-02-29 14:44:10 +01:00
|
|
|
key: widget.twoColumns ? _scaffoldMessengerKey : null,
|
2024-01-29 15:04:52 +01:00
|
|
|
child: Scaffold(
|
|
|
|
body: NestedScrollView(
|
|
|
|
headerSliverBuilder: (context, innerBoxIsScrolled) => [
|
|
|
|
SliverOverlapAbsorber(
|
|
|
|
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
|
|
|
sliver: SliverAppBar.large(
|
|
|
|
pinned: true,
|
|
|
|
floating: true,
|
|
|
|
centerTitle: false,
|
|
|
|
forceElevated: innerBoxIsScrolled,
|
|
|
|
surfaceTintColor: isDesktop(width) ? Colors.transparent : null,
|
|
|
|
title: Text(AppLocalizations.of(context)!.settings),
|
|
|
|
)
|
2023-05-18 13:54:50 +02:00
|
|
|
)
|
2024-01-29 15:04:52 +01:00
|
|
|
],
|
|
|
|
body: SafeArea(
|
|
|
|
top: false,
|
|
|
|
bottom: false,
|
|
|
|
child: Builder(
|
|
|
|
builder: (context) => CustomScrollView(
|
|
|
|
slivers: [
|
|
|
|
SliverOverlapInjector(
|
|
|
|
handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
|
|
|
|
),
|
|
|
|
SliverList.list(
|
|
|
|
children: [
|
|
|
|
if (
|
|
|
|
serversProvider.selectedServer != null &&
|
|
|
|
statusProvider.serverStatus != null &&
|
|
|
|
serversProvider.apiClient2 != null
|
|
|
|
) ...[
|
|
|
|
SectionLabel(label: AppLocalizations.of(context)!.serverSettings),
|
|
|
|
_SettingsTile(
|
|
|
|
icon: Icons.search_rounded,
|
|
|
|
title: AppLocalizations.of(context)!.safeSearch,
|
|
|
|
subtitle: AppLocalizations.of(context)!.safeSearchSettings,
|
|
|
|
thisItem: 0,
|
|
|
|
screenToNavigate: const SafeSearchSettingsScreen(),
|
|
|
|
twoColumns: widget.twoColumns,
|
|
|
|
),
|
|
|
|
_SettingsTile(
|
|
|
|
icon: Icons.list_alt_rounded,
|
|
|
|
title: AppLocalizations.of(context)!.logsSettings,
|
|
|
|
subtitle: AppLocalizations.of(context)!.logsSettingsDescription,
|
|
|
|
thisItem: 1,
|
|
|
|
screenToNavigate: const LogsSettings(),
|
|
|
|
twoColumns: widget.twoColumns,
|
|
|
|
),
|
|
|
|
_SettingsTile(
|
|
|
|
icon: Icons.analytics_rounded,
|
|
|
|
title: AppLocalizations.of(context)!.statisticsSettings,
|
|
|
|
subtitle: AppLocalizations.of(context)!.statisticsSettingsDescription,
|
|
|
|
thisItem: 2,
|
|
|
|
screenToNavigate: const StatisticsSettings(),
|
|
|
|
twoColumns: widget.twoColumns,
|
|
|
|
),
|
|
|
|
_SettingsTile(
|
|
|
|
icon: Icons.lock_rounded,
|
|
|
|
title: AppLocalizations.of(context)!.accessSettings,
|
|
|
|
subtitle: AppLocalizations.of(context)!.accessSettingsDescription,
|
|
|
|
thisItem: 3,
|
|
|
|
screenToNavigate: const AccessSettings(),
|
|
|
|
twoColumns: widget.twoColumns,
|
|
|
|
),
|
|
|
|
_SettingsTile(
|
|
|
|
icon: Icons.install_desktop_rounded,
|
|
|
|
title: AppLocalizations.of(context)!.dhcpSettings,
|
|
|
|
subtitle: AppLocalizations.of(context)!.dhcpSettingsDescription,
|
|
|
|
thisItem: 4,
|
|
|
|
screenToNavigate: const DhcpScreen(),
|
|
|
|
twoColumns: widget.twoColumns,
|
|
|
|
),
|
|
|
|
_SettingsTile(
|
|
|
|
icon: Icons.dns_rounded,
|
|
|
|
title: AppLocalizations.of(context)!.dnsSettings,
|
|
|
|
subtitle: AppLocalizations.of(context)!.dnsSettingsDescription,
|
|
|
|
thisItem: 5,
|
|
|
|
screenToNavigate: DnsSettings(
|
|
|
|
splitView: widget.twoColumns,
|
|
|
|
),
|
|
|
|
twoColumns: widget.twoColumns,
|
|
|
|
),
|
|
|
|
_SettingsTile(
|
|
|
|
icon: Icons.security_rounded,
|
|
|
|
title: AppLocalizations.of(context)!.encryptionSettings,
|
|
|
|
subtitle: AppLocalizations.of(context)!.encryptionSettingsDescription,
|
|
|
|
thisItem: 6,
|
|
|
|
screenToNavigate: const EncryptionSettings(),
|
|
|
|
twoColumns: widget.twoColumns,
|
|
|
|
),
|
|
|
|
_SettingsTile(
|
|
|
|
icon: Icons.route_rounded,
|
|
|
|
title: AppLocalizations.of(context)!.dnsRewrites,
|
|
|
|
subtitle: AppLocalizations.of(context)!.dnsRewritesDescription,
|
|
|
|
thisItem: 7,
|
|
|
|
screenToNavigate: const DnsRewritesScreen(),
|
|
|
|
twoColumns: widget.twoColumns,
|
|
|
|
),
|
|
|
|
if (serversProvider.updateAvailable.data != null) _SettingsTile(
|
|
|
|
icon: Icons.system_update_rounded,
|
|
|
|
title: AppLocalizations.of(context)!.updates,
|
|
|
|
subtitle: AppLocalizations.of(context)!.updatesDescription,
|
|
|
|
trailing: serversProvider.updateAvailable.data != null &&
|
|
|
|
serversProvider.updateAvailable.data!.canAutoupdate == true
|
|
|
|
? Container(
|
|
|
|
width: 10,
|
|
|
|
height: 10,
|
|
|
|
margin: const EdgeInsets.only(right: 12),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(20),
|
|
|
|
color: Colors.red
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
thisItem: 8,
|
|
|
|
screenToNavigate: const UpdateScreen(),
|
|
|
|
twoColumns: widget.twoColumns,
|
|
|
|
),
|
|
|
|
_SettingsTile(
|
|
|
|
icon: Icons.info_rounded,
|
|
|
|
title: AppLocalizations.of(context)!.serverInformation,
|
|
|
|
subtitle: AppLocalizations.of(context)!.serverInformationDescription,
|
|
|
|
thisItem: 9,
|
|
|
|
screenToNavigate: const ServerInformation(),
|
|
|
|
twoColumns: widget.twoColumns,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
SectionLabel(label: AppLocalizations.of(context)!.appSettings),
|
2023-12-01 02:03:13 +01:00
|
|
|
_SettingsTile(
|
2024-01-29 15:04:52 +01:00
|
|
|
icon: Icons.palette_rounded,
|
|
|
|
title: AppLocalizations.of(context)!.customization,
|
|
|
|
subtitle: AppLocalizations.of(context)!.customizationDescription,
|
|
|
|
thisItem: 10,
|
|
|
|
screenToNavigate: const Customization(),
|
2023-12-01 02:03:13 +01:00
|
|
|
twoColumns: widget.twoColumns,
|
2023-10-24 21:28:57 +02:00
|
|
|
),
|
2023-12-01 02:03:13 +01:00
|
|
|
_SettingsTile(
|
2024-01-29 15:04:52 +01:00
|
|
|
icon: Icons.storage_rounded,
|
|
|
|
title: AppLocalizations.of(context)!.servers,
|
|
|
|
subtitle: serversProvider.selectedServer != null
|
|
|
|
? statusProvider.serverStatus != null
|
|
|
|
? "${AppLocalizations.of(context)!.connectedTo} ${serversProvider.selectedServer!.name}"
|
|
|
|
: "${AppLocalizations.of(context)!.selectedServer} ${serversProvider.selectedServer!.name}"
|
|
|
|
: AppLocalizations.of(context)!.noServerSelected,
|
|
|
|
thisItem: 11,
|
|
|
|
screenToNavigate: const Servers(),
|
2023-12-01 02:03:13 +01:00
|
|
|
twoColumns: widget.twoColumns,
|
2023-10-24 21:28:57 +02:00
|
|
|
),
|
2023-12-01 02:03:13 +01:00
|
|
|
_SettingsTile(
|
2024-01-29 15:04:52 +01:00
|
|
|
icon: Icons.settings,
|
|
|
|
title: AppLocalizations.of(context)!.generalSettings,
|
|
|
|
subtitle: AppLocalizations.of(context)!.generalSettingsDescription,
|
|
|
|
thisItem: 12,
|
|
|
|
screenToNavigate: GeneralSettings(splitView: widget.twoColumns),
|
2023-12-01 02:03:13 +01:00
|
|
|
twoColumns: widget.twoColumns,
|
2023-10-24 21:28:57 +02:00
|
|
|
),
|
2023-12-01 02:03:13 +01:00
|
|
|
_SettingsTile(
|
2024-01-29 15:04:52 +01:00
|
|
|
icon: Icons.build_outlined,
|
|
|
|
title: AppLocalizations.of(context)!.advancedSettings,
|
|
|
|
subtitle: AppLocalizations.of(context)!.advancedSetupDescription,
|
|
|
|
thisItem: 13,
|
|
|
|
screenToNavigate: const AdvancedSettings(),
|
2023-12-01 02:03:13 +01:00
|
|
|
twoColumns: widget.twoColumns,
|
2023-10-24 21:28:57 +02:00
|
|
|
),
|
2024-01-29 15:04:52 +01:00
|
|
|
SectionLabel(label: AppLocalizations.of(context)!.aboutApp),
|
|
|
|
CustomListTile(
|
|
|
|
title: AppLocalizations.of(context)!.appVersion,
|
|
|
|
subtitle: appConfigProvider.getAppInfo!.version,
|
2023-10-24 21:28:57 +02:00
|
|
|
),
|
2024-01-29 15:04:52 +01:00
|
|
|
CustomListTile(
|
2025-01-21 20:55:54 +01:00
|
|
|
title: AppLocalizations.of(context)!.applicationDetails,
|
|
|
|
subtitle: AppLocalizations.of(context)!.applicationDetailsDescription,
|
|
|
|
trailing: Icon(Icons.open_in_new_rounded),
|
|
|
|
onTap: () => openUrl(Urls.appDetailsWebpage),
|
2023-10-24 21:28:57 +02:00
|
|
|
),
|
2025-01-21 20:55:54 +01:00
|
|
|
CustomListTile(
|
|
|
|
title: AppLocalizations.of(context)!.myOtherApps,
|
|
|
|
subtitle: AppLocalizations.of(context)!.myOtherAppsDescription,
|
|
|
|
trailing: Icon(Icons.open_in_new_rounded),
|
|
|
|
onTap: () => openUrl(Urls.jgeek00AppsWebpage),
|
|
|
|
),
|
|
|
|
SizedBox(height: 16)
|
2024-01-29 15:04:52 +01:00
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
),
|
2023-10-24 21:28:57 +02:00
|
|
|
),
|
2024-01-29 15:04:52 +01:00
|
|
|
)
|
|
|
|
),
|
2022-09-27 15:43:52 +02:00
|
|
|
);
|
2022-09-26 13:51:18 +02:00
|
|
|
}
|
2023-12-01 02:03:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class _SettingsTile extends StatelessWidget {
|
|
|
|
final String title;
|
|
|
|
final String subtitle;
|
|
|
|
final IconData icon;
|
|
|
|
final Widget? trailing;
|
|
|
|
final Widget screenToNavigate;
|
|
|
|
final int thisItem;
|
|
|
|
final bool twoColumns;
|
|
|
|
|
|
|
|
const _SettingsTile({
|
|
|
|
required this.title,
|
|
|
|
required this.subtitle,
|
|
|
|
required this.icon,
|
|
|
|
this.trailing,
|
|
|
|
required this.screenToNavigate,
|
|
|
|
required this.thisItem,
|
|
|
|
required this.twoColumns
|
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
|
|
|
|
|
|
|
if (twoColumns) {
|
|
|
|
return CustomSettingsTile(
|
|
|
|
title: title,
|
|
|
|
subtitle: subtitle,
|
|
|
|
icon: icon,
|
|
|
|
trailing: trailing,
|
|
|
|
thisItem: thisItem,
|
|
|
|
selectedItem: appConfigProvider.selectedSettingsScreen,
|
|
|
|
onTap: () {
|
|
|
|
appConfigProvider.setSelectedSettingsScreen(screen: thisItem, notify: true);
|
2024-03-10 21:15:24 +01:00
|
|
|
Navigator.of(settingsNavigatorKey.currentContext!).pushReplacement(
|
|
|
|
PageRouteBuilder(
|
|
|
|
pageBuilder: (context, animation1, animation2) => screenToNavigate,
|
|
|
|
transitionDuration: Duration.zero,
|
|
|
|
reverseTransitionDuration: Duration.zero,
|
|
|
|
),
|
|
|
|
);
|
2023-12-01 02:03:13 +01:00
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return CustomListTile(
|
|
|
|
title: title,
|
|
|
|
subtitle: subtitle,
|
|
|
|
icon: icon,
|
|
|
|
trailing: trailing,
|
|
|
|
onTap: () {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
MaterialPageRoute(builder: (context) => screenToNavigate)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-09-26 13:51:18 +02:00
|
|
|
}
|