adguard-home-manager/lib/screens/clients/client/client_form.dart

298 lines
12 KiB
Dart
Raw Normal View History

2023-11-01 15:43:19 +01:00
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:adguard_home_manager/screens/clients/client/blocked_services_section.dart';
import 'package:adguard_home_manager/screens/clients/client/client_screen.dart';
import 'package:adguard_home_manager/screens/clients/client/client_screen_functions.dart';
import 'package:adguard_home_manager/screens/clients/client/identifiers_section.dart';
import 'package:adguard_home_manager/screens/clients/client/settings_tile.dart';
import 'package:adguard_home_manager/screens/clients/client/tags_section.dart';
import 'package:adguard_home_manager/screens/clients/client/upstream_servers_section.dart';
2024-01-25 22:34:30 +01:00
import 'package:adguard_home_manager/screens/clients/client/blocking_schedule.dart';
2023-11-01 15:43:19 +01:00
import 'package:adguard_home_manager/widgets/custom_switch_list_tile.dart';
2023-11-01 15:43:19 +01:00
import 'package:adguard_home_manager/widgets/custom_list_tile.dart';
import 'package:adguard_home_manager/widgets/section_label.dart';
import 'package:adguard_home_manager/models/clients.dart';
import 'package:adguard_home_manager/models/safe_search.dart';
class ClientForm extends StatelessWidget {
final bool isFullScreen;
final Client? client;
final TextEditingController nameController;
final List<ControllerListItem> identifiersControllers;
final List<String> selectedTags;
final bool useGlobalSettingsFiltering;
final bool? enableFiltering;
final bool? enableSafeBrowsing;
final bool? enableParentalControl;
final bool? enableSafeSearch;
final SafeSearch? safeSearch;
final SafeSearch defaultSafeSearch;
final bool useGlobalSettingsServices;
final List<String> blockedServices;
final void Function(List<String>) updateBlockedServices;
final List<ControllerListItem> upstreamServers;
final void Function(List<ControllerListItem>) updateUpstreamServers;
final void Function(List<String>) updateSelectedTags;
final void Function(List<ControllerListItem>) updateIdentifiersControllers;
final void Function() enableDisableGlobalSettingsFiltering;
final void Function(bool) updateEnableFiltering;
final void Function(bool) updateEnableSafeBrowsing;
final void Function(bool) updateEnableParentalControl;
final void Function(bool) updateEnableSafeSearch;
final void Function(SafeSearch) updateSafeSearch;
final void Function(bool) updateUseGlobalSettingsServices;
final bool ignoreClientQueryLog;
final void Function(bool) updateIgnoreClientQueryLog;
final bool ignoreClientStatistics;
final void Function(bool) updateIgnoreClientStatistics;
final bool enableDnsCache;
final void Function(bool) updateEnableDnsCache;
final TextEditingController dnsCacheField;
final String? dnsCacheError;
final void Function(String?) updateDnsCacheError;
2024-01-25 22:34:30 +01:00
final BlockedServicesSchedule blockedServicesSchedule;
final void Function(BlockedServicesSchedule) setBlockedServicesSchedule;
2023-11-01 15:43:19 +01:00
const ClientForm({
2023-11-29 11:56:28 +01:00
super.key,
2023-11-01 15:43:19 +01:00
required this.isFullScreen,
required this.client,
required this.nameController,
required this.identifiersControllers,
required this.selectedTags,
required this.useGlobalSettingsFiltering,
required this.enableFiltering,
required this.enableParentalControl,
required this.enableSafeBrowsing,
required this.enableSafeSearch,
required this.safeSearch,
required this.blockedServices,
required this.updateBlockedServices,
required this.upstreamServers,
required this.updateUpstreamServers,
required this.defaultSafeSearch,
required this.useGlobalSettingsServices,
required this.updateSelectedTags,
required this.updateIdentifiersControllers,
required this.enableDisableGlobalSettingsFiltering,
required this.updateEnableFiltering,
required this.updateEnableParentalControl,
required this.updateEnableSafeBrowsing,
required this.updateEnableSafeSearch,
required this.updateSafeSearch,
required this.updateUseGlobalSettingsServices,
required this.ignoreClientQueryLog,
required this.ignoreClientStatistics,
required this.updateIgnoreClientQueryLog,
required this.updateIgnoreClientStatistics,
required this.enableDnsCache,
required this.updateEnableDnsCache,
required this.dnsCacheField,
required this.dnsCacheError,
required this.updateDnsCacheError,
2024-01-25 22:34:30 +01:00
required this.blockedServicesSchedule,
required this.setBlockedServicesSchedule,
2023-11-29 11:56:28 +01:00
});
2023-11-01 15:43:19 +01:00
@override
Widget build(BuildContext context) {
return Column(
2023-11-01 15:43:19 +01:00
children: [
const SizedBox(height: 8),
2023-11-01 15:43:19 +01:00
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
2023-11-01 15:43:19 +01:00
child: TextFormField(
enabled: client != null ? false : true,
controller: nameController,
onChanged: (_) => {},
2023-11-01 15:43:19 +01:00
decoration: InputDecoration(
prefixIcon: const Icon(Icons.badge_rounded),
border: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10)
)
),
labelText: AppLocalizations.of(context)!.name,
),
),
),
SectionLabel(
label: AppLocalizations.of(context)!.tags,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
2023-11-01 15:43:19 +01:00
),
TagsSection(
selectedTags: selectedTags,
onTagsSelected: updateSelectedTags
),
IdentifiersSection(
identifiersControllers: identifiersControllers,
onUpdateIdentifiersControllers: (c) {
updateIdentifiersControllers(c);
},
onCheckValidValues: () => {}
2023-11-01 15:43:19 +01:00
),
SectionLabel(
label: AppLocalizations.of(context)!.settings,
padding: const EdgeInsets.only(
left: 16, right: 16, top: 12, bottom: 24
2023-11-01 15:43:19 +01:00
)
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
2023-11-01 15:43:19 +01:00
child: Material(
color: Theme.of(context).colorScheme.primary.withOpacity(0.1),
borderRadius: BorderRadius.circular(28),
child: InkWell(
onTap: enableDisableGlobalSettingsFiltering,
borderRadius: BorderRadius.circular(28),
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 6
2023-11-01 15:43:19 +01:00
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
2023-11-29 11:56:28 +01:00
Flexible(
child: Text(
AppLocalizations.of(context)!.useGlobalSettings,
style: TextStyle(
fontSize: 16,
color: Theme.of(context).colorScheme.onSurface
),
2023-11-01 15:43:19 +01:00
),
),
Switch(
value: useGlobalSettingsFiltering,
onChanged: (value) => enableDisableGlobalSettingsFiltering()
)
],
),
),
),
),
),
const SizedBox(height: 8),
2023-11-01 15:43:19 +01:00
SettingsTile(
label: AppLocalizations.of(context)!.enableFiltering,
value: enableFiltering,
onChange: (value) => updateEnableFiltering(value),
useGlobalSettingsFiltering: useGlobalSettingsFiltering,
),
SettingsTile(
label: AppLocalizations.of(context)!.enableSafeBrowsing,
value: enableSafeBrowsing,
onChange: (value) => updateEnableSafeBrowsing(value),
useGlobalSettingsFiltering: useGlobalSettingsFiltering,
),
SettingsTile(
label: AppLocalizations.of(context)!.enableParentalControl,
value: enableParentalControl,
onChange: (value) => updateEnableParentalControl(value),
useGlobalSettingsFiltering: useGlobalSettingsFiltering,
),
2023-11-20 02:26:53 +01:00
CustomListTile(
2023-11-01 15:43:19 +01:00
title: AppLocalizations.of(context)!.safeSearch,
padding: const EdgeInsets.symmetric(
horizontal: 34,
2023-11-01 15:43:19 +01:00
vertical: 16
),
trailing: Padding(
padding: const EdgeInsets.only(right: 16),
child: Icon(
Icons.chevron_right_rounded,
color: useGlobalSettingsFiltering == true
? Colors.grey
: Theme.of(context).colorScheme.onSurfaceVariant,
),
),
onTap: useGlobalSettingsFiltering == false
? () => openSafeSearchModal(
context: context,
blockedServices: blockedServices,
defaultSafeSearch: defaultSafeSearch,
safeSearch: safeSearch,
onUpdateSafeSearch: updateSafeSearch
)
: null,
),
SectionLabel(
label: AppLocalizations.of(context)!.queryLogsAndStatistics,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
),
CustomSwitchListTile(
title: AppLocalizations.of(context)!.ignoreClientQueryLog,
value: ignoreClientQueryLog,
onChanged: updateIgnoreClientQueryLog,
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 6
),
),
CustomSwitchListTile(
title: AppLocalizations.of(context)!.ignoreClientStatistics,
value: ignoreClientStatistics,
onChanged: updateIgnoreClientStatistics,
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 6
),
),
2023-11-01 15:43:19 +01:00
SectionLabel(
label: AppLocalizations.of(context)!.blockedServices,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
2023-11-01 15:43:19 +01:00
),
BlockedServicesSection(
useGlobalSettingsServices: useGlobalSettingsServices,
blockedServices: blockedServices,
onUpdatedBlockedServices: updateBlockedServices,
onUpdateServicesGlobalSettings: updateUseGlobalSettingsServices,
),
UpstreamServersSection(
upstreamServers: upstreamServers,
onCheckValidValues: () => {},
2023-11-01 15:43:19 +01:00
onUpdateUpstreamServers: updateUpstreamServers
),
SectionLabel(
label: AppLocalizations.of(context)!.upstreamDnsCacheConfiguration,
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
),
CustomSwitchListTile(
title: AppLocalizations.of(context)!.enableDnsCachingClient,
value: enableDnsCache,
onChanged: updateEnableDnsCache,
padding: const EdgeInsets.symmetric(
horizontal: 16,
vertical: 6
),
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 24),
child: TextFormField(
controller: dnsCacheField,
onChanged: (v) => updateDnsCacheError(!validateNumber(v) ? AppLocalizations.of(context)!.invalidValue : null),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.storage_rounded),
border: const OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(10)
)
),
labelText: AppLocalizations.of(context)!.dnsCacheSize,
errorText: dnsCacheError
),
keyboardType: TextInputType.number,
),
),
2024-01-25 22:34:30 +01:00
BlockingSchedule(
blockedServicesSchedule: blockedServicesSchedule,
setBlockedServicesSchedule: setBlockedServicesSchedule,
),
const SizedBox(height: 16),
2023-11-01 15:43:19 +01:00
],
);
}
}