瀏覽代碼

Fix OOMs that came along with loading image bytes directly

Vishnu Mohandas 5 年之前
父節點
當前提交
c400238ce0
共有 2 個文件被更改,包括 10 次插入10 次删除
  1. 4 4
      lib/core/cache/image_cache.dart
  2. 6 6
      lib/ui/zoomable_image.dart

+ 4 - 4
lib/core/cache/image_cache.dart

@@ -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);
   }
 }

+ 6 - 6
lib/ui/zoomable_image.dart

@@ -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(() {