adguard-home-manager/lib/screens/home/top_items/row_item.dart

185 lines
5.4 KiB
Dart
Raw Normal View History

2023-11-01 20:47:37 +01:00
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/options_menu.dart';
2023-11-01 20:47:37 +01:00
import 'package:adguard_home_manager/models/menu_option.dart';
import 'package:adguard_home_manager/constants/enums.dart';
2023-11-01 20:47:37 +01:00
import 'package:adguard_home_manager/providers/status_provider.dart';
2024-01-25 00:50:35 +01:00
class RowItem extends StatelessWidget {
final HomeTopItems type;
2023-11-01 20:47:37 +01:00
final Color chartColor;
final String domain;
final String number;
final bool clients;
final bool showColor;
final String? unit;
final List<MenuOption> Function(dynamic) options;
final void Function(dynamic)? onTapEntry;
2023-11-01 20:47:37 +01:00
const RowItem({
super.key,
2023-11-01 20:47:37 +01:00
required this.type,
required this.chartColor,
required this.domain,
required this.number,
required this.clients,
required this.showColor,
required this.options,
this.onTapEntry,
this.unit,
});
2023-11-01 20:47:37 +01:00
@override
Widget build(BuildContext context) {
final statusProvider = Provider.of<StatusProvider>(context);
String? name;
2024-01-25 00:50:35 +01:00
if (clients == true) {
2023-11-01 20:47:37 +01:00
try {
2024-01-25 00:50:35 +01:00
name = statusProvider.serverStatus!.clients.firstWhere((c) => c.ids.contains(domain)).name;
2023-11-01 20:47:37 +01:00
} catch (e) {
// ---- //
}
}
return Material(
color: Colors.transparent,
child: OptionsMenu(
2024-01-25 00:50:35 +01:00
value: domain,
options: options,
onTap: onTapEntry,
2023-11-01 20:47:37 +01:00
child: Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 8
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Row(
children: [
2024-01-25 00:51:46 +01:00
if (showColor == true) Container(
2024-01-25 00:50:35 +01:00
margin: const EdgeInsets.only(right: 16),
width: 12,
height: 12,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: chartColor
2023-11-01 20:47:37 +01:00
),
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
2024-01-25 00:50:35 +01:00
domain,
2023-11-01 20:47:37 +01:00
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 16,
color: Theme.of(context).colorScheme.onSurface
),
),
if (name != null) ...[
const SizedBox(height: 5),
Text(
name,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 14,
color: Theme.of(context).colorScheme.onSurfaceVariant
),
),
]
],
),
),
],
),
),
const SizedBox(width: 16),
Text(
2024-01-25 00:50:35 +01:00
number,
2023-11-01 20:47:37 +01:00
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface
),
)
],
),
),
),
);
}
}
2024-01-25 00:50:35 +01:00
class OthersRowItem extends StatelessWidget {
2023-11-01 20:47:37 +01:00
final List<Map<String, dynamic>> items;
final bool showColor;
const OthersRowItem({
super.key,
2023-11-01 20:47:37 +01:00
required this.items,
required this.showColor,
});
2023-11-01 20:47:37 +01:00
@override
Widget build(BuildContext context) {
2024-01-25 00:50:35 +01:00
if (items.length <= 5) {
2023-11-01 20:47:37 +01:00
return const SizedBox();
}
2024-01-25 00:50:35 +01:00
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 20,
vertical: 8
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Row(
children: [
2024-01-25 00:51:46 +01:00
if (showColor == true) Container(
2024-01-25 00:50:35 +01:00
margin: const EdgeInsets.only(right: 16),
width: 12,
height: 12,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
color: Colors.grey
2023-11-01 20:47:37 +01:00
),
2024-01-25 00:50:35 +01:00
),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
AppLocalizations.of(context)!.others,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 16,
color: Theme.of(context).colorScheme.onSurface
2023-11-01 20:47:37 +01:00
),
2024-01-25 00:50:35 +01:00
),
],
2023-11-01 20:47:37 +01:00
),
2024-01-25 00:50:35 +01:00
),
],
2023-11-01 20:47:37 +01:00
),
2024-01-25 00:50:35 +01:00
),
const SizedBox(width: 16),
Text(
List<int>.from(
items.sublist(5, items.length).map((e) => e.values.first.toInt())
).reduce((a, b) => a + b).toString(),
style: TextStyle(
color: Theme.of(context).colorScheme.onSurface
),
)
],
2023-11-01 20:47:37 +01:00
),
);
}
}