Skip to content

Commit a312011

Browse files
committed
feat: increased image performance
Added resizing to images which dramatically increased efficiency. Drastically decreased memory usages. Imporved cached images loading time. Fixed PostMedia carousel rebuilding. Previously, PostView always used InViewNotifier. That caused widget inside of the InViewNotifier widget to constantly rebuild. However, we need to track whether the widget is in view only if it is video. We shouldn't have wrapped images with InViewNotifierWidget. Fixed send duplicated attachments issue.
1 parent e2d9f3d commit a312011

33 files changed

+384
-162
lines changed

lib/auth/login/view/login_page.dart

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,29 @@ class LoginView extends StatelessWidget {
5656
),
5757
),
5858
const Align(child: SignInButton()),
59-
const Padding(
60-
padding: EdgeInsets.symmetric(
61-
vertical: AppSpacing.md,
62-
),
63-
child: AppDivider(withText: true),
59+
Row(
60+
children: <Widget>[
61+
const Expanded(
62+
child: AppDivider(
63+
endIndent: AppSpacing.sm,
64+
indent: AppSpacing.md,
65+
color: AppColors.white,
66+
height: 36,
67+
),
68+
),
69+
Text(
70+
'OR',
71+
style: context.titleMedium,
72+
),
73+
const Expanded(
74+
child: AppDivider(
75+
color: AppColors.white,
76+
indent: AppSpacing.sm,
77+
endIndent: AppSpacing.md,
78+
height: 36,
79+
),
80+
),
81+
],
6482
),
6583
Align(
6684
child: AuthProviderSignInButton(

lib/chats/chat/view/chat_page.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,11 @@ class ChatAppBar extends StatelessWidget implements PreferredSizeWidget {
456456
title: Text(participant.displayUsername),
457457
subtitle: Text(context.l10n.onlineText),
458458
leading: UserStoriesAvatar(
459+
resizeHeight: 156,
459460
author: participant,
460461
enableInactiveBorder: false,
461462
withAdaptiveBorder: false,
462-
radius: 26,
463+
radius: 22,
463464
),
464465
),
465466
bottom: const PreferredSize(

lib/chats/chat/widgets/message_content.dart

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,7 @@ class MessageSharedPost extends StatelessWidget {
236236
),
237237
Stack(
238238
children: [
239-
AspectRatio(
240-
aspectRatio: 1,
241-
child: ImageAttachmentThumbnail(
242-
image: Attachment(imageUrl: sharedPost.firstMediaUrl),
243-
fit: BoxFit.cover,
244-
),
245-
),
239+
MessageSharedPostImage(sharedPost: sharedPost),
246240
Positioned(
247241
top: AppSpacing.sm,
248242
right: AppSpacing.sm,
@@ -329,6 +323,31 @@ class MessageSharedPost extends StatelessWidget {
329323
}
330324
}
331325

326+
class MessageSharedPostImage extends StatelessWidget {
327+
const MessageSharedPostImage({
328+
required this.sharedPost,
329+
super.key,
330+
});
331+
332+
final PostBlock sharedPost;
333+
334+
@override
335+
Widget build(BuildContext context) {
336+
final screenWidth = (context.screenWidth * .85) - AppSpacing.md * 2;
337+
final pixelRatio = context.devicePixelRatio;
338+
339+
final thumbnailWidth = (screenWidth * pixelRatio) ~/ 1;
340+
return AspectRatio(
341+
aspectRatio: 1,
342+
child: ImageAttachmentThumbnail(
343+
resizeHeight: thumbnailWidth,
344+
image: Attachment(imageUrl: sharedPost.firstMediaUrl),
345+
fit: BoxFit.cover,
346+
),
347+
);
348+
}
349+
}
350+
332351
class MessageSharedReel extends StatelessWidget {
333352
const MessageSharedReel({
334353
required this.sharedPost,

lib/chats/chat/widgets/message_input_controller.dart

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -144,26 +144,11 @@ class MessageInputController extends ValueNotifier<Message> {
144144
attachments = [...attachments, attachment];
145145
}
146146

147-
/// Adds a new attachment at the specified [index].
148-
void addAttachmentAt(int index, Attachment attachment) {
149-
attachments = [...attachments]..insert(index, attachment);
150-
}
151-
152147
/// Removes the specified [attachment] from the message.
153148
void removeAttachment(Attachment attachment) {
154149
attachments = [...attachments]..remove(attachment);
155150
}
156151

157-
/// Remove the attachment with the given [attachmentId].
158-
void removeAttachmentById(String attachmentId) {
159-
attachments = [...attachments]..removeWhere((it) => it.id == attachmentId);
160-
}
161-
162-
/// Removes the attachment at the given [index].
163-
void removeAttachmentAt(int index) {
164-
attachments = [...attachments]..removeAt(index);
165-
}
166-
167152
/// Clears the message attachments.
168153
void clearAttachments() {
169154
attachments = [];
@@ -242,17 +227,12 @@ class MessageInputController extends ValueNotifier<Message> {
242227
if (attachments
243228
.map((e) => e.type.toAttachmentType)
244229
.contains(AttachmentType.urlPreview)) {
245-
attachments.retainWhere(
246-
(e) => e.type.toAttachmentType == AttachmentType.urlPreview,
247-
);
248-
attachments = [...attachments]
249-
..remove(attachment)
250-
..insert(0, attachment);
251-
} else {
252-
attachments = [...attachments]
253-
..remove(attachment)
254-
..insert(0, attachment);
230+
attachments = attachments
231+
..removeWhere(
232+
(e) => e.type.toAttachmentType == AttachmentType.urlPreview,
233+
);
255234
}
235+
addAttachment(attachment);
256236
_ogAttachment = attachment;
257237
}
258238

lib/chats/chat/widgets/replied_message_bubble.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class RepliedMessageBubble extends StatelessWidget {
5656
children: [
5757
if (!repliedMessageSharedPostDeleted) ...[
5858
ImageAttachmentThumbnail(
59+
resizeHeight: 138,
5960
image: Attachment(imageUrl: replyMessageAttachmentUrl),
6061
fit: BoxFit.cover,
6162
borderRadius: 4,

lib/chats/widgets/chat_inbox_tile.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class ChatInboxTile extends StatelessWidget {
3737
.add(ChatsDeleteChatRequested(chatId: chat.id, userId: user.id)),
3838
),
3939
leading: UserStoriesAvatar(
40+
resizeHeight: 156,
4041
author: participant,
4142
enableInactiveBorder: false,
4243
withAdaptiveBorder: false,

lib/comments/comment/view/comment_view.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class CommentGroup extends StatelessWidget {
7777
),
7878
avatarBuilder: (context, author, onAvatarTap, radius) =>
7979
UserStoriesAvatar(
80+
resizeHeight: 108,
8081
author: author,
8182
onAvatarTap: onAvatarTap,
8283
radius: radius,

lib/feed/post/view/post_view.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class PostLargeView extends StatelessWidget {
135135
likersInFollowings: likersInFollowings,
136136
postAuthorAvatarBuilder: (context, author, onAvatarTap) {
137137
return UserStoriesAvatar(
138+
resizeHeight: 108,
138139
author: author.toUser,
139140
onAvatarTap: onAvatarTap,
140141
enableInactiveBorder: false,

lib/feed/post/widgets/post_popup_dialog.dart

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class PopupDialogHeader extends StatelessWidget {
100100
),
101101
horizontalTitleGap: AppSpacing.sm,
102102
leading: UserProfileAvatar(
103+
resizeHeight: 108,
103104
avatarUrl: block.author.avatarUrl,
104105
isLarge: false,
105106
enableBorder: false,
@@ -134,13 +135,7 @@ class PopupDialogBody extends StatelessWidget {
134135
alignment: Alignment.center,
135136
children: [
136137
if (block.firstMedia is ImageMedia)
137-
AspectRatio(
138-
aspectRatio: 1,
139-
child: ImageAttachmentThumbnail(
140-
image: Attachment(imageUrl: block.firstMediaUrl),
141-
fit: BoxFit.cover,
142-
),
143-
)
138+
PostPopupImage(block: block)
144139
else
145140
InlineVideo(
146141
videoSettings: VideoSettings.build(
@@ -172,6 +167,32 @@ class PopupDialogBody extends StatelessWidget {
172167
}
173168
}
174169

170+
class PostPopupImage extends StatelessWidget {
171+
const PostPopupImage({
172+
required this.block,
173+
super.key,
174+
});
175+
176+
final PostBlock block;
177+
178+
@override
179+
Widget build(BuildContext context) {
180+
final screenWidth = (context.screenWidth) - AppSpacing.md * 2;
181+
final pixelRatio = context.devicePixelRatio;
182+
183+
final thumbnailWidth = (screenWidth * pixelRatio) ~/ 1;
184+
185+
return AspectRatio(
186+
aspectRatio: 1,
187+
child: ImageAttachmentThumbnail(
188+
resizeWidth: thumbnailWidth,
189+
image: Attachment(imageUrl: block.firstMediaUrl),
190+
fit: BoxFit.cover,
191+
),
192+
);
193+
}
194+
}
195+
175196
class PopupDialogFooter extends StatelessWidget {
176197
const PopupDialogFooter({
177198
required this.likeButtonKey,

lib/feed/post/widgets/share_post.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ class UsersListView extends StatelessWidget {
526526
Stack(
527527
children: [
528528
UserProfileAvatar(
529+
resizeHeight: 252,
529530
avatarUrl: user.avatarUrl,
530531
enableBorder: false,
531532
),

0 commit comments

Comments
 (0)