mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-06-10 16:39:39 +00:00
Updated block client modal
This commit is contained in:
parent
7944f6f18a
commit
5c9e0e99b9
5 changed files with 156 additions and 225 deletions
|
@ -169,5 +169,6 @@
|
||||||
"hideZeroValuesDescription": "On homescreen, hide blocks with zero value",
|
"hideZeroValuesDescription": "On homescreen, hide blocks with zero value",
|
||||||
"webAdminPanel": "Web admin. panel",
|
"webAdminPanel": "Web admin. panel",
|
||||||
"visitGooglePlay": "Visit Google Play page",
|
"visitGooglePlay": "Visit Google Play page",
|
||||||
"gitHub": "App code available on GitHub"
|
"gitHub": "App code available on GitHub",
|
||||||
|
"blockClient": "Block client"
|
||||||
}
|
}
|
|
@ -169,5 +169,6 @@
|
||||||
"hideZeroValuesDescription": "En la pantalla de inicio, oculta bloqueos con valor cero",
|
"hideZeroValuesDescription": "En la pantalla de inicio, oculta bloqueos con valor cero",
|
||||||
"webAdminPanel": "Panel de admin. web",
|
"webAdminPanel": "Panel de admin. web",
|
||||||
"visitGooglePlay": "Visita la página de Google Play",
|
"visitGooglePlay": "Visita la página de Google Play",
|
||||||
"gitHub": "Código de la app disponible en GitHub"
|
"gitHub": "Código de la app disponible en GitHub",
|
||||||
|
"blockClient": "Bloquear cliente"
|
||||||
}
|
}
|
|
@ -1,198 +0,0 @@
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
||||||
|
|
||||||
class AddClientModal extends StatefulWidget {
|
|
||||||
final String list;
|
|
||||||
final void Function(String, String) onConfirm;
|
|
||||||
|
|
||||||
const AddClientModal({
|
|
||||||
Key? key,
|
|
||||||
required this.list,
|
|
||||||
required this.onConfirm
|
|
||||||
}) : super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<AddClientModal> createState() => _AddClientModalState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _AddClientModalState extends State<AddClientModal> {
|
|
||||||
String list = '';
|
|
||||||
|
|
||||||
TextEditingController ipController = TextEditingController();
|
|
||||||
String? ipError;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
list = widget.list;
|
|
||||||
super.initState();
|
|
||||||
}
|
|
||||||
|
|
||||||
void validateIp(String value) {
|
|
||||||
RegExp ipAddress = RegExp(r'^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$');
|
|
||||||
if (ipAddress.hasMatch(value) == true) {
|
|
||||||
setState(() => ipError = null);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
setState(() => ipError = AppLocalizations.of(context)!.ipNotValid);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool checkValidValues() {
|
|
||||||
if (
|
|
||||||
(list == 'allowed' ||
|
|
||||||
list == 'blocked') &&
|
|
||||||
ipController.text != '' &&
|
|
||||||
ipError == null
|
|
||||||
) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return AlertDialog(
|
|
||||||
title: Column(
|
|
||||||
children: [
|
|
||||||
const Icon(
|
|
||||||
Icons.add,
|
|
||||||
size: 26,
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
|
||||||
Text(
|
|
||||||
AppLocalizations.of(context)!.addClient,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
content: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Material(
|
|
||||||
borderRadius: const BorderRadius.only(
|
|
||||||
topLeft: Radius.circular(15),
|
|
||||||
bottomLeft: Radius.circular(15)
|
|
||||||
),
|
|
||||||
color: Colors.transparent,
|
|
||||||
child: InkWell(
|
|
||||||
borderRadius: const BorderRadius.only(
|
|
||||||
topLeft: Radius.circular(15),
|
|
||||||
bottomLeft: Radius.circular(15)
|
|
||||||
),
|
|
||||||
onTap: () => setState(() => list = 'allowed'),
|
|
||||||
child: AnimatedContainer(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
|
|
||||||
duration: const Duration(milliseconds: 200),
|
|
||||||
curve: Curves.easeInOut,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: const BorderRadius.only(
|
|
||||||
topLeft: Radius.circular(15),
|
|
||||||
bottomLeft: Radius.circular(15)
|
|
||||||
),
|
|
||||||
border: Border.all(
|
|
||||||
color: Theme.of(context).primaryColor
|
|
||||||
),
|
|
||||||
color: list == 'allowed'
|
|
||||||
? Theme.of(context).primaryColor
|
|
||||||
: Theme.of(context).primaryColor.withOpacity(0.05)
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
AppLocalizations.of(context)!.allowed,
|
|
||||||
style: TextStyle(
|
|
||||||
color: list == 'allowed'
|
|
||||||
? Colors.white
|
|
||||||
: null
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Material(
|
|
||||||
borderRadius: const BorderRadius.only(
|
|
||||||
topRight: Radius.circular(15),
|
|
||||||
bottomRight: Radius.circular(15)
|
|
||||||
),
|
|
||||||
color: Colors.transparent,
|
|
||||||
child: InkWell(
|
|
||||||
borderRadius: const BorderRadius.only(
|
|
||||||
topRight: Radius.circular(15),
|
|
||||||
bottomRight: Radius.circular(15)
|
|
||||||
),
|
|
||||||
onTap: () => setState(() => list = 'blocked'),
|
|
||||||
child: AnimatedContainer(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
|
|
||||||
duration: const Duration(milliseconds: 200),
|
|
||||||
curve: Curves.easeInOut,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
borderRadius: const BorderRadius.only(
|
|
||||||
topRight: Radius.circular(15),
|
|
||||||
bottomRight: Radius.circular(15)
|
|
||||||
),
|
|
||||||
border: Border.all(
|
|
||||||
color: Theme.of(context).primaryColor
|
|
||||||
),
|
|
||||||
color: list == 'blocked'
|
|
||||||
? Theme.of(context).primaryColor
|
|
||||||
: Theme.of(context).primaryColor.withOpacity(0.05)
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
AppLocalizations.of(context)!.blocked,
|
|
||||||
style: TextStyle(
|
|
||||||
color: list == 'blocked'
|
|
||||||
? Colors.white
|
|
||||||
: null
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const SizedBox(height: 30),
|
|
||||||
TextFormField(
|
|
||||||
controller: ipController,
|
|
||||||
onChanged: validateIp,
|
|
||||||
decoration: InputDecoration(
|
|
||||||
prefixIcon: const Icon(Icons.link_rounded),
|
|
||||||
errorText: ipError,
|
|
||||||
border: const OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.all(
|
|
||||||
Radius.circular(10)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
labelText: AppLocalizations.of(context)!.ipAddress,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
child: Text(AppLocalizations.of(context)!.cancel)
|
|
||||||
),
|
|
||||||
TextButton(
|
|
||||||
onPressed: checkValidValues() == true
|
|
||||||
? () {
|
|
||||||
Navigator.pop(context);
|
|
||||||
widget.onConfirm(list, ipController.text);
|
|
||||||
}
|
|
||||||
: null,
|
|
||||||
child: Text(
|
|
||||||
AppLocalizations.of(context)!.confirm,
|
|
||||||
style: TextStyle(
|
|
||||||
color: checkValidValues() == true
|
|
||||||
? Theme.of(context).primaryColor
|
|
||||||
: Colors.grey
|
|
||||||
),
|
|
||||||
)
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
125
lib/screens/clients/block_client_modal.dart
Normal file
125
lib/screens/clients/block_client_modal.dart
Normal file
|
@ -0,0 +1,125 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
class BlockClientModal extends StatefulWidget {
|
||||||
|
final void Function(String) onConfirm;
|
||||||
|
|
||||||
|
const BlockClientModal({
|
||||||
|
Key? key,
|
||||||
|
required this.onConfirm
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<BlockClientModal> createState() => _BlockClientModalState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _BlockClientModalState extends State<BlockClientModal> {
|
||||||
|
TextEditingController ipController = TextEditingController();
|
||||||
|
String? ipError;
|
||||||
|
|
||||||
|
void validateIp(String value) {
|
||||||
|
RegExp ipAddress = RegExp(r'^((25[0-5]|(2[0-4]|1\d|[1-9]|)\d)(\.(?!$)|$)){4}$');
|
||||||
|
if (ipAddress.hasMatch(value) == true) {
|
||||||
|
setState(() => ipError = null);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setState(() => ipError = AppLocalizations.of(context)!.ipNotValid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool checkValidValues() {
|
||||||
|
if (
|
||||||
|
ipController.text != '' &&
|
||||||
|
ipError == null
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: MediaQuery.of(context).viewInsets,
|
||||||
|
child: Container(
|
||||||
|
height: 322,
|
||||||
|
padding: const EdgeInsets.all(28),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Theme.of(context).dialogBackgroundColor,
|
||||||
|
borderRadius: const BorderRadius.only(
|
||||||
|
topLeft: Radius.circular(28),
|
||||||
|
topRight: Radius.circular(28)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
const Icon(
|
||||||
|
Icons.block,
|
||||||
|
size: 26,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
Text(
|
||||||
|
AppLocalizations.of(context)!.blockClient,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 24
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 30),
|
||||||
|
TextFormField(
|
||||||
|
controller: ipController,
|
||||||
|
onChanged: validateIp,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
prefixIcon: const Icon(Icons.link_rounded),
|
||||||
|
errorText: ipError,
|
||||||
|
border: const OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.all(
|
||||||
|
Radius.circular(10)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
labelText: AppLocalizations.of(context)!.ipAddress,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 20),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: Text(AppLocalizations.of(context)!.cancel)
|
||||||
|
),
|
||||||
|
const SizedBox(width: 20),
|
||||||
|
TextButton(
|
||||||
|
onPressed: checkValidValues() == true
|
||||||
|
? () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
widget.onConfirm(ipController.text);
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
child: Text(
|
||||||
|
AppLocalizations.of(context)!.confirm,
|
||||||
|
style: TextStyle(
|
||||||
|
color: checkValidValues() == true
|
||||||
|
? Theme.of(context).primaryColor
|
||||||
|
: Colors.grey
|
||||||
|
),
|
||||||
|
)
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
import 'package:adguard_home_manager/screens/clients/add_client_modal.dart';
|
import 'package:adguard_home_manager/screens/clients/block_client_modal.dart';
|
||||||
|
|
||||||
import 'package:adguard_home_manager/services/http_requests.dart';
|
import 'package:adguard_home_manager/services/http_requests.dart';
|
||||||
import 'package:adguard_home_manager/models/clients_allowed_blocked.dart';
|
import 'package:adguard_home_manager/models/clients_allowed_blocked.dart';
|
||||||
|
@ -20,25 +20,15 @@ class ClientsFab extends StatelessWidget {
|
||||||
final serversProvider = Provider.of<ServersProvider>(context);
|
final serversProvider = Provider.of<ServersProvider>(context);
|
||||||
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
||||||
|
|
||||||
void confirmRemoveDomain(String list, String ip) async {
|
void confirmRemoveDomain(String ip) async {
|
||||||
Map<String, List<String>> body = {};
|
Map<String, List<String>> body = {};
|
||||||
|
|
||||||
if (list == 'allowed') {
|
|
||||||
final List<String> clients = [...serversProvider.clients.data!.clientsAllowedBlocked?.allowedClients ?? [], ip];
|
|
||||||
body = {
|
|
||||||
"allowed_clients": clients,
|
|
||||||
"disallowed_clients": serversProvider.clients.data!.clientsAllowedBlocked?.disallowedClients ?? [],
|
|
||||||
"blocked_hosts": serversProvider.clients.data!.clientsAllowedBlocked?.blockedHosts ?? [],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
else if (list == 'blocked') {
|
|
||||||
final List<String> clients = [...serversProvider.clients.data!.clientsAllowedBlocked?.disallowedClients ?? [], ip];
|
final List<String> clients = [...serversProvider.clients.data!.clientsAllowedBlocked?.disallowedClients ?? [], ip];
|
||||||
body = {
|
body = {
|
||||||
"allowed_clients": serversProvider.clients.data!.clientsAllowedBlocked?.allowedClients ?? [],
|
"allowed_clients": serversProvider.clients.data!.clientsAllowedBlocked?.allowedClients ?? [],
|
||||||
"disallowed_clients": clients,
|
"disallowed_clients": clients,
|
||||||
"blocked_hosts": serversProvider.clients.data!.clientsAllowedBlocked?.blockedHosts ?? [],
|
"blocked_hosts": serversProvider.clients.data!.clientsAllowedBlocked?.blockedHosts ?? [],
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
ProcessModal processModal = ProcessModal(context: context);
|
ProcessModal processModal = ProcessModal(context: context);
|
||||||
processModal.open(AppLocalizations.of(context)!.addingClient);
|
processModal.open(AppLocalizations.of(context)!.addingClient);
|
||||||
|
@ -82,25 +72,37 @@ class ClientsFab extends StatelessWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void openAddClient(String list) {
|
void openBlockClient() {
|
||||||
showDialog(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (ctx) => AddClientModal(
|
builder: (ctx) => BlockClientModal(
|
||||||
list: list,
|
|
||||||
onConfirm: confirmRemoveDomain
|
onConfirm: confirmRemoveDomain
|
||||||
)
|
),
|
||||||
|
isScrollControlled: true,
|
||||||
|
backgroundColor: Colors.transparent
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void openAddClient() {
|
||||||
|
// showModalBottomSheet(
|
||||||
|
// context: context,
|
||||||
|
// builder: (ctx) => BlockClientModal(
|
||||||
|
// onConfirm: confirmRemoveDomain
|
||||||
|
// ),
|
||||||
|
// isScrollControlled: true,
|
||||||
|
// backgroundColor: Colors.transparent
|
||||||
|
// );
|
||||||
|
}
|
||||||
|
|
||||||
if (appConfigProvider.selectedClientsTab == 1) {
|
if (appConfigProvider.selectedClientsTab == 1) {
|
||||||
return FloatingActionButton(
|
return FloatingActionButton(
|
||||||
onPressed: () => openAddClient('allowed'),
|
onPressed: () => openAddClient(),
|
||||||
child: const Icon(Icons.add),
|
child: const Icon(Icons.add),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if (appConfigProvider.selectedClientsTab == 2) {
|
else if (appConfigProvider.selectedClientsTab == 2) {
|
||||||
return FloatingActionButton(
|
return FloatingActionButton(
|
||||||
onPressed: () => openAddClient('blocked'),
|
onPressed: () => openBlockClient(),
|
||||||
child: const Icon(Icons.add),
|
child: const Icon(Icons.add),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue