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",
"all": "All",
"filtered": "Filtered",
"checkAppLogs": "Check app logs"
"checkAppLogs": "Check app logs",
"refresh": "Refresh"
}

View file

@ -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"
}

View file

@ -14,11 +14,13 @@ import 'package:adguard_home_manager/classes/process_modal.dart';
class BlockedAllowedList extends StatelessWidget {
final String type;
final List<String> 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),
)
],
),
);
}

View file

@ -49,7 +49,7 @@ class ClientsWidget extends StatefulWidget {
class _ClientsWidgetState extends State<ClientsWidget> 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<ClientsWidget> 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,
),
),
],
),

View file

@ -5,10 +5,12 @@ import 'package:adguard_home_manager/models/clients.dart';
class ClientsList extends StatelessWidget {
final List<AutoClient> 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)
)
],
),
);
}