Added client name clients list

This commit is contained in:
Juan Gilsanz Polo 2022-10-22 03:16:08 +02:00
parent 82870ded63
commit 195f97ca64
6 changed files with 97 additions and 18 deletions

View file

@ -6,6 +6,8 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:adguard_home_manager/widgets/custom_list_tile.dart';
import 'package:adguard_home_manager/functions/number_format.dart';
import 'package:adguard_home_manager/providers/app_config_provider.dart';
import 'package:adguard_home_manager/providers/servers_provider.dart';
@ -14,11 +16,13 @@ import 'package:adguard_home_manager/services/http_requests.dart';
class TopItemsScreen extends StatelessWidget {
final String type;
final String title;
final bool? isClient;
const TopItemsScreen({
Key? key,
required this.type,
required this.title,
this.isClient,
}) : super(key: key);
@override
@ -49,6 +53,7 @@ class TopItemsScreen extends StatelessWidget {
total = total + int.parse(element.values.toList()[0].toString());
}
return Scaffold(
appBar: AppBar(
title: Text(title),
@ -71,11 +76,44 @@ class TopItemsScreen extends StatelessWidget {
},
child: ListView.builder(
itemCount: data.length,
itemBuilder: (context, index) => ListTile(
title: Text(data[index].keys.toList()[0]),
trailing: Text(data[index].values.toList()[0].toString()),
subtitle: Text("${doubleFormat((data[index].values.toList()[0]/total*100), Platform.localeName)}%")
)
itemBuilder: (context, index) {
String? name;
if (isClient != null && isClient == true) {
try {
name = serversProvider.serverStatus.data!.clients.firstWhere((c) => c.ids.contains(data[index].keys.toList()[0])).name;
} catch (e) {
// ---- //
}
}
return CustomListTile(
title: data[index].keys.toList()[0],
trailing: Text(data[index].values.toList()[0].toString()),
subtitleWidget: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
if (name != null) ...[
Text(
name,
style: TextStyle(
fontSize: 14,
color: Theme.of(context).brightness == Brightness.light
? Colors.black
: Colors.white
),
),
const SizedBox(height: 5),
],
Text(
"${doubleFormat((data[index].values.toList()[0]/total*100), Platform.localeName)}%",
style: TextStyle(
color: Theme.of(context).listTileTheme.iconColor
),
),
],
)
);
}
),
),
);