-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix(mobile): pause image loading on inactive state #21543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| void _cancelImageStream() { | ||
| final imageProvider = widget.imageProvider; | ||
| if (imageProvider is CancellableImageProvider) { | ||
| imageProvider.cancel(); | ||
| } | ||
| _stopListeningToImageStream(); | ||
| } | ||
|
|
||
| void _cancelThumbhashStream() { | ||
| final thumbhashProvider = widget.thumbhashProvider; | ||
| if (thumbhashProvider is CancellableImageProvider) { | ||
| thumbhashProvider.cancel(); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do wonder if we need separate methods for the two providers like this? Both can be upcasted to ImageProvider, then dowcast them back to CancellableImageProvider and cancel it
|
|
||
| @override | ||
| void didChangeAppLifecycleState(AppLifecycleState state) { | ||
| if (!mounted) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if (!mounted) return; | |
| if (!mounted) { | |
| return; | |
| } |
eb70a45 to
fda8058
Compare
Description
The app continues to load images when it's inactive but not yet paused. This can lead to errors and makes it a more likely candidate to be harvested by the OS due to higher memory usage. This PR handles this by pausing image requests and resuming them when the app is active again.