Fix OOMs that came along with loading image bytes directly
This commit is contained in:
parent
57dd9d098b
commit
c400238ce0
2 changed files with 10 additions and 10 deletions
8
lib/core/cache/image_cache.dart
vendored
8
lib/core/cache/image_cache.dart
vendored
|
@ -1,16 +1,16 @@
|
|||
import 'dart:typed_data';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:photos/core/cache/lru_map.dart';
|
||||
import 'package:photos/models/photo.dart';
|
||||
|
||||
class ImageLruCache {
|
||||
static LRUMap<int, Uint8List> _map = LRUMap(500);
|
||||
static LRUMap<int, File> _map = LRUMap(500);
|
||||
|
||||
static Uint8List get(Photo photo) {
|
||||
static File get(Photo photo) {
|
||||
return _map.get(photo.generatedId);
|
||||
}
|
||||
|
||||
static void put(Photo photo, Uint8List imageData) {
|
||||
static void put(Photo photo, File imageData) {
|
||||
_map.put(photo.generatedId, imageData);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import 'dart:typed_data';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:photos/core/cache/image_cache.dart';
|
||||
import 'package:photos/core/cache/thumbnail_cache.dart';
|
||||
|
@ -72,11 +72,11 @@ class _ZoomableImageState extends State<ZoomableImage> {
|
|||
if (cachedImage != null) {
|
||||
_onFinalImageLoaded(cachedImage, context);
|
||||
} else {
|
||||
widget.photo.getBytes().then((bytes) {
|
||||
widget.photo.getAsset().file.then((file) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_onFinalImageLoaded(bytes, context);
|
||||
ImageLruCache.put(widget.photo, bytes);
|
||||
_onFinalImageLoaded(file, context);
|
||||
ImageLruCache.put(widget.photo, file);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -108,8 +108,8 @@ class _ZoomableImageState extends State<ZoomableImage> {
|
|||
_loadedLargeThumbnail = true;
|
||||
}
|
||||
|
||||
void _onFinalImageLoaded(Uint8List bytes, BuildContext context) {
|
||||
final imageProvider = Image.memory(bytes).image;
|
||||
void _onFinalImageLoaded(File file, BuildContext context) {
|
||||
final imageProvider = Image.file(file).image;
|
||||
precacheImage(imageProvider, context).then((value) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
|
|
Loading…
Add table
Reference in a new issue