From f4847c240723f1779b880f72ce0aaaeb2de88ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20R=C3=A1=C5=BE?= Date: Tue, 17 Nov 2026 23:53:53 +0100 Subject: [PATCH] fix(chat): let an attachment fill its bubble Every bubble was painted with the accent background and 16x10 padding, so an image, gif, album, video, voice note or file sat inside a coloured frame instead of being the bubble. Media bubbles now drop that padding and background and clip the attachment to the bubble corners; only a reply keeps a surface, because its quote still needs one. The selection border moved to `foregroundDecoration`: with the bubble clipped, a border in `decoration` is painted under the attachment and disappears as soon as the media covers it. --- lib/widgets/chat_bubble.dart | 37 ++++++++++++++++++++++++++---------- test/chat_bubble_test.dart | 25 ++++++++++++++++++++++++ 2 files changed, 52 insertions(+), 10 deletions(-) diff --git a/lib/widgets/chat_bubble.dart b/lib/widgets/chat_bubble.dart index 6bf6257..af6e414 100644 --- a/lib/widgets/chat_bubble.dart +++ b/lib/widgets/chat_bubble.dart @@ -289,21 +289,38 @@ class _ChatBubbleState extends State { ], ); - // Emoji-only messages drop the bubble chrome and read large. + // Emoji-only messages drop the bubble chrome and read large; an attachment + // is the bubble, so it is clipped to the corners instead of sitting inside + // a coloured frame. + final isMedia = widget.message.isMedia; final bubbleBox = Container( decoration: BoxDecoration( - color: _isLargeEmoji ? null : bubbleBackground(), + // A reply needs a surface for its quote; the attachment below fills the + // rest of the bubble. + color: isMedia + ? (widget.message.isReply ? bubbleBackground() : null) + : (_isLargeEmoji ? null : bubbleBackground()), borderRadius: BorderRadius.circular(20), - border: widget.selected - ? Border.all( + ), + // Above the child: a border in the decoration would sit under an + // attachment that fills the bubble. + foregroundDecoration: widget.selected + ? BoxDecoration( + borderRadius: BorderRadius.circular(20), + border: Border.all( color: Theme.of(context).colorScheme.primary, width: 2, - ) - : null, - ), - padding: _isLargeEmoji - ? EdgeInsets.zero - : const EdgeInsets.symmetric(horizontal: 16, vertical: 10), + ), + ) + : null, + clipBehavior: isMedia ? Clip.antiAlias : Clip.none, + padding: isMedia + ? (widget.message.isReply + ? const EdgeInsets.fromLTRB(8, 8, 8, 0) + : EdgeInsets.zero) + : (_isLargeEmoji + ? EdgeInsets.zero + : const EdgeInsets.symmetric(horizontal: 16, vertical: 10)), child: bubble, ); diff --git a/test/chat_bubble_test.dart b/test/chat_bubble_test.dart index 2d7bf24..07ee74b 100644 --- a/test/chat_bubble_test.dart +++ b/test/chat_bubble_test.dart @@ -10,6 +10,8 @@ import 'package:whisper/models/user.dart'; import 'package:whisper/utils/singleton.dart'; import 'package:whisper/utils/text_envelope.dart'; import 'package:whisper/widgets/chat_bubble.dart'; +import 'package:whisper/widgets/media_bubble.dart'; +import 'package:whisper_websocket_client_dart/models/media_type.dart'; /// Plain text of everything the bubble rendered, spans included. String renderedText(WidgetTester tester) => tester @@ -168,5 +170,28 @@ void main() { TextDecorationStyle.solid, reason: tappable); } + + // An attachment is the bubble: no coloured frame or padding around it. + await show(ChatBubble( + null, + PrivateMessage( + '2', + '', + DateTime(2026), + DateTime(2026), + true, + mediaTypeStr: MediaType.image.name, + downloadStatus: MediaDownloadStatus.failed, + ), + null, + peer, + accentColor: Colors.blue, + )); + final mediaFrame = tester.widget(find + .ancestor( + of: find.byType(MediaBubble), matching: find.byType(Container)) + .first); + expect(mediaFrame.padding, EdgeInsets.zero); + expect((mediaFrame.decoration as BoxDecoration?)?.color, isNull); }); }