11import 'dart:typed_data' ;
22
33import 'package:flutter/material.dart' ;
4+ import 'package:flutter_svg/svg.dart' ;
45import 'package:matrix/matrix.dart' ;
56import 'package:watch_it/watch_it.dart' ;
67import 'package:yaru/yaru.dart' ;
78
89import '../../../common/view/image_shimmer.dart' ;
910import '../../../common/view/ui_constants.dart' ;
10- import '../../common/chat_model .dart' ;
11+ import '../../common/event_x .dart' ;
1112import '../../common/local_image_model.dart' ;
1213import '../chat_download_model.dart' ;
13- import 'chat_event_status_icon.dart' ;
1414import 'chat_message_attachment_indicator.dart' ;
15- import 'chat_message_menu.dart' ;
16- import 'chat_message_reactions.dart' ;
1715
1816class ChatImage extends StatelessWidget with WatchItMixin {
1917 const ChatImage ({
@@ -45,109 +43,56 @@ class ChatImage extends StatelessWidget with WatchItMixin {
4543 final theHeight = dimension ?? height ?? imageHeight;
4644 final theWidth = dimension ?? width;
4745 final theFit = fit ?? BoxFit .cover;
48- final isUserMessage = di <ChatModel >().isUserEvent (event);
4946 final maybeImage =
5047 watchPropertyValue ((LocalImageModel m) => m.get (event.eventId));
5148
5249 return Padding (
53- padding: EdgeInsets .only (
54- top: kBigPadding,
55- bottom: kBigPadding,
56- right: kSmallPadding,
57- left: (isUserMessage ? 0 : kAvatarDefaultSize + kBigPadding),
58- ),
59- child: Align (
60- alignment: isUserMessage ? Alignment .centerRight : Alignment .centerLeft,
61- child: ClipRRect (
62- borderRadius: const BorderRadius .all (kBigBubbleRadius),
63- child: Stack (
64- children: [
65- ChatMessageMenu (
66- event: event,
67- child: SizedBox (
68- height: theHeight,
69- width: theWidth,
70- child: maybeImage != null
71- ? Image .memory (
50+ padding: const EdgeInsets .symmetric (vertical: kSmallPadding),
51+ child: ClipRRect (
52+ borderRadius: const BorderRadius .all (kBigBubbleRadius),
53+ child: Stack (
54+ children: [
55+ SizedBox (
56+ height: theHeight,
57+ width: theWidth,
58+ child: maybeImage != null
59+ ? event.isSvgImage
60+ ? SvgPicture .memory (
7261 maybeImage,
7362 fit: theFit,
7463 height: theHeight,
7564 width: theWidth,
7665 )
77- : ChatImageFuture (
78- event: event,
79- width: theWidth,
80- height: theHeight,
66+ : Image .memory (
67+ maybeImage,
8168 fit: theFit,
82- ),
83- ),
84- ),
85- if (! event.redacted)
86- Positioned (
87- left: kSmallPadding,
88- bottom: kSmallPadding,
89- child: ChatMessageReactions (
90- key: ValueKey ('${event .eventId }reactions' ),
91- event: event,
92- timeline: timeline,
93- ),
94- ),
95- Positioned (
96- top: kSmallPadding,
97- right: 10 * kSmallPadding,
98- child: IconButton (
99- style: IconButton .styleFrom (
100- backgroundColor: Colors .black.withValues (alpha: 0.5 ),
101- shape: const CircleBorder (),
102- ),
103- onPressed: () => di <ChatDownloadModel >().safeFile (event),
104- icon: ChatMessageAttachmentIndicator (
105- event: event,
106- iconSize: 22 ,
107- color: Colors .white,
108- ),
109- ),
110- ),
111- if (isUserMessage)
112- Positioned (
113- bottom: 0 ,
114- right: 0 ,
115- child: Container (
116- padding:
117- const EdgeInsets .symmetric (horizontal: kSmallPadding),
118- margin: const EdgeInsets .all (kMediumPadding),
119- decoration: BoxDecoration (
120- borderRadius: BorderRadius .circular (kBigPadding),
121- color: Colors .black.withValues (alpha: 0.5 ),
122- ),
123- child: ChatEventStatusIcon (
124- timeline: timeline,
125- padding: const EdgeInsets .all (kTinyPadding),
126- event: event,
127- foregroundColor: Colors .white,
128- ),
129- ),
130- )
131- else
132- Positioned (
133- bottom: 0 ,
134- right: 0 ,
135- child: Container (
136- padding:
137- const EdgeInsets .symmetric (horizontal: kSmallPadding),
138- margin: const EdgeInsets .all (kMediumPadding),
139- decoration: BoxDecoration (
140- borderRadius: BorderRadius .circular (kBigPadding),
141- color: Colors .black.withValues (alpha: 0.5 ),
142- ),
143- child: ChatEventStatusIcon (
144- timeline: timeline,
145- padding: const EdgeInsets .all (kTinyPadding),
69+ height: theHeight,
70+ width: theWidth,
71+ )
72+ : ChatImageFuture (
14673 event: event,
147- foregroundColor: Colors .white,
74+ width: theWidth,
75+ height: theHeight,
76+ fit: theFit,
14877 ),
149- ),
78+ ),
79+ Positioned (
80+ top: kSmallPadding,
81+ right: onTap != null ? 10 * kSmallPadding : kSmallPadding,
82+ child: IconButton (
83+ style: IconButton .styleFrom (
84+ backgroundColor: Colors .black.withValues (alpha: 0.5 ),
85+ shape: const CircleBorder (),
15086 ),
87+ onPressed: () => di <ChatDownloadModel >().safeFile (event),
88+ icon: ChatMessageAttachmentIndicator (
89+ event: event,
90+ iconSize: 22 ,
91+ color: Colors .white,
92+ ),
93+ ),
94+ ),
95+ if (onTap != null )
15196 Positioned (
15297 top: kSmallPadding,
15398 right: kSmallPadding,
@@ -163,8 +108,7 @@ class ChatImage extends StatelessWidget with WatchItMixin {
163108 ),
164109 ),
165110 ),
166- ],
167- ),
111+ ],
168112 ),
169113 ),
170114 );
@@ -207,6 +151,19 @@ class _ChatImageFutureState extends State<ChatImageFuture> {
207151 builder: (context, snapshot) {
208152 if (snapshot.hasData) {
209153 final data = snapshot.data;
154+
155+ if (widget.event.isSvgImage ||
156+ widget.event.thumbnailMimetype == 'image/svg+xml' ||
157+ widget.event.attachmentMimetype.contains ('svg' ) ||
158+ widget.event.thumbnailMimetype.contains ('svg' )) {
159+ SvgPicture .memory (
160+ data! ,
161+ fit: widget.fit ?? BoxFit .contain,
162+ height: widget.height,
163+ width: widget.width,
164+ );
165+ }
166+
210167 return Image .memory (
211168 data! ,
212169 fit: widget.fit,
0 commit comments