2022-10-01 03:13:50 +02:00
|
|
|
// ignore_for_file: use_build_context_synchronously
|
2023-05-01 15:58:06 +02:00
|
|
|
|
2022-09-30 23:33:57 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-10-01 03:13:50 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2022-09-30 23:33:57 +02:00
|
|
|
|
2023-05-04 22:38:37 +02:00
|
|
|
import 'package:adguard_home_manager/widgets/domain_options.dart';
|
2022-10-01 02:00:51 +02:00
|
|
|
|
2022-10-03 22:41:19 +02:00
|
|
|
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
2022-10-02 04:25:11 +02:00
|
|
|
import 'package:adguard_home_manager/functions/get_filtered_status.dart';
|
2022-09-30 23:33:57 +02:00
|
|
|
import 'package:adguard_home_manager/models/logs.dart';
|
|
|
|
import 'package:adguard_home_manager/functions/format_time.dart';
|
|
|
|
|
|
|
|
class LogTile extends StatelessWidget {
|
|
|
|
final Log log;
|
|
|
|
final int length;
|
|
|
|
final int index;
|
2023-05-01 15:58:06 +02:00
|
|
|
final bool? isLogSelected;
|
|
|
|
final void Function(Log) onLogTap;
|
2023-05-02 14:01:49 +02:00
|
|
|
final bool? useAlwaysNormalTile;
|
2022-09-30 23:33:57 +02:00
|
|
|
|
|
|
|
const LogTile({
|
|
|
|
Key? key,
|
|
|
|
required this.log,
|
|
|
|
required this.length,
|
2023-05-01 15:58:06 +02:00
|
|
|
required this.index,
|
|
|
|
this.isLogSelected,
|
2023-05-02 14:01:49 +02:00
|
|
|
required this.onLogTap,
|
|
|
|
this.useAlwaysNormalTile
|
2022-09-30 23:33:57 +02:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-10-03 22:41:19 +02:00
|
|
|
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
2022-10-01 03:13:50 +02:00
|
|
|
|
2022-09-30 23:33:57 +02:00
|
|
|
final width = MediaQuery.of(context).size.width;
|
|
|
|
|
|
|
|
Widget logStatusWidget({
|
|
|
|
required IconData icon,
|
|
|
|
required Color color,
|
|
|
|
required String text
|
|
|
|
}) {
|
2023-01-25 20:51:23 +01:00
|
|
|
return SizedBox(
|
2023-05-01 21:34:00 +02:00
|
|
|
width: 80,
|
2022-10-21 12:33:22 +02:00
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
icon,
|
2022-09-30 23:33:57 +02:00
|
|
|
color: color,
|
2022-10-21 12:33:22 +02:00
|
|
|
size: 14,
|
|
|
|
),
|
|
|
|
const SizedBox(height: 5),
|
|
|
|
Text(
|
|
|
|
text,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
color: color,
|
|
|
|
fontSize: 12
|
|
|
|
),
|
|
|
|
)
|
|
|
|
]
|
|
|
|
),
|
2022-09-30 23:33:57 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget generateLogStatus() {
|
2022-10-26 16:51:39 +02:00
|
|
|
final filter = getFilteredStatus(context, appConfigProvider, log.reason, false);
|
2022-10-02 04:25:11 +02:00
|
|
|
return logStatusWidget(
|
|
|
|
icon: filter['icon'],
|
|
|
|
color: filter['color'],
|
|
|
|
text: filter['label'],
|
|
|
|
);
|
2022-09-30 23:33:57 +02:00
|
|
|
}
|
2023-01-04 14:08:25 +01:00
|
|
|
|
2023-05-20 21:12:52 +02:00
|
|
|
String logClient() {
|
|
|
|
if (appConfigProvider.showIpLogs == true) {
|
|
|
|
return log.client;
|
|
|
|
}
|
|
|
|
else if (log.clientInfo != null && log.clientInfo!.name != "") {
|
|
|
|
return log.clientInfo!.name;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return log.client;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-02 14:01:49 +02:00
|
|
|
if (width > 1100 && !(useAlwaysNormalTile == true)) {
|
2023-05-01 15:58:06 +02:00
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
2023-05-04 22:38:37 +02:00
|
|
|
child: InkWell(
|
2023-05-01 15:58:06 +02:00
|
|
|
borderRadius: BorderRadius.circular(28),
|
2023-05-04 22:38:37 +02:00
|
|
|
child: DomainOptions(
|
2023-05-01 15:58:06 +02:00
|
|
|
onTap: () => onLogTap(log),
|
2023-05-04 22:38:37 +02:00
|
|
|
borderRadius: BorderRadius.circular(28),
|
|
|
|
item: log.question.name,
|
|
|
|
isBlocked: isDomainBlocked(log.reason),
|
2023-05-01 15:58:06 +02:00
|
|
|
child: Container(
|
|
|
|
width: double.maxFinite,
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(28),
|
|
|
|
color: isLogSelected == true
|
|
|
|
? Theme.of(context).colorScheme.primaryContainer
|
|
|
|
: null
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Flexible(
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
2022-10-21 12:33:22 +02:00
|
|
|
children: [
|
2023-05-01 15:58:06 +02:00
|
|
|
Flexible(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
2023-05-20 20:31:48 +02:00
|
|
|
log.question.name ?? "N/A",
|
2023-05-01 15:58:06 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16,
|
|
|
|
fontWeight: FontWeight.w400,
|
|
|
|
color: Theme.of(context).colorScheme.onSurface,
|
|
|
|
),
|
2022-10-21 12:33:22 +02:00
|
|
|
),
|
2023-05-01 15:58:06 +02:00
|
|
|
const SizedBox(height: 5),
|
2023-05-20 21:12:52 +02:00
|
|
|
if (log.client.length <= 15 && appConfigProvider.showTimeLogs == false) Row(
|
2023-05-01 15:58:06 +02:00
|
|
|
children: [
|
|
|
|
...[
|
|
|
|
Icon(
|
|
|
|
Icons.smartphone_rounded,
|
|
|
|
size: 16,
|
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
|
|
|
),
|
2023-05-20 21:12:52 +02:00
|
|
|
const SizedBox(width: 8),
|
2023-05-01 15:58:06 +02:00
|
|
|
Flexible(
|
|
|
|
child: Text(
|
2023-05-20 21:12:52 +02:00
|
|
|
logClient(),
|
2023-05-01 15:58:06 +02:00
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
|
|
|
fontSize: 14,
|
|
|
|
height: 1.4,
|
|
|
|
fontWeight: FontWeight.w400,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
2023-05-20 21:12:52 +02:00
|
|
|
const SizedBox(width: 16),
|
2023-05-01 15:58:06 +02:00
|
|
|
...[
|
|
|
|
Icon(
|
|
|
|
Icons.schedule_rounded,
|
|
|
|
size: 16,
|
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
|
|
|
),
|
2023-05-20 21:12:52 +02:00
|
|
|
const SizedBox(width: 8),
|
2023-05-01 15:58:06 +02:00
|
|
|
Flexible(
|
|
|
|
child: Text(
|
|
|
|
convertTimestampLocalTimezone(log.time, 'HH:mm:ss'),
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
|
|
|
fontSize: 13
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
],
|
2022-10-21 12:33:22 +02:00
|
|
|
),
|
2023-05-20 21:12:52 +02:00
|
|
|
if (log.client.length > 15 || appConfigProvider.showTimeLogs == true) Column(
|
2023-05-01 15:58:06 +02:00
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
Icons.smartphone_rounded,
|
|
|
|
size: 16,
|
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
|
|
|
),
|
2023-05-20 21:12:52 +02:00
|
|
|
const SizedBox(width: 8),
|
2023-05-01 15:58:06 +02:00
|
|
|
Flexible(
|
|
|
|
child: Text(
|
2023-05-20 21:12:52 +02:00
|
|
|
logClient(),
|
2023-05-01 15:58:06 +02:00
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
|
|
|
fontSize: 13
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
Icons.schedule_rounded,
|
|
|
|
size: 16,
|
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
|
|
|
),
|
2023-05-20 21:12:52 +02:00
|
|
|
const SizedBox(width: 8),
|
2023-05-01 15:58:06 +02:00
|
|
|
SizedBox(
|
|
|
|
child: Text(
|
|
|
|
convertTimestampLocalTimezone(log.time, 'HH:mm:ss'),
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
|
|
|
fontSize: 13
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2023-05-20 21:12:52 +02:00
|
|
|
if (appConfigProvider.showTimeLogs == true && log.elapsedMs != '') ...[
|
2023-05-01 15:58:06 +02:00
|
|
|
const SizedBox(height: 10),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
Icons.timer,
|
|
|
|
size: 16,
|
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
|
|
|
),
|
2023-05-20 21:12:52 +02:00
|
|
|
const SizedBox(width: 8),
|
2023-05-01 15:58:06 +02:00
|
|
|
SizedBox(
|
|
|
|
child: Text(
|
|
|
|
"${double.parse(log.elapsedMs).toStringAsFixed(2)} ms",
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
|
|
|
fontSize: 13
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
|
|
|
],
|
2022-10-27 22:57:59 +02:00
|
|
|
),
|
2023-05-01 15:58:06 +02:00
|
|
|
)
|
2022-10-21 12:33:22 +02:00
|
|
|
],
|
2022-09-30 23:33:57 +02:00
|
|
|
),
|
2023-05-01 15:58:06 +02:00
|
|
|
),
|
|
|
|
generateLogStatus()
|
|
|
|
],
|
|
|
|
)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return Material(
|
|
|
|
color: Colors.transparent,
|
2023-05-04 22:38:37 +02:00
|
|
|
child: DomainOptions(
|
2023-05-01 15:58:06 +02:00
|
|
|
onTap: () => onLogTap(log),
|
2023-05-04 22:38:37 +02:00
|
|
|
item: log.question.name,
|
|
|
|
isBlocked: isDomainBlocked(log.reason),
|
2023-05-01 15:58:06 +02:00
|
|
|
child: Container(
|
|
|
|
width: double.maxFinite,
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
2023-05-20 20:31:48 +02:00
|
|
|
log.question.name ?? "N/A",
|
2023-05-01 15:58:06 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16,
|
|
|
|
height: 1.5,
|
|
|
|
fontWeight: FontWeight.w400,
|
|
|
|
color: Theme.of(context).colorScheme.onSurface
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(height: 5),
|
2023-05-20 21:12:52 +02:00
|
|
|
if (log.client.length <= 15 && appConfigProvider.showTimeLogs == false) Row(
|
2023-05-01 15:58:06 +02:00
|
|
|
children: [
|
|
|
|
...[
|
2022-10-21 12:33:22 +02:00
|
|
|
Icon(
|
|
|
|
Icons.smartphone_rounded,
|
|
|
|
size: 16,
|
2022-11-05 02:35:35 +01:00
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
2022-10-21 12:33:22 +02:00
|
|
|
),
|
2023-05-20 21:12:52 +02:00
|
|
|
const SizedBox(width: 8),
|
2022-12-17 22:18:39 +01:00
|
|
|
Flexible(
|
2022-10-21 12:33:22 +02:00
|
|
|
child: Text(
|
2023-05-20 21:12:52 +02:00
|
|
|
logClient(),
|
2022-10-21 12:33:22 +02:00
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
2022-11-05 02:35:35 +01:00
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
2023-05-01 15:58:06 +02:00
|
|
|
fontSize: 14,
|
|
|
|
height: 1.4,
|
|
|
|
fontWeight: FontWeight.w400,
|
2022-10-21 12:33:22 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
2023-05-20 21:12:52 +02:00
|
|
|
const SizedBox(width: 16),
|
2023-05-01 15:58:06 +02:00
|
|
|
...[
|
|
|
|
Icon(
|
|
|
|
Icons.schedule_rounded,
|
|
|
|
size: 16,
|
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
|
|
|
),
|
2023-05-20 21:12:52 +02:00
|
|
|
const SizedBox(width: 8),
|
2023-05-01 15:58:06 +02:00
|
|
|
Flexible(
|
|
|
|
child: Text(
|
|
|
|
convertTimestampLocalTimezone(log.time, 'HH:mm:ss'),
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
|
|
|
fontSize: 13
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
),
|
2023-05-20 21:12:52 +02:00
|
|
|
if (log.client.length > 15 || appConfigProvider.showTimeLogs == true) Column(
|
2023-05-01 15:58:06 +02:00
|
|
|
children: [
|
2022-10-27 22:57:59 +02:00
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
2023-05-01 15:58:06 +02:00
|
|
|
Icons.smartphone_rounded,
|
2022-10-27 22:57:59 +02:00
|
|
|
size: 16,
|
2023-05-01 15:58:06 +02:00
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
2022-10-27 22:57:59 +02:00
|
|
|
),
|
2023-05-20 21:12:52 +02:00
|
|
|
const SizedBox(width: 8),
|
2022-12-17 22:18:39 +01:00
|
|
|
Flexible(
|
2022-10-27 22:57:59 +02:00
|
|
|
child: Text(
|
2023-05-20 21:12:52 +02:00
|
|
|
logClient(),
|
2022-10-27 22:57:59 +02:00
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
2022-11-05 02:35:35 +01:00
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
2022-10-27 22:57:59 +02:00
|
|
|
fontSize: 13
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
Row(
|
|
|
|
children: [
|
2023-05-20 21:12:52 +02:00
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
Icons.schedule_rounded,
|
|
|
|
size: 16,
|
2022-11-05 02:35:35 +01:00
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
2022-10-27 22:57:59 +02:00
|
|
|
),
|
2023-05-20 21:12:52 +02:00
|
|
|
const SizedBox(width: 8),
|
|
|
|
SizedBox(
|
|
|
|
child: Text(
|
|
|
|
convertTimestampLocalTimezone(log.time, 'HH:mm:ss'),
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
|
|
|
fontSize: 13
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
if (appConfigProvider.showTimeLogs == true && log.elapsedMs != '') ...[
|
|
|
|
const SizedBox(width: 16),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
Icons.timer,
|
|
|
|
size: 16,
|
2023-05-01 15:58:06 +02:00
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
|
|
|
),
|
2023-05-20 21:12:52 +02:00
|
|
|
const SizedBox(width: 8),
|
|
|
|
SizedBox(
|
|
|
|
child: Text(
|
|
|
|
"${double.parse(log.elapsedMs).toStringAsFixed(2)} ms",
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).listTileTheme.textColor,
|
|
|
|
fontSize: 13
|
|
|
|
),
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2023-05-01 15:58:06 +02:00
|
|
|
],
|
2023-05-20 21:12:52 +02:00
|
|
|
],
|
|
|
|
),
|
2022-10-27 22:57:59 +02:00
|
|
|
],
|
2023-05-01 15:58:06 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-10-21 12:33:22 +02:00
|
|
|
),
|
2023-05-01 15:58:06 +02:00
|
|
|
const SizedBox(width: 10),
|
|
|
|
generateLogStatus()
|
|
|
|
],
|
|
|
|
),
|
2022-09-30 23:33:57 +02:00
|
|
|
),
|
|
|
|
),
|
2023-05-01 15:58:06 +02:00
|
|
|
);
|
|
|
|
}
|
2022-09-30 23:33:57 +02:00
|
|
|
}
|
|
|
|
}
|