1
0
Fork 0
mrtiboute/lib/widgets/components/stream_element_card.dart

75 lines
2.2 KiB
Dart
Raw Normal View History

2022-04-14 21:57:32 +02:00
import 'package:desktopapp/classes/stream_element.dart';
2022-04-14 22:48:15 +02:00
import 'package:desktopapp/utils/requests.dart';
2022-04-14 21:57:32 +02:00
import 'package:flutter/material.dart';
2022-04-14 22:48:15 +02:00
import 'package:intl/intl.dart';
2022-04-14 21:57:32 +02:00
class StreamElementCard extends StatelessWidget {
2022-04-14 22:48:15 +02:00
const StreamElementCard({Key? key, required this.streamElement})
: super(key: key);
2022-04-14 21:57:32 +02:00
final StreamElement streamElement;
@override
Widget build(BuildContext context) {
IconData icon;
2022-04-26 20:29:09 +02:00
Color textColor;
2022-04-14 21:57:32 +02:00
switch (streamElement.type) {
case StreamElementType.log:
icon = Icons.info;
2022-04-26 20:29:09 +02:00
textColor = Colors.white;
2022-04-14 21:57:32 +02:00
break;
case StreamElementType.alert:
icon = Icons.notifications_active;
2022-04-26 20:29:09 +02:00
textColor = Colors.white;
break;
case StreamElementType.warning:
icon = Icons.warning_rounded;
textColor = Colors.yellow[600]!;
break;
case StreamElementType.error:
icon = Icons.error_rounded;
textColor = Colors.red[300]!;
2022-04-14 21:57:32 +02:00
break;
}
return Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
2022-04-14 22:48:15 +02:00
Text(
DateFormat.jms().format(streamElement.date),
style: const TextStyle(fontSize: 16),
),
const SizedBox(width: 8),
2022-04-14 21:57:32 +02:00
Icon(
icon,
size: 30,
2022-04-26 20:29:09 +02:00
color: textColor,
2022-04-14 21:57:32 +02:00
),
2022-04-14 22:48:15 +02:00
const SizedBox(width: 8),
Expanded(
child: Text(
streamElement.message,
2022-04-26 20:29:09 +02:00
style: TextStyle(fontSize: 16, color: textColor),
2022-04-14 22:48:15 +02:00
),
2022-04-14 21:57:32 +02:00
),
2022-04-14 22:48:15 +02:00
if (streamElement.type == StreamElementType.alert)
IconButton(
icon: const Icon(Icons.send),
onPressed: () async {
2022-04-17 22:32:27 +02:00
await Requests.sendAlert(streamElement.message,
type: AlertType.host);
2022-04-14 22:48:15 +02:00
},
),
2022-04-14 21:57:32 +02:00
],
)
],
),
),
);
}
}