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,7 +80,9 @@ class BlockedAllowedList extends StatelessWidget {
} }
if (data.isNotEmpty) { if (data.isNotEmpty) {
return ListView.builder( return RefreshIndicator(
onRefresh: () async {},
child: ListView.builder(
padding: const EdgeInsets.only(top: 0), padding: const EdgeInsets.only(top: 0),
itemCount: data.length, itemCount: data.length,
itemBuilder: (context, index) => ListTile( itemBuilder: (context, index) => ListTile(
@ -95,13 +99,16 @@ class BlockedAllowedList extends StatelessWidget {
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,
children: [
Text(
AppLocalizations.of(context)!.noClientsList, AppLocalizations.of(context)!.noClientsList,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: const TextStyle( style: const TextStyle(
@ -109,6 +116,13 @@ class BlockedAllowedList extends StatelessWidget {
color: Colors.grey 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(
onRefresh: fetchClients,
child: ClientsList(
data: serversProvider.clients.data!.autoClientsData, data: serversProvider.clients.data!.autoClientsData,
fetchClients: fetchClients,
), ),
BlockedAllowedList( ),
RefreshIndicator(
onRefresh: fetchClients,
child: BlockedAllowedList(
type: 'allowed', type: 'allowed',
data: serversProvider.clients.data!.clientsAllowedBlocked!.allowedClients, data: serversProvider.clients.data!.clientsAllowedBlocked!.allowedClients,
fetchClients: fetchClients,
), ),
BlockedAllowedList( ),
RefreshIndicator(
onRefresh: fetchClients,
child: BlockedAllowedList(
type: 'blocked', type: 'blocked',
data: serversProvider.clients.data!.clientsAllowedBlocked!.disallowedClients, 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,8 +37,10 @@ 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,
children: [
Text(
AppLocalizations.of(context)!.noClientsList, AppLocalizations.of(context)!.noClientsList,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: const TextStyle( style: const TextStyle(
@ -44,6 +48,13 @@ class ClientsList extends StatelessWidget {
color: Colors.grey color: Colors.grey
), ),
), ),
const SizedBox(height: 30),
TextButton.icon(
onPressed: fetchClients,
icon: const Icon(Icons.refresh_rounded),
label: Text(AppLocalizations.of(context)!.refresh)
)
],
), ),
); );
} }