From 82079268d39ccd1377434a18152ec0335747b4a9 Mon Sep 17 00:00:00 2001 From: Juan Gilsanz Polo Date: Sun, 2 Oct 2022 18:31:47 +0200 Subject: [PATCH] Added refresh on clients --- lib/l10n/app_en.arb | 3 +- lib/l10n/app_es.arb | 3 +- lib/screens/clients/blocked_allowed_list.dart | 64 +++++++++++-------- lib/screens/clients/clients.dart | 30 ++++++--- lib/screens/clients/clients_list.dart | 29 ++++++--- 5 files changed, 84 insertions(+), 45 deletions(-) diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 014752d..fbee287 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -155,5 +155,6 @@ "unselectAll": "Unselect all", "all": "All", "filtered": "Filtered", - "checkAppLogs": "Check app logs" + "checkAppLogs": "Check app logs", + "refresh": "Refresh" } \ No newline at end of file diff --git a/lib/l10n/app_es.arb b/lib/l10n/app_es.arb index 6a32d45..a86630f 100644 --- a/lib/l10n/app_es.arb +++ b/lib/l10n/app_es.arb @@ -155,5 +155,6 @@ "unselectAll": "Deseleccionar todo", "all": "Todas", "filtered": "Filtrada", - "checkAppLogs": "Comprueba los logs de la app" + "checkAppLogs": "Comprueba los logs de la app", + "refresh": "Actualizar" } \ No newline at end of file diff --git a/lib/screens/clients/blocked_allowed_list.dart b/lib/screens/clients/blocked_allowed_list.dart index a933af4..a71dd43 100644 --- a/lib/screens/clients/blocked_allowed_list.dart +++ b/lib/screens/clients/blocked_allowed_list.dart @@ -14,11 +14,13 @@ import 'package:adguard_home_manager/classes/process_modal.dart'; class BlockedAllowedList extends StatelessWidget { final String type; final List data; + final Future Function() fetchClients; const BlockedAllowedList({ Key? key, required this.type, - required this.data + required this.data, + required this.fetchClients }) : super(key: key); @override @@ -78,37 +80,49 @@ class BlockedAllowedList extends StatelessWidget { } if (data.isNotEmpty) { - return ListView.builder( - padding: const EdgeInsets.only(top: 0), - itemCount: data.length, - itemBuilder: (context, index) => ListTile( - title: Text(data[index]), - trailing: IconButton( - onPressed: () => { - showDialog( - context: context, - builder: (context) => RemoveDomainModal( - onConfirm: () => confirmRemoveDomain(data[index]), + return RefreshIndicator( + onRefresh: () async {}, + child: ListView.builder( + padding: const EdgeInsets.only(top: 0), + itemCount: data.length, + itemBuilder: (context, index) => ListTile( + title: Text(data[index]), + trailing: IconButton( + onPressed: () => { + showDialog( + context: context, + builder: (context) => RemoveDomainModal( + onConfirm: () => confirmRemoveDomain(data[index]), + ) ) - ) - }, - icon: const Icon(Icons.delete_rounded) - ), - ) + }, + icon: const Icon(Icons.delete_rounded) + ), + ) + ), ); } else { return SizedBox( width: double.maxFinite, - child: Center( - child: Text( - AppLocalizations.of(context)!.noClientsList, - textAlign: TextAlign.center, - style: const TextStyle( - fontSize: 24, - color: Colors.grey + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + AppLocalizations.of(context)!.noClientsList, + textAlign: TextAlign.center, + style: const TextStyle( + fontSize: 24, + color: Colors.grey + ), ), - ), + const SizedBox(height: 30), + TextButton.icon( + onPressed: fetchClients, + icon: const Icon(Icons.refresh_rounded), + label: Text(AppLocalizations.of(context)!.refresh), + ) + ], ), ); } diff --git a/lib/screens/clients/clients.dart b/lib/screens/clients/clients.dart index d8241c9..64a4b80 100644 --- a/lib/screens/clients/clients.dart +++ b/lib/screens/clients/clients.dart @@ -49,7 +49,7 @@ class ClientsWidget extends StatefulWidget { class _ClientsWidgetState extends State with TickerProviderStateMixin { late TabController tabController; - void fetchClients() async { + Future fetchClients() async { widget.setLoadingStatus(0, false); final result = await getClients(widget.server); if (result['result'] == 'success') { @@ -148,16 +148,28 @@ class _ClientsWidgetState extends State with TickerProviderStateM child: TabBarView( controller: tabController, children: [ - ClientsList( - data: serversProvider.clients.data!.autoClientsData, + RefreshIndicator( + onRefresh: fetchClients, + child: ClientsList( + data: serversProvider.clients.data!.autoClientsData, + fetchClients: fetchClients, + ), ), - BlockedAllowedList( - type: 'allowed', - data: serversProvider.clients.data!.clientsAllowedBlocked!.allowedClients, + RefreshIndicator( + onRefresh: fetchClients, + child: BlockedAllowedList( + type: 'allowed', + data: serversProvider.clients.data!.clientsAllowedBlocked!.allowedClients, + fetchClients: fetchClients, + ), ), - BlockedAllowedList( - type: 'blocked', - data: serversProvider.clients.data!.clientsAllowedBlocked!.disallowedClients, + RefreshIndicator( + onRefresh: fetchClients, + child: BlockedAllowedList( + type: 'blocked', + data: serversProvider.clients.data!.clientsAllowedBlocked!.disallowedClients, + fetchClients: fetchClients, + ), ), ], ), diff --git a/lib/screens/clients/clients_list.dart b/lib/screens/clients/clients_list.dart index 0943d93..b02146e 100644 --- a/lib/screens/clients/clients_list.dart +++ b/lib/screens/clients/clients_list.dart @@ -5,10 +5,12 @@ import 'package:adguard_home_manager/models/clients.dart'; class ClientsList extends StatelessWidget { final List data; + final Future Function() fetchClients; const ClientsList({ Key? key, - required this.data + required this.data, + required this.fetchClients }) : super(key: key); @override @@ -35,15 +37,24 @@ class ClientsList extends StatelessWidget { else { return SizedBox( width: double.maxFinite, - child: Center( - child: Text( - AppLocalizations.of(context)!.noClientsList, - textAlign: TextAlign.center, - style: const TextStyle( - fontSize: 24, - color: Colors.grey + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + AppLocalizations.of(context)!.noClientsList, + textAlign: TextAlign.center, + style: const TextStyle( + fontSize: 24, + color: Colors.grey + ), ), - ), + const SizedBox(height: 30), + TextButton.icon( + onPressed: fetchClients, + icon: const Icon(Icons.refresh_rounded), + label: Text(AppLocalizations.of(context)!.refresh) + ) + ], ), ); }