1
0
Fork 0
mrtiboute/lib/widgets/components/stream_element_card.dart
2022-04-26 20:29:09 +02:00

74 lines
2.2 KiB
Dart

import 'package:desktopapp/classes/stream_element.dart';
import 'package:desktopapp/utils/requests.dart';
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
class StreamElementCard extends StatelessWidget {
const StreamElementCard({Key? key, required this.streamElement})
: super(key: key);
final StreamElement streamElement;
@override
Widget build(BuildContext context) {
IconData icon;
Color textColor;
switch (streamElement.type) {
case StreamElementType.log:
icon = Icons.info;
textColor = Colors.white;
break;
case StreamElementType.alert:
icon = Icons.notifications_active;
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]!;
break;
}
return Card(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Text(
DateFormat.jms().format(streamElement.date),
style: const TextStyle(fontSize: 16),
),
const SizedBox(width: 8),
Icon(
icon,
size: 30,
color: textColor,
),
const SizedBox(width: 8),
Expanded(
child: Text(
streamElement.message,
style: TextStyle(fontSize: 16, color: textColor),
),
),
if (streamElement.type == StreamElementType.alert)
IconButton(
icon: const Icon(Icons.send),
onPressed: () async {
await Requests.sendAlert(streamElement.message,
type: AlertType.host);
},
),
],
)
],
),
),
);
}
}