mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-05-14 05:52:51 +00:00
Added options modal and delete client
This commit is contained in:
parent
e78dbb232f
commit
c25e3375e6
6 changed files with 200 additions and 10 deletions
|
@ -1,10 +1,13 @@
|
|||
// ignore_for_file: use_build_context_synchronously
|
||||
|
||||
import 'package:adguard_home_manager/screens/clients/remove_domain_modal.dart';
|
||||
import 'package:animations/animations.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:adguard_home_manager/screens/clients/fab.dart';
|
||||
import 'package:adguard_home_manager/screens/clients/options_modal.dart';
|
||||
import 'package:adguard_home_manager/screens/clients/client_modal.dart';
|
||||
|
||||
import 'package:adguard_home_manager/classes/process_modal.dart';
|
||||
|
@ -68,18 +71,68 @@ class AddedList extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
|
||||
void deleteClient(Client client) async {
|
||||
ProcessModal processModal = ProcessModal(context: context);
|
||||
processModal.open(AppLocalizations.of(context)!.removingClient);
|
||||
|
||||
final result = await postDeleteClient(server: serversProvider.selectedServer!, name: client.name);
|
||||
|
||||
processModal.close();
|
||||
|
||||
if (result['result'] == 'success') {
|
||||
ClientsData clientsData = serversProvider.clients.data!;
|
||||
clientsData.clients = clientsData.clients.where((c) => c.name != client.name).toList();
|
||||
serversProvider.setClientsData(clientsData);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.clientDeletedSuccessfully),
|
||||
backgroundColor: Colors.green,
|
||||
)
|
||||
);
|
||||
}
|
||||
else {
|
||||
appConfigProvider.addLog(result['log']);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(AppLocalizations.of(context)!.clientNotDeleted),
|
||||
backgroundColor: Colors.red,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void openClientModal(Client client) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (ctx) => ClientModal(
|
||||
client: client,
|
||||
onConfirm: confirmEditClient
|
||||
onConfirm: confirmEditClient,
|
||||
onDelete: deleteClient,
|
||||
),
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent
|
||||
);
|
||||
}
|
||||
|
||||
void openDeleteModal(Client client) {
|
||||
showModal(
|
||||
context: context,
|
||||
builder: (ctx) => RemoveDomainModal(
|
||||
onConfirm: () => deleteClient(client)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
void openOptionsModal(Client client) {
|
||||
showModal(
|
||||
context: context,
|
||||
builder: (ctx) => OptionsModal(
|
||||
onDelete: () => openDeleteModal(client),
|
||||
onEdit: () => openClientModal(client),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
return Stack(
|
||||
children: [
|
||||
if (data.isNotEmpty) RefreshIndicator(
|
||||
|
@ -89,6 +142,7 @@ class AddedList extends StatelessWidget {
|
|||
itemCount: data.length,
|
||||
itemBuilder: (context, index) => ListTile(
|
||||
isThreeLine: true,
|
||||
onLongPress: () => openOptionsModal(data[index]),
|
||||
onTap: () => openClientModal(data[index]),
|
||||
title: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 5),
|
||||
|
|
|
@ -3,6 +3,7 @@ import 'package:provider/provider.dart';
|
|||
import 'package:uuid/uuid.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
import 'package:adguard_home_manager/screens/clients/remove_domain_modal.dart';
|
||||
import 'package:adguard_home_manager/screens/clients/services_modal.dart';
|
||||
import 'package:adguard_home_manager/screens/clients/tags_modal.dart';
|
||||
|
||||
|
@ -12,11 +13,13 @@ import 'package:adguard_home_manager/models/clients.dart';
|
|||
class ClientModal extends StatefulWidget {
|
||||
final Client? client;
|
||||
final void Function(Client) onConfirm;
|
||||
final void Function(Client)? onDelete;
|
||||
|
||||
const ClientModal({
|
||||
Key? key,
|
||||
this.client,
|
||||
required this.onConfirm
|
||||
required this.onConfirm,
|
||||
this.onDelete,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
|
@ -181,6 +184,18 @@ class _ClientModalState extends State<ClientModal> {
|
|||
}
|
||||
}
|
||||
|
||||
void openDeleteClientModal() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) => RemoveDomainModal(
|
||||
onConfirm: () {
|
||||
Navigator.pop(context);
|
||||
widget.onDelete!(widget.client!);
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Widget settignsTile({
|
||||
required String label,
|
||||
required bool? value,
|
||||
|
@ -626,13 +641,23 @@ class _ClientModalState extends State<ClientModal> {
|
|||
Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Row(
|
||||
mainAxisAlignment: widget.client == null || (widget.client != null && editMode == true)
|
||||
? MainAxisAlignment.end
|
||||
: MainAxisAlignment.spaceBetween,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
if (widget.client != null && editMode == false) TextButton(
|
||||
onPressed: () => setState(() => editMode = true),
|
||||
child: Text(AppLocalizations.of(context)!.edit)
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: [
|
||||
if (widget.client != null && editMode == false) ...[
|
||||
IconButton(
|
||||
onPressed: () => setState(() => editMode = true),
|
||||
icon: const Icon(Icons.edit)
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
],
|
||||
if (widget.client != null && widget.onDelete != null) IconButton(
|
||||
onPressed: openDeleteClientModal,
|
||||
icon: const Icon(Icons.delete)
|
||||
),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
|
|
71
lib/screens/clients/options_modal.dart
Normal file
71
lib/screens/clients/options_modal.dart
Normal file
|
@ -0,0 +1,71 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||
|
||||
class OptionsModal extends StatelessWidget {
|
||||
final void Function() onEdit;
|
||||
final void Function() onDelete;
|
||||
|
||||
const OptionsModal({
|
||||
Key? key,
|
||||
required this.onDelete,
|
||||
required this.onEdit,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
contentPadding: const EdgeInsets.all(0),
|
||||
title: Column(
|
||||
children: [
|
||||
const Icon(Icons.more_horiz),
|
||||
const SizedBox(height: 20),
|
||||
Text(AppLocalizations.of(context)!.options)
|
||||
],
|
||||
),
|
||||
content: SizedBox(
|
||||
height: 150,
|
||||
width: double.minPositive,
|
||||
child: ListView(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
children: [
|
||||
const SizedBox(height: 25),
|
||||
ListTile(
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
onEdit();
|
||||
},
|
||||
title: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Text(AppLocalizations.of(context)!.edit),
|
||||
),
|
||||
leading: const Padding(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Icon(Icons.edit),
|
||||
),
|
||||
),
|
||||
ListTile(
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
onDelete();
|
||||
},
|
||||
title: Padding(
|
||||
padding: const EdgeInsets.all(10.0),
|
||||
child: Text(AppLocalizations.of(context)!.delete),
|
||||
),
|
||||
leading: const Padding(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Icon(Icons.delete),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text(AppLocalizations.of(context)!.close)
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue