71 lines
2.4 KiB
Dart
71 lines
2.4 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
import '../sessions/chat_adaptive.dart';
|
|
|
|
/// The small, non-selectable metadata line for a recorded chat message time.
|
|
/// The visible value includes a local date so messages from different days are
|
|
/// not ambiguous; the tooltip and semantics expose the full localized value.
|
|
class ChatMessageTimestamp extends StatelessWidget {
|
|
const ChatMessageTimestamp({super.key, required this.createdAt});
|
|
|
|
final int? createdAt;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final instant = createdAt == null
|
|
? null
|
|
: DateTime.fromMillisecondsSinceEpoch(
|
|
createdAt!,
|
|
isUtc: true,
|
|
).toLocal();
|
|
if (instant == null) return const SizedBox.shrink();
|
|
|
|
final cupertino =
|
|
chatControlsStyleOf(context) == ChatControlsStyle.cupertino;
|
|
final material = Localizations.of<MaterialLocalizations>(
|
|
context,
|
|
MaterialLocalizations,
|
|
);
|
|
final String date, time, full;
|
|
if (material != null) {
|
|
time = material.formatTimeOfDay(
|
|
TimeOfDay.fromDateTime(instant),
|
|
alwaysUse24HourFormat: true,
|
|
);
|
|
date = '${instant.day} ${material.formatMonthYear(instant)}';
|
|
full = '$date, $time';
|
|
} else {
|
|
final local = CupertinoLocalizations.of(context);
|
|
time =
|
|
'${local.datePickerHour(instant.hour).padLeft(2, '0')}:${local.datePickerMinute(instant.minute)}';
|
|
date =
|
|
'${local.datePickerDayOfMonth(instant.day)} ${local.datePickerMonth(instant.month)} ${local.datePickerYear(instant.year)}';
|
|
full = '$date, $time';
|
|
}
|
|
final style =
|
|
(cupertino
|
|
? CupertinoTheme.of(context).textTheme.textStyle
|
|
: (Theme.of(context).textTheme.bodySmall ?? const TextStyle()))
|
|
.copyWith(
|
|
color: cupertino
|
|
? CupertinoColors.secondaryLabel.resolveFrom(context)
|
|
: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
fontSize: 12,
|
|
);
|
|
final label = 'Sent $full';
|
|
final text = Text('$date · $time', style: style);
|
|
return SelectionContainer.disabled(
|
|
child: Tooltip(
|
|
message: full,
|
|
child: Semantics(
|
|
container: true,
|
|
label: label,
|
|
excludeSemantics: true,
|
|
child: text,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|