2023-05-15 09:45:41 -04:00
|
|
|
import 'package:contacts_plus_plus/client_holder.dart';
|
2023-05-06 13:24:28 -04:00
|
|
|
import 'package:contacts_plus_plus/models/message.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2023-05-15 09:45:41 -04:00
|
|
|
import 'package:intl/intl.dart';
|
2023-05-06 13:24:28 -04:00
|
|
|
|
|
|
|
class MessageStateIndicator extends StatelessWidget {
|
2023-05-15 09:45:41 -04:00
|
|
|
MessageStateIndicator({required this.message, this.foregroundColor, super.key});
|
2023-05-06 13:24:28 -04:00
|
|
|
|
2023-05-15 09:45:41 -04:00
|
|
|
final DateFormat _dateFormat = DateFormat.Hm();
|
|
|
|
final Message message;
|
|
|
|
final Color? foregroundColor;
|
2023-05-06 13:24:28 -04:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-05-15 09:45:41 -04:00
|
|
|
final color = foregroundColor?.withAlpha(150);
|
|
|
|
return Row(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 4.0),
|
|
|
|
child: Text(
|
|
|
|
_dateFormat.format(message.sendTime.toLocal()),
|
|
|
|
style: Theme
|
|
|
|
.of(context)
|
|
|
|
.textTheme
|
|
|
|
.labelMedium
|
|
|
|
?.copyWith(color: color),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (message.senderId == ClientHolder
|
|
|
|
.of(context)
|
|
|
|
.apiClient
|
|
|
|
.userId)
|
|
|
|
Icon(
|
|
|
|
switch (message.state) {
|
|
|
|
MessageState.local => Icons.alarm,
|
|
|
|
MessageState.sent => Icons.done,
|
|
|
|
MessageState.read => Icons.done_all,
|
|
|
|
},
|
|
|
|
size: 12,
|
|
|
|
color: color,
|
|
|
|
),
|
|
|
|
],
|
2023-05-06 13:24:28 -04:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|