78 lines
2.7 KiB
Dart
78 lines
2.7 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: MediaQuery.alwaysUse24HourFormatOf(context),
|
|
);
|
|
date = material.formatCompactDate(instant);
|
|
full = '${material.formatFullDate(instant)}, $time';
|
|
} else {
|
|
final local = CupertinoLocalizations.of(context);
|
|
final use24 = MediaQuery.alwaysUse24HourFormatOf(context);
|
|
final hour = use24
|
|
? instant.hour
|
|
: (instant.hour % 12 == 0 ? 12 : instant.hour % 12);
|
|
final period = use24
|
|
? ''
|
|
: ' ${instant.hour < 12 ? local.anteMeridiemAbbreviation : local.postMeridiemAbbreviation}';
|
|
time =
|
|
'${local.datePickerHour(hour)}:${local.datePickerMinute(instant.minute)}$period';
|
|
date =
|
|
'${local.datePickerMediumDate(instant)} ${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,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|