패키지, 저장소 및 앱 카테고리 검색

패키지 상세v1.2.1

disposable_cached_images

메모리에서 이미지를 표시하고 해제하기 위한 플러터 패키지입니다.

30일 다운로드
155
좋아요
36
Pub 점수
60

패키지 설치

flutter pub add disposable_cached_images

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

이미지를 효율적으로 표시하도록 설계된 플러터 패키지로, 더 이상 필요하지 않을 때 자동으로 메모리를 관리하여 이미지를 해제합니다. 임시로 이미지를 캐싱하고 사용 후 즉시 제거함으로써 성능을 최적화하고, 이미지가 많은 애플리케이션에서 메모리 오버헤드를 줄입니다. 갤러리나 소셜 미디어 피드처럼 동적으로 수많은 이미지를 로드하는 앱에 적합합니다. 이 패키지는 플러터의 이미지 로딩 파이프라인과 원활하게 통합되며, 로컬 및 네트워크 이미지를 모두 지원합니다. 메모리 누수를 방지하고 앱의 반응성을 향상시킵니다.

사용 사례

  • 이미지 갤러리
  • 소셜 미디어 피드
  • 동적 이미지 표시
  • 메모리 효율적인 이미지 로딩
  • 실시간 사진 미리보기

주요 기능

  • 자동 메모리 해제
  • 임시 이미지 캐싱
  • 네트워크 및 로컬 이미지 지원
  • 메모리 누수를 방지합니다
  • Flutter와의 원활한 통합

적합한 대상

  • 고 이미지 밀도 앱
  • 성능 중심의 UI
  • 메모리 제약 환경
  • 자원 관리를 우선시하는 개발자
  • 빠른 이미지 폐기 필요 앱

고려 사항

  • 기본 캐싱 요구 사항에 제한됨
  • 고급 캐시 제거 전략 없음
  • 지속적인 이미지 저장에 적합하지 않습니다
  • 복잡한 시나리오에서는 수동 폐기 필요
  • 내장된 이미지 압축 없음

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

A flutter package for downloading, caching, displaying and releasing images from memory.

Features

Display images from the Internet and/or local files (assets and device storage).

Caching images in the cache directory.

Cancel the download if the image widget has been disposed to reduce bandwidth usage.

Remove the image from memory if the image widget has been disposed to reduce device memory usage.

High performance due to the use of dart:isolate

Usage

Setting up

All you have to do is Initializing the cache and wrap the root widget with DisposableImages.

void main() {
  await DisposableImages.init();

  runApp(const DisposableImages(MyApp()));
}

Now your app is ready to use the package.

initialization options
maximumDecodedImagesCount

The maximum number of decoded images that should be kept in memory when using DisposableImages.decodedImages

maximumDecode

The maximum number of images to be decoded simultaneously

maximumDownload

The maximum number of images to be downloaded simultaneously

Displaying images

Use DisposableCachedImage named constructors to display images.

Obtaining an image from a URL
DisposableCachedImage.network(imageUrl: 'https://picsum.photos/id/23/200/300');
Obtaining a local image from assets using path
DisposableCachedImage.asset(imagePath: 'assets/images/a_dot_burr.jpeg');
Obtaining a local image from device storage using path
DisposableCachedImage.local(imagePath: 'assets/images/a_dot_burr.jpeg');
Obtaining an image from Uint8List
DisposableCachedImage.bytes(bytes: bytes);
Display dynamic height images

If you are using dynamic height images, you should declare this as shown below to avoid UI jumping

DisposableCachedImage.network(
  imageUrl: imageUrl,
  isDynamicHeight: true,
  width: MediaQuery.of(context).size.width * 0.3,
),

width required when displaying dynamic height images


You can display your custom widgets while the image is loading, downloading, has an error and when it is ready as shown below

DisposableCachedImage.network(
  imageUrl: 'https://picsum.photos/id/23/200/300',
  onLoading: (context) => const Center(
    child: Icon(Icons.downloading),
  ),
  progressBuilder: (context, progress) => Center(
    child: LinearProgressIndicator(value: progress),
  ),
  onError: (context, error, stackTrace, retryCall) => Center(
    child: IconButton(
      onPressed: retryCall,
      icon: const Icon(Icons.download),
    ),
  ),
  onImage: (context, imageWidget, height, width) => Stack(
    children: [
      imageWidget,
      MyWidget(),
    ],
  ),
);
Resize images

You can change the image size to the provided width and \ or height by enabling resizeImage (disabled by default) to reduce raster thread usage when using high resolution images, if this option is enabled the same provider instance would be used for the number of images that share the same url \ path with a different image size for each widget to have a gallery like experience.

To change the size of the images in bytes before they are saved to the storage, provide maxCacheWidth and \ or maxCacheHeight.

DisposableCachedImage.network(
 imageUrl: imageUrl,
 maxCacheWidth: 300,
 width: 200,
 resizeImage: true,
),
Clipping

You can clip the image either with rounded corners by providing BorderRadius

DisposableCachedImage.network(
  imageUrl: imageUrl,
  borderRadius: const BorderRadius.all(Radius.circular(20)),
),

Or by setting BoxShape to get oval image

DisposableCachedImage.network(
  imageUrl: imageUrl,
  shape: BoxShape.circle,
),
Keeping images alive

By default each image is removed from memory when it is not being used by any widget, however you can keep some images in memory for the entire application lifecycle as shown below

DisposableCachedImage.network(
  imageUrl: imageUrl,
  keepAlive: true,
),

The other arguments are similar if not quite the same as Image Widget


Decode images before displaying

You can use DisposableImages.decodedImages to decode images before displaying them in case you need to show images immediately without loading

  // decode network images
  DisposableImages.decodedImages.addNetwork(url);

  // decode loacl images
  DisposableImages.decodedImages.addLocal(path);

  // decode assets images
  DisposableImages.decodedImages.addAssets(path);

If you decode the images in this way, you will have to dispose the images manually or set the maximum number of decoded images

// set the maximum number of decoded images, old images will be removed if this number is exeeded
// this is optional and can be null
DisposableImages.init(maximumDecodedImagesCount: 100);


// dispose an image by key
// the key is path if the image is local or assets, if it's a network image the key is the url
DisposableImages.decodedImages.dispose(key);

// dispose all images
DisposableImages.decodedImages.disposeAll();
Remove all cached images from the device storage
DisposableCachedImage.clearCache();

How it works

The package uses RawImage with dart-ui-Image directly without the need for ImageProvider

Stores and retrieves files using dart:io.

Disposing and changing image state using flutter_riverpod with state_notifier.

Downloading images with dart:_http on other platforms.

Example app

The example directory has a sample application that uses this plugin.

Roadmap

Improve package documentation

Further improvements

카테고리

의존성

의존성 목록 4 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.