2023-10-29 13:59:36 +01:00
|
|
|
// ignore_for_file: use_build_context_synchronously
|
|
|
|
|
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:expandable/expandable.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
|
|
|
|
import 'package:adguard_home_manager/screens/home/management_modal/main_switch.dart';
|
|
|
|
import 'package:adguard_home_manager/screens/home/management_modal/small_switch.dart';
|
|
|
|
|
|
|
|
import 'package:adguard_home_manager/functions/snackbar.dart';
|
|
|
|
import 'package:adguard_home_manager/providers/status_provider.dart';
|
|
|
|
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
|
|
|
|
|
|
|
class ManagementModal extends StatefulWidget {
|
|
|
|
final bool dialog;
|
|
|
|
|
|
|
|
const ManagementModal({
|
2023-12-09 04:04:14 +01:00
|
|
|
super.key,
|
2023-10-29 13:59:36 +01:00
|
|
|
required this.dialog
|
2023-12-09 04:04:14 +01:00
|
|
|
});
|
2023-10-29 13:59:36 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<ManagementModal> createState() => _ManagementModalState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _ManagementModalState extends State<ManagementModal> with SingleTickerProviderStateMixin {
|
|
|
|
late AnimationController animationController;
|
|
|
|
late Animation<double> animation;
|
|
|
|
final ExpandableController expandableController = ExpandableController();
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
expandableController.addListener(() async {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 200));
|
|
|
|
if (expandableController.value == false) {
|
|
|
|
animationController.animateTo(0);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
animationController.animateBack(1);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
animationController = AnimationController(
|
|
|
|
duration: const Duration(milliseconds: 200),
|
|
|
|
vsync: this,
|
|
|
|
)
|
|
|
|
..addListener(() => setState(() => {}));
|
|
|
|
animation = Tween(
|
|
|
|
begin: 0.0,
|
|
|
|
end: 0.5,
|
|
|
|
).animate(CurvedAnimation(
|
|
|
|
parent: animationController,
|
|
|
|
curve: Curves.easeInOut
|
|
|
|
));
|
|
|
|
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
animationController.dispose();
|
|
|
|
super.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final statusProvider = Provider.of<StatusProvider>(context);
|
|
|
|
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
|
|
|
|
|
|
|
void updateBlocking({
|
|
|
|
required bool value,
|
|
|
|
required String filter,
|
|
|
|
int? time
|
|
|
|
}) async {
|
|
|
|
final result = await statusProvider.updateBlocking(
|
|
|
|
block: filter,
|
|
|
|
newStatus: value,
|
|
|
|
time: time
|
|
|
|
);
|
2023-11-19 22:52:40 +01:00
|
|
|
if (mounted && result == false) {
|
2023-10-29 13:59:36 +01:00
|
|
|
showSnacbkar(
|
|
|
|
appConfigProvider: appConfigProvider,
|
|
|
|
label: AppLocalizations.of(context)!.invalidUsernamePassword,
|
|
|
|
color: Colors.red
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void disableWithCountdown(int time) async {
|
|
|
|
updateBlocking(value: false, filter: 'general', time: time);
|
|
|
|
expandableController.toggle();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (widget.dialog == true) {
|
|
|
|
return Dialog(
|
|
|
|
child: ConstrainedBox(
|
|
|
|
constraints: const BoxConstraints(
|
|
|
|
maxWidth: 400
|
|
|
|
),
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Flexible(
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: _Modal(
|
|
|
|
expandableController: expandableController,
|
|
|
|
updateBlocking: updateBlocking,
|
|
|
|
disableWithCountdown: disableWithCountdown,
|
|
|
|
animation: animation,
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(24),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
child: Text(AppLocalizations.of(context)!.close),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (Platform.isIOS) const SizedBox(height: 16)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Theme.of(context).colorScheme.surface,
|
|
|
|
borderRadius: const BorderRadius.only(
|
|
|
|
topLeft: Radius.circular(28),
|
|
|
|
topRight: Radius.circular(28)
|
|
|
|
)
|
|
|
|
),
|
2023-12-09 04:04:14 +01:00
|
|
|
child: SafeArea(
|
|
|
|
child: Column(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Flexible(
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
child: _Modal(
|
|
|
|
expandableController: expandableController,
|
|
|
|
updateBlocking: updateBlocking,
|
|
|
|
disableWithCountdown: disableWithCountdown,
|
|
|
|
animation: animation,
|
|
|
|
)
|
|
|
|
),
|
2023-10-29 13:59:36 +01:00
|
|
|
),
|
2023-12-09 04:04:14 +01:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(24),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
TextButton(
|
|
|
|
onPressed: () => Navigator.pop(context),
|
|
|
|
child: Text(AppLocalizations.of(context)!.close),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2023-10-29 13:59:36 +01:00
|
|
|
),
|
2023-12-09 04:04:14 +01:00
|
|
|
if (Platform.isIOS) const SizedBox(height: 16)
|
|
|
|
],
|
|
|
|
),
|
2023-10-29 13:59:36 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _Modal extends StatelessWidget {
|
|
|
|
final ExpandableController expandableController;
|
|
|
|
final void Function({ required bool value, required String filter }) updateBlocking;
|
|
|
|
final void Function(int) disableWithCountdown;
|
|
|
|
final Animation<double> animation;
|
|
|
|
|
|
|
|
const _Modal({
|
|
|
|
required this.expandableController,
|
|
|
|
required this.updateBlocking,
|
|
|
|
required this.disableWithCountdown,
|
|
|
|
required this.animation,
|
2023-11-29 11:56:28 +01:00
|
|
|
});
|
2023-10-29 13:59:36 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final statusProvider = Provider.of<StatusProvider>(context);
|
|
|
|
|
|
|
|
return Wrap(
|
|
|
|
children: [
|
|
|
|
// Header
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Padding(
|
2023-12-09 04:04:14 +01:00
|
|
|
padding: const EdgeInsets.only(top: 24),
|
|
|
|
child: Icon(
|
|
|
|
Icons.shield_rounded,
|
|
|
|
size: 24,
|
|
|
|
color: Theme.of(context).listTileTheme.iconColor
|
|
|
|
),
|
2023-10-29 13:59:36 +01:00
|
|
|
),
|
2023-12-09 04:04:14 +01:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
|
|
child: Text(
|
|
|
|
AppLocalizations.of(context)!.manageServer,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 24,
|
|
|
|
color: Theme.of(context).colorScheme.onSurface,
|
|
|
|
),
|
2023-10-29 13:59:36 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
|
|
|
|
MainSwitch(
|
|
|
|
expandableController: expandableController,
|
|
|
|
updateBlocking: updateBlocking,
|
|
|
|
disableWithCountdown: disableWithCountdown,
|
|
|
|
animation: animation,
|
|
|
|
),
|
|
|
|
Container(height: 10),
|
|
|
|
SmallSwitch(
|
|
|
|
label: AppLocalizations.of(context)!.ruleFiltering,
|
|
|
|
icon: Icons.filter_list_rounded,
|
|
|
|
value: statusProvider.serverStatus!.filteringEnabled,
|
|
|
|
onChange: (value) => updateBlocking(value: value, filter: 'filtering'),
|
|
|
|
disabled: statusProvider.protectionsManagementProcess.contains('filtering')
|
|
|
|
),
|
|
|
|
SmallSwitch(
|
|
|
|
label: AppLocalizations.of(context)!.safeBrowsing,
|
|
|
|
icon: Icons.vpn_lock_rounded,
|
|
|
|
value: statusProvider.serverStatus!.safeBrowsingEnabled,
|
|
|
|
onChange: (value) => updateBlocking(value: value, filter: 'safeBrowsing'),
|
|
|
|
disabled: statusProvider.protectionsManagementProcess.contains('safeBrowsing')
|
|
|
|
),
|
|
|
|
SmallSwitch(
|
|
|
|
label: AppLocalizations.of(context)!.parentalFiltering,
|
|
|
|
icon: Icons.block,
|
|
|
|
value: statusProvider.serverStatus!.parentalControlEnabled,
|
|
|
|
onChange: (value) => updateBlocking(value: value, filter: 'parentalControl'),
|
|
|
|
disabled: statusProvider.protectionsManagementProcess.contains('parentalControl')
|
|
|
|
),
|
|
|
|
SmallSwitch(
|
|
|
|
label: AppLocalizations.of(context)!.safeSearch,
|
|
|
|
icon: Icons.search_rounded,
|
|
|
|
value: statusProvider.serverStatus!.safeSearchEnabled,
|
|
|
|
onChange: (value) => updateBlocking(value: value, filter: 'safeSearch'),
|
|
|
|
disabled: statusProvider.protectionsManagementProcess.contains('safeSearch')
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|