Skip to content
This repository has been archived by the owner on Jun 13, 2024. It is now read-only.

Commit

Permalink
Shrink image sizes of attachments in Reply app. (#996)
Browse files Browse the repository at this point in the history
During the investigation of
flutter/flutter#132690 , we discovered that
the Reply image previews are the fully size 2000x2000 images. The
decoding of these images is putting the device under heavy strain which
is making it hard to diagnose other performance issues.
  • Loading branch information
jonahwilliams authored Aug 22, 2023
1 parent 8f5d333 commit ecfb9e5
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/studies/reply/mail_card_preview.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:animations/animations.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:gallery/layout/adaptive.dart';
import 'package:gallery/studies/reply/colors.dart';
Expand Down Expand Up @@ -255,6 +256,16 @@ class _MailPreview extends StatelessWidget {
class _PicturePreview extends StatelessWidget {
const _PicturePreview();

bool _shouldShrinkImage() {
switch (defaultTargetPlatform) {
case TargetPlatform.iOS:
case TargetPlatform.android:
return true;
default:
return false;
}
}

@override
Widget build(BuildContext context) {
return SizedBox(
Expand All @@ -269,6 +280,7 @@ class _PicturePreview extends StatelessWidget {
'reply/attachments/paris_${index + 1}.jpg',
gaplessPlayback: true,
package: 'flutter_gallery_assets',
cacheWidth: _shouldShrinkImage() ? 200 : null,
),
);
},
Expand Down
12 changes: 12 additions & 0 deletions lib/studies/reply/mail_view_page.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:gallery/studies/reply/model/email_model.dart';
import 'package:gallery/studies/reply/model/email_store.dart';
Expand Down Expand Up @@ -134,6 +135,16 @@ class _MailViewBody extends StatelessWidget {
class _PictureGrid extends StatelessWidget {
const _PictureGrid();

bool _shouldShrinkImage() {
switch (defaultTargetPlatform) {
case TargetPlatform.iOS:
case TargetPlatform.android:
return true;
default:
return false;
}
}

@override
Widget build(BuildContext context) {
return GridView.builder(
Expand All @@ -151,6 +162,7 @@ class _PictureGrid extends StatelessWidget {
gaplessPlayback: true,
package: 'flutter_gallery_assets',
fit: BoxFit.fill,
cacheWidth: _shouldShrinkImage() ? 500 : null,
);
},
);
Expand Down
1 change: 1 addition & 0 deletions lib/studies/shrine/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class _ShrineAppState extends State<ShrineApp>

return ScopedModel<AppStateModel>(
model: _model.value,
// ignore: deprecated_member_use
child: WillPopScope(
onWillPop: _onWillPop,
child: MaterialApp(
Expand Down
Binary file modified test_goldens/goldens/demo_desktop_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_goldens/goldens/demo_desktop_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_goldens/goldens/demo_mobile_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_goldens/goldens/demo_mobile_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_goldens/goldens/shrine_desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified test_goldens/goldens/shrine_mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ecfb9e5

Please sign in to comment.