Files
meshcore-open/lib/widgets/message_bubble_frame.dart
T
zjs81 88dcc5943f UI refresh: shared widgets, screen cleanups, and full translations
- Extract reusable widgets (chat composer/send pipeline, message bubble
  frame, reaction chips, path map scaffold, radio settings dialog,
  translation settings section, map POI clusters, nav tiles, etc.) and
  slim down the screens that used them
- Map: hide/remove markers with restore, confirm before setting node
  location, POI clustering, semantics labels
- Map cache: cancellable downloads and a bulk tile limit
- Repeater: unsaved-changes guard, CLI search/copy/share transcript,
  framed-command debug preview, disconnected banner
- Confirm before clearing chats and debug logs
- Keep cached unread totals in sync on per-contact/channel updates
- Move remaining hardcoded strings into l10n and translate the 98 new
  keys into all 17 non-English locales
2026-10-11 15:17:01 -07:00

130 lines
3.6 KiB
Dart

import 'package:flutter/material.dart';
import '../theme/mesh_theme.dart';
/// Colours shared by the direct-message and channel chat bubbles.
@immutable
class MessageBubbleColors {
final Color background;
final Color border;
final Color text;
final Color meta;
const MessageBubbleColors({
required this.background,
required this.border,
required this.text,
required this.meta,
});
/// Outgoing bubbles use [MeshPalette.me] / [MeshPalette.meBorder] /
/// [MeshPalette.meInk]; a failed send switches to the error container.
factory MessageBubbleColors.of(
ColorScheme scheme, {
required bool isOutgoing,
bool isFailed = false,
}) {
final text = isFailed
? scheme.onErrorContainer
: isOutgoing
? MeshPalette.meInk
: scheme.onSurface;
return MessageBubbleColors(
background: isFailed
? scheme.errorContainer
: isOutgoing
? MeshPalette.me
: scheme.surfaceContainerLow,
border: isFailed
? scheme.error
: isOutgoing
? MeshPalette.meBorder
: scheme.outlineVariant,
text: text,
meta: text.withValues(alpha: 0.65),
);
}
}
/// Asymmetric bubble radius: the corner nearest the sender is tight.
BorderRadius messageBubbleRadius({required bool isOutgoing}) {
return isOutgoing
? const BorderRadius.only(
topLeft: Radius.circular(MeshRadii.lg),
topRight: Radius.circular(MeshRadii.lg),
bottomLeft: Radius.circular(MeshRadii.lg),
bottomRight: Radius.circular(MeshRadii.xs),
)
: const BorderRadius.only(
topLeft: Radius.circular(MeshRadii.xs),
topRight: Radius.circular(MeshRadii.lg),
bottomLeft: Radius.circular(MeshRadii.lg),
bottomRight: Radius.circular(MeshRadii.lg),
);
}
/// Extra sender-name hues beyond the [MeshPalette] accents. They match the
/// two extra hues [AvatarCircle] uses, so a name and its avatar agree.
const Color kSenderHuePeriwinkle = Color(0xFF8FA8F0);
const Color kSenderHueAqua = Color(0xFF6FD9CE);
const List<Color> _senderHues = [
MeshPalette.blue,
MeshPalette.magenta,
MeshPalette.signal,
MeshPalette.warn,
kSenderHuePeriwinkle,
kSenderHueAqua,
];
/// Deterministic name-to-hue mapping consistent with [AvatarCircle].
Color senderNameColor(String name) {
var h = 0;
for (final c in name.codeUnits) {
h = (h * 31 + c) & 0x7fffffff;
}
return _senderHues[h % _senderHues.length];
}
/// The bubble container shared by both chat screens: colour, border,
/// asymmetric radius, padding and the 72% max width.
class MessageBubbleFrame extends StatelessWidget {
final bool isOutgoing;
final bool isFailed;
/// Tighter padding for media (GIF) content.
final bool compact;
final double maxWidth;
final Widget child;
const MessageBubbleFrame({
super.key,
required this.isOutgoing,
required this.maxWidth,
required this.child,
this.isFailed = false,
this.compact = false,
});
@override
Widget build(BuildContext context) {
final colors = MessageBubbleColors.of(
Theme.of(context).colorScheme,
isOutgoing: isOutgoing,
isFailed: isFailed,
);
return Container(
padding: compact
? const EdgeInsets.all(4)
: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
constraints: BoxConstraints(maxWidth: maxWidth * 0.72),
decoration: BoxDecoration(
color: colors.background,
borderRadius: messageBubbleRadius(isOutgoing: isOutgoing),
border: Border.all(color: colors.border, width: 1),
),
child: child,
);
}
}