2022-09-28 15:47:43 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-09-29 00:13:54 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
2022-09-28 15:47:43 +02:00
|
|
|
|
|
|
|
import 'package:adguard_home_manager/models/clients.dart';
|
|
|
|
|
|
|
|
class ClientsList extends StatelessWidget {
|
2022-10-08 22:16:35 +02:00
|
|
|
final ScrollController scrollController;
|
2022-10-08 15:06:40 +02:00
|
|
|
final int loadStatus;
|
2022-09-28 15:47:43 +02:00
|
|
|
final List<AutoClient> data;
|
2022-10-02 18:31:47 +02:00
|
|
|
final Future Function() fetchClients;
|
2022-09-28 15:47:43 +02:00
|
|
|
|
|
|
|
const ClientsList({
|
|
|
|
Key? key,
|
2022-10-08 22:16:35 +02:00
|
|
|
required this.scrollController,
|
2022-10-08 15:06:40 +02:00
|
|
|
required this.loadStatus,
|
2022-10-02 18:31:47 +02:00
|
|
|
required this.data,
|
|
|
|
required this.fetchClients
|
2022-09-28 15:47:43 +02:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-10-08 15:06:40 +02:00
|
|
|
switch (loadStatus) {
|
|
|
|
case 0:
|
|
|
|
return SizedBox(
|
|
|
|
width: double.maxFinite,
|
|
|
|
height: MediaQuery.of(context).size.height-171,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
const CircularProgressIndicator(),
|
|
|
|
const SizedBox(height: 30),
|
|
|
|
Text(
|
|
|
|
AppLocalizations.of(context)!.loadingStatus,
|
2022-10-10 00:12:29 +02:00
|
|
|
textAlign: TextAlign.center,
|
2022-10-08 15:06:40 +02:00
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 22,
|
|
|
|
color: Colors.grey,
|
|
|
|
),
|
2022-09-29 00:13:54 +02:00
|
|
|
)
|
2022-10-08 15:06:40 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
if (data.isNotEmpty) {
|
|
|
|
return ListView.builder(
|
|
|
|
padding: const EdgeInsets.only(top: 0),
|
|
|
|
itemCount: data.length,
|
|
|
|
itemBuilder: (context, index) => ListTile(
|
|
|
|
title: Text(
|
|
|
|
data[index].name != ''
|
|
|
|
? data[index].name!
|
|
|
|
: data[index].ip
|
2022-10-02 18:31:47 +02:00
|
|
|
),
|
2022-10-08 15:06:40 +02:00
|
|
|
subtitle: data[index].name != ''
|
|
|
|
? Text(
|
|
|
|
data[index].ip
|
|
|
|
)
|
|
|
|
: null,
|
|
|
|
trailing: Text(data[index].source),
|
2022-10-02 18:31:47 +02:00
|
|
|
)
|
2022-10-08 15:06:40 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return SizedBox(
|
|
|
|
width: double.maxFinite,
|
|
|
|
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)
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
return SizedBox(
|
|
|
|
width: double.maxFinite,
|
|
|
|
height: MediaQuery.of(context).size.height-171,
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
const Icon(
|
|
|
|
Icons.error,
|
|
|
|
color: Colors.red,
|
|
|
|
size: 50,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 30),
|
|
|
|
Text(
|
|
|
|
AppLocalizations.of(context)!.errorLoadServerStatus,
|
2022-10-10 00:12:29 +02:00
|
|
|
textAlign: TextAlign.center,
|
2022-10-08 15:06:40 +02:00
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 22,
|
|
|
|
color: Colors.grey,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
default:
|
|
|
|
return const SizedBox();
|
2022-09-29 00:13:54 +02:00
|
|
|
}
|
2022-09-28 15:47:43 +02:00
|
|
|
}
|
|
|
|
}
|