adguard-home-manager/lib/screens/logs/log_tile.dart

239 lines
9 KiB
Dart
Raw Normal View History

// ignore_for_file: use_build_context_synchronously
2022-09-30 23:33:57 +02:00
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
2022-09-30 23:33:57 +02:00
2022-11-03 14:51:32 +01:00
import 'package:adguard_home_manager/screens/logs/log_details_screen.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;
const LogTile({
Key? key,
required this.log,
required this.length,
required this.index
}) : super(key: key);
@override
Widget build(BuildContext context) {
2022-10-03 22:41:19 +02:00
final appConfigProvider = Provider.of<AppConfigProvider>(context);
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
}) {
2022-10-21 12:33:22 +02:00
return Flexible(
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() {
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
}
2022-11-03 14:51:32 +01:00
2022-09-30 23:33:57 +02:00
return Material(
color: Colors.transparent,
child: InkWell(
2022-11-03 14:51:32 +01:00
onTap: () => Navigator.push(context, MaterialPageRoute(
builder: (context) => LogDetailsScreen(log: log)
)),
2022-09-30 23:33:57 +02:00
child: Container(
width: double.maxFinite,
2022-11-04 22:56:00 +01:00
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
2022-09-30 23:33:57 +02:00
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
2022-10-21 12:33:22 +02:00
SizedBox(
width: width-130,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
2022-09-30 23:33:57 +02:00
log.question.name,
2022-11-04 17:04:25 +01:00
style: TextStyle(
2022-11-03 14:51:32 +01:00
fontSize: 16,
height: 1.5,
fontWeight: FontWeight.w400,
2022-11-04 17:04:25 +01:00
color: Theme.of(context).colorScheme.onSurface
2022-09-30 23:33:57 +02:00
),
),
2022-11-03 14:51:32 +01:00
const SizedBox(height: 5),
if (log.client.length <= 15 && appConfigProvider.showNameTimeLogs == false) Row(
2022-10-21 12:33:22 +02:00
children: [
...[
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
),
const SizedBox(width: 5),
SizedBox(
child: Text(
log.client,
overflow: TextOverflow.ellipsis,
style: TextStyle(
2022-11-05 02:35:35 +01:00
color: Theme.of(context).listTileTheme.textColor,
2022-11-03 14:51:32 +01:00
fontSize: 14,
height: 1.4,
fontWeight: FontWeight.w400,
2022-10-21 12:33:22 +02:00
),
),
)
],
const SizedBox(width: 15),
...[
Icon(
Icons.schedule_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
),
const SizedBox(width: 5),
SizedBox(
child: Text(
formatTimestampUTCFromAPI(log.time, 'HH:mm:ss'),
overflow: TextOverflow.ellipsis,
style: TextStyle(
2022-11-05 02:35:35 +01:00
color: Theme.of(context).listTileTheme.textColor,
2022-10-21 12:33:22 +02:00
fontSize: 13
),
),
),
2022-10-21 12:33:22 +02:00
],
],
2022-09-30 23:33:57 +02:00
),
if (log.client.length > 15 || appConfigProvider.showNameTimeLogs == true) Column(
2022-10-21 12:33:22 +02:00
children: [
Row(
children: [
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
),
const SizedBox(width: 15),
SizedBox(
child: Text(
log.client,
overflow: TextOverflow.ellipsis,
style: TextStyle(
2022-11-05 02:35:35 +01:00
color: Theme.of(context).listTileTheme.textColor,
2022-10-21 12:33:22 +02:00
fontSize: 13
),
),
)
],
),
if (appConfigProvider.showNameTimeLogs == true && log.clientInfo!.name != '') ...[
const SizedBox(height: 10),
Row(
children: [
Icon(
Icons.badge_rounded,
size: 16,
2022-11-04 17:04:25 +01:00
color: Theme.of(context).colorScheme.onSurfaceVariant,
),
const SizedBox(width: 15),
SizedBox(
child: Text(
log.clientInfo!.name,
overflow: TextOverflow.ellipsis,
style: TextStyle(
2022-11-05 02:35:35 +01:00
color: Theme.of(context).listTileTheme.textColor,
fontSize: 13
),
),
)
],
),
],
2022-10-21 12:33:22 +02:00
const SizedBox(height: 10),
Row(
children: [
Icon(
Icons.schedule_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
),
const SizedBox(width: 15),
SizedBox(
child: Text(
formatTimestampUTCFromAPI(log.time, 'HH:mm:ss'),
overflow: TextOverflow.ellipsis,
style: TextStyle(
2022-11-05 02:35:35 +01:00
color: Theme.of(context).listTileTheme.textColor,
2022-10-21 12:33:22 +02:00
fontSize: 13
),
),
)
],
),
if (appConfigProvider.showNameTimeLogs == true && log.elapsedMs != '') ...[
const SizedBox(height: 10),
Row(
children: [
Icon(
Icons.timer,
size: 16,
2022-11-05 02:35:35 +01:00
color: Theme.of(context).listTileTheme.textColor,
),
const SizedBox(width: 15),
SizedBox(
child: Text(
"${double.parse(log.elapsedMs).toStringAsFixed(2)} ms",
overflow: TextOverflow.ellipsis,
style: TextStyle(
2022-11-05 02:35:35 +01:00
color: Theme.of(context).listTileTheme.textColor,
fontSize: 13
),
),
)
],
),
],
2022-10-21 12:33:22 +02:00
],
),
],
),
2022-09-30 23:33:57 +02:00
),
2022-10-21 12:33:22 +02:00
const SizedBox(width: 10),
generateLogStatus()
2022-09-30 23:33:57 +02:00
],
),
),
),
);
}
}