2022-09-27 22:49:58 +02:00
|
|
|
// ignore_for_file: use_build_context_synchronously
|
|
|
|
|
2022-09-27 18:42:23 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
|
2022-10-03 22:41:19 +02:00
|
|
|
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
2022-09-27 18:42:23 +02:00
|
|
|
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
|
|
|
|
2022-09-28 01:43:29 +02:00
|
|
|
class ManagementModal extends StatelessWidget {
|
2022-09-27 18:42:23 +02:00
|
|
|
const ManagementModal({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final serversProvider = Provider.of<ServersProvider>(context);
|
2022-10-03 22:41:19 +02:00
|
|
|
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
2022-09-27 18:42:23 +02:00
|
|
|
|
2022-09-27 22:49:58 +02:00
|
|
|
void updateBlocking(bool value, String filter) async {
|
|
|
|
final result = await serversProvider.updateBlocking(
|
|
|
|
serversProvider.selectedServer!,
|
|
|
|
filter,
|
|
|
|
value
|
|
|
|
);
|
2022-10-03 22:41:19 +02:00
|
|
|
if (result != null ) {
|
|
|
|
if (result != false) {
|
|
|
|
appConfigProvider.addLog(result['log']);
|
|
|
|
}
|
2022-09-27 22:49:58 +02:00
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
SnackBar(
|
|
|
|
content: Text(AppLocalizations.of(context)!.invalidUsernamePassword),
|
|
|
|
backgroundColor: Colors.red,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-27 18:42:23 +02:00
|
|
|
Widget mainSwitch() {
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
|
|
|
child: Material(
|
|
|
|
color: Theme.of(context).primaryColor.withOpacity(0.1),
|
|
|
|
borderRadius: BorderRadius.circular(28),
|
|
|
|
child: InkWell(
|
2022-09-28 01:43:29 +02:00
|
|
|
onTap: serversProvider.protectionsManagementProcess.contains('general') == false
|
2022-09-27 22:49:58 +02:00
|
|
|
? () => updateBlocking(!serversProvider.serverStatus.data!.generalEnabled, 'general')
|
|
|
|
: null,
|
2022-09-27 18:42:23 +02:00
|
|
|
borderRadius: BorderRadius.circular(28),
|
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 20,
|
|
|
|
vertical: 12
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
AppLocalizations.of(context)!.allProtections,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 18,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Switch(
|
|
|
|
value: serversProvider.serverStatus.data!.generalEnabled,
|
2022-09-28 01:43:29 +02:00
|
|
|
onChanged: serversProvider.protectionsManagementProcess.contains('general') == false
|
2022-09-27 22:49:58 +02:00
|
|
|
? (value) => updateBlocking(value, 'general')
|
|
|
|
: null,
|
2022-09-27 18:42:23 +02:00
|
|
|
activeColor: Theme.of(context).primaryColor,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-09-27 22:49:58 +02:00
|
|
|
Widget smallSwitch(String label, IconData icon, bool value, Function(bool) onChange, bool disabled) {
|
2022-09-27 18:42:23 +02:00
|
|
|
return Material(
|
|
|
|
color: Colors.transparent,
|
|
|
|
child: InkWell(
|
2022-09-27 22:49:58 +02:00
|
|
|
onTap: disabled == false
|
|
|
|
? () => onChange(!value)
|
|
|
|
: null,
|
2022-09-27 18:42:23 +02:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(
|
|
|
|
horizontal: 35,
|
|
|
|
vertical: 5
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
2022-09-27 22:49:58 +02:00
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
icon,
|
|
|
|
size: 24,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 20),
|
|
|
|
Text(
|
|
|
|
label,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 15,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
2022-09-27 18:42:23 +02:00
|
|
|
),
|
|
|
|
Switch(
|
|
|
|
value: value,
|
2022-09-27 22:49:58 +02:00
|
|
|
onChanged: disabled == false
|
|
|
|
? onChange
|
|
|
|
: null,
|
2022-09-27 18:42:23 +02:00
|
|
|
activeColor: Theme.of(context).primaryColor,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
width: double.maxFinite,
|
|
|
|
height: 540,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context).dialogBackgroundColor,
|
|
|
|
borderRadius: const BorderRadius.only(
|
|
|
|
topLeft: Radius.circular(28),
|
|
|
|
topRight: Radius.circular(28)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Column(
|
|
|
|
children: [
|
|
|
|
const Padding(
|
|
|
|
padding: EdgeInsets.only(top: 24),
|
|
|
|
child: Icon(
|
2022-09-27 22:49:58 +02:00
|
|
|
Icons.shield_rounded,
|
2022-09-27 18:42:23 +02:00
|
|
|
size: 26,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 24),
|
|
|
|
child: Text(
|
|
|
|
AppLocalizations.of(context)!.manageServer,
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 22
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
mainSwitch(),
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
smallSwitch(
|
|
|
|
AppLocalizations.of(context)!.ruleFiltering,
|
2022-09-27 22:49:58 +02:00
|
|
|
Icons.filter_list_rounded,
|
|
|
|
serversProvider.serverStatus.data!.filteringEnabled,
|
|
|
|
(value) => updateBlocking(value, 'filtering'),
|
2022-09-28 01:43:29 +02:00
|
|
|
serversProvider.protectionsManagementProcess.contains('filtering')
|
2022-09-27 18:42:23 +02:00
|
|
|
),
|
|
|
|
smallSwitch(
|
|
|
|
AppLocalizations.of(context)!.safeBrowsing,
|
2022-09-27 22:49:58 +02:00
|
|
|
Icons.vpn_lock_rounded,
|
|
|
|
serversProvider.serverStatus.data!.safeBrowsingEnabled,
|
|
|
|
(value) => updateBlocking(value, 'safeBrowsing'),
|
2022-09-28 01:43:29 +02:00
|
|
|
serversProvider.protectionsManagementProcess.contains('safeBrowsing')
|
2022-09-27 18:42:23 +02:00
|
|
|
),
|
|
|
|
smallSwitch(
|
|
|
|
AppLocalizations.of(context)!.parentalFiltering,
|
2022-09-27 22:49:58 +02:00
|
|
|
Icons.block,
|
|
|
|
serversProvider.serverStatus.data!.parentalControlEnabled,
|
|
|
|
(value) => updateBlocking(value, 'parentalControl'),
|
2022-09-28 01:43:29 +02:00
|
|
|
serversProvider.protectionsManagementProcess.contains('parentalControl')
|
2022-09-27 18:42:23 +02:00
|
|
|
),
|
|
|
|
smallSwitch(
|
|
|
|
AppLocalizations.of(context)!.safeSearch,
|
2022-09-27 22:49:58 +02:00
|
|
|
Icons.search_rounded,
|
|
|
|
serversProvider.serverStatus.data!.safeSearchEnabled,
|
|
|
|
(value) => updateBlocking(value, 'safeSearch'),
|
2022-09-28 01:43:29 +02:00
|
|
|
serversProvider.protectionsManagementProcess.contains('safeSearch')
|
2022-09-27 18:42:23 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(24),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
child: Text(AppLocalizations.of(context)!.close),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|