adguard-home-manager/lib/screens/clients/clients_list.dart

111 lines
3.5 KiB
Dart
Raw Normal View History

2022-09-28 15:47:43 +02:00
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2022-09-28 15:47:43 +02:00
2023-10-07 23:03:30 +02:00
import 'package:adguard_home_manager/screens/clients/client/active_client_tile.dart';
2023-05-01 21:34:00 +02:00
2023-04-06 18:10:23 +02:00
import 'package:adguard_home_manager/widgets/tab_content_list.dart';
2022-10-21 12:38:04 +02:00
import 'package:adguard_home_manager/providers/clients_provider.dart';
2022-09-28 15:47:43 +02:00
import 'package:adguard_home_manager/models/clients.dart';
class ClientsList extends StatelessWidget {
final List<AutoClient> data;
2023-05-01 21:34:00 +02:00
final void Function(AutoClient) onClientSelected;
final AutoClient? selectedClient;
final bool splitView;
2022-09-28 15:47:43 +02:00
const ClientsList({
Key? key,
2022-10-02 18:31:47 +02:00
required this.data,
2023-05-01 21:34:00 +02:00
required this.onClientSelected,
this.selectedClient,
2023-05-04 01:59:50 +02:00
required this.splitView,
2022-09-28 15:47:43 +02:00
}) : super(key: key);
@override
Widget build(BuildContext context) {
final clientsProvider = Provider.of<ClientsProvider>(context);
2023-04-06 18:10:23 +02:00
return CustomTabContentList(
2023-05-01 21:34:00 +02:00
listPadding: splitView == true
? const EdgeInsets.only(top: 8)
: null,
2023-04-06 18:10:23 +02:00
loadingGenerator: () => 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,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22,
color: Theme.of(context).colorScheme.onSurfaceVariant,
2022-11-04 22:56:00 +01:00
),
2023-04-06 18:10:23 +02:00
)
],
),
),
itemsCount: data.length,
2023-05-01 21:34:00 +02:00
contentWidget: (index) => ActiveClientTile(
client: data[index],
onTap: onClientSelected,
splitView: splitView,
selectedClient: selectedClient,
),
2023-04-06 18:10:23 +02:00
noData: SizedBox(
width: double.maxFinite,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.noClientsList,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 24,
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
2022-10-08 15:06:40 +02:00
),
2023-04-06 18:10:23 +02:00
const SizedBox(height: 30),
TextButton.icon(
onPressed: () => clientsProvider.fetchClients(updateLoading: false),
2023-04-06 18:10:23 +02:00
icon: const Icon(Icons.refresh_rounded),
label: Text(AppLocalizations.of(context)!.refresh)
)
],
),
),
errorGenerator: () => 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,
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 22,
color: Theme.of(context).colorScheme.onSurfaceVariant,
2022-10-08 15:06:40 +02:00
),
2023-04-06 18:10:23 +02:00
)
],
),
),
loadStatus: clientsProvider.loadStatus,
onRefresh: () => clientsProvider.fetchClients(updateLoading: false),
2023-04-06 18:10:23 +02:00
);
2022-09-28 15:47:43 +02:00
}
}