Added refresh on clients

This commit is contained in:
Juan Gilsanz Polo 2022-10-02 18:31:47 +02:00
parent 721316cf1b
commit 82079268d3
5 changed files with 84 additions and 45 deletions

View file

@ -155,5 +155,6 @@
"unselectAll": "Unselect all", "unselectAll": "Unselect all",
"all": "All", "all": "All",
"filtered": "Filtered", "filtered": "Filtered",
"checkAppLogs": "Check app logs" "checkAppLogs": "Check app logs",
"refresh": "Refresh"
} }

View file

@ -155,5 +155,6 @@
"unselectAll": "Deseleccionar todo", "unselectAll": "Deseleccionar todo",
"all": "Todas", "all": "Todas",
"filtered": "Filtrada", "filtered": "Filtrada",
"checkAppLogs": "Comprueba los logs de la app" "checkAppLogs": "Comprueba los logs de la app",
"refresh": "Actualizar"
} }

View file

@ -14,11 +14,13 @@ import 'package:adguard_home_manager/classes/process_modal.dart';
class BlockedAllowedList extends StatelessWidget { class BlockedAllowedList extends StatelessWidget {
final String type; final String type;
final List<String> data; final List<String> data;
final Future Function() fetchClients;
const BlockedAllowedList({ const BlockedAllowedList({
Key? key, Key? key,
required this.type, required this.type,
required this.data required this.data,
required this.fetchClients
}) : super(key: key); }) : super(key: key);
@override @override
@ -78,37 +80,49 @@ class BlockedAllowedList extends StatelessWidget {
} }
if (data.isNotEmpty) { if (data.isNotEmpty) {
return ListView.builder( return RefreshIndicator(
padding: const EdgeInsets.only(top: 0), onRefresh: () async {},
itemCount: data.length, child: ListView.builder(
itemBuilder: (context, index) => ListTile( padding: const EdgeInsets.only(top: 0),
title: Text(data[index]), itemCount: data.length,
trailing: IconButton( itemBuilder: (context, index) => ListTile(
onPressed: () => { title: Text(data[index]),
showDialog( trailing: IconButton(
context: context, onPressed: () => {
builder: (context) => RemoveDomainModal( showDialog(
onConfirm: () => confirmRemoveDomain(data[index]), context: context,
builder: (context) => RemoveDomainModal(
onConfirm: () => confirmRemoveDomain(data[index]),
)
) )
) },
}, icon: const Icon(Icons.delete_rounded)
icon: const Icon(Icons.delete_rounded) ),
), )
) ),
); );
} }
else { else {
return SizedBox( return SizedBox(
width: double.maxFinite, width: double.maxFinite,
child: Center( child: Column(
child: Text( mainAxisAlignment: MainAxisAlignment.center,
AppLocalizations.of(context)!.noClientsList, children: [
textAlign: TextAlign.center, Text(
style: const TextStyle( AppLocalizations.of(context)!.noClientsList,
fontSize: 24, textAlign: TextAlign.center,
color: Colors.grey 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),
)
],
), ),
); );
} }

View file

@ -49,7 +49,7 @@ class ClientsWidget extends StatefulWidget {
class _ClientsWidgetState extends State<ClientsWidget> with TickerProviderStateMixin { class _ClientsWidgetState extends State<ClientsWidget> with TickerProviderStateMixin {
late TabController tabController; late TabController tabController;
void fetchClients() async { Future fetchClients() async {
widget.setLoadingStatus(0, false); widget.setLoadingStatus(0, false);
final result = await getClients(widget.server); final result = await getClients(widget.server);
if (result['result'] == 'success') { if (result['result'] == 'success') {
@ -148,16 +148,28 @@ class _ClientsWidgetState extends State<ClientsWidget> with TickerProviderStateM
child: TabBarView( child: TabBarView(
controller: tabController, controller: tabController,
children: [ children: [
ClientsList( RefreshIndicator(
data: serversProvider.clients.data!.autoClientsData, onRefresh: fetchClients,
child: ClientsList(
data: serversProvider.clients.data!.autoClientsData,
fetchClients: fetchClients,
),
), ),
BlockedAllowedList( RefreshIndicator(
type: 'allowed', onRefresh: fetchClients,
data: serversProvider.clients.data!.clientsAllowedBlocked!.allowedClients, child: BlockedAllowedList(
type: 'allowed',
data: serversProvider.clients.data!.clientsAllowedBlocked!.allowedClients,
fetchClients: fetchClients,
),
), ),
BlockedAllowedList( RefreshIndicator(
type: 'blocked', onRefresh: fetchClients,
data: serversProvider.clients.data!.clientsAllowedBlocked!.disallowedClients, child: BlockedAllowedList(
type: 'blocked',
data: serversProvider.clients.data!.clientsAllowedBlocked!.disallowedClients,
fetchClients: fetchClients,
),
), ),
], ],
), ),

View file

@ -5,10 +5,12 @@ import 'package:adguard_home_manager/models/clients.dart';
class ClientsList extends StatelessWidget { class ClientsList extends StatelessWidget {
final List<AutoClient> data; final List<AutoClient> data;
final Future Function() fetchClients;
const ClientsList({ const ClientsList({
Key? key, Key? key,
required this.data required this.data,
required this.fetchClients
}) : super(key: key); }) : super(key: key);
@override @override
@ -35,15 +37,24 @@ class ClientsList extends StatelessWidget {
else { else {
return SizedBox( return SizedBox(
width: double.maxFinite, width: double.maxFinite,
child: Center( child: Column(
child: Text( mainAxisAlignment: MainAxisAlignment.center,
AppLocalizations.of(context)!.noClientsList, children: [
textAlign: TextAlign.center, Text(
style: const TextStyle( AppLocalizations.of(context)!.noClientsList,
fontSize: 24, textAlign: TextAlign.center,
color: Colors.grey 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)
)
],
), ),
); );
} }