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

패키지 상세v3.0.1

optimized_cached_image

네트워크에서 이미지를 로드하고 컨테이너 크기에 따라 리사이징하며 메모리 사용을 고려한 캐싱을 지원하는 라이브러리입니다.

30일 다운로드
355
좋아요
114
Pub 점수
60

패키지 설치

flutter pub add optimized_cached_image

패키지 개요

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

OptimizedCachedImage는 네트워크 이미지를 효율적으로 로드하고 크기를 조정하며 캐시하는 데 중점을 두고 설계된 Flutter 패키지입니다. 메모리 사용량을 최소화합니다. 자동으로 컨테이너의 크기에 맞게 이미지 크기를 조정하여 불필요한 메모리 소비를 줄입니다. 캐싱 메커니즘과 리소스 처리 최적화를 통해 원활한 성능을 보장합니다. 자주 이미지를 로드하는 앱에 적합하며, 사용자 경험을 희생하지 않고 속도와 효율성 사이의 균형을 유지합니다.

사용 사례

  • URL에서 동적 이미지 로드
  • 컨테이너 차원에 맞게 이미지 크기 조정
  • 네트워크 요청을 줄이기 위해 이미지를 캐시합니다
  • 이미지가 많은 앱에서 메모리 사용량 줄이기
  • 효율적인 이미지 처리를 통한 앱 성능 향상

주요 기능

  • 자동 이미지 크기 조정
  • 메모리 효율적인 캐싱
  • 네트워크 이미지 로딩
  • 컨테이너 인식 스케일링
  • 낮은 메모리 오버헤드

적합한 대상

  • 높은 이미지 트래픽을 가진 앱
  • 성능 중심의 UI
  • 제한된 메모리가 있는 모바일 앱
  • 이미지 갤러리 및 피드
  • 전자상거래 또는 소셜 미디어 앱

고려 사항

  • 초기 로드를 위해 인터넷 연결이 필요합니다
  • 사용자 정의 캐시 정책을 위한 구성이 필요할 수 있습니다
  • 제한된 플랫폼 고유 최적화
  • 정적 로컬 이미지에 적합하지 않습니다
  • 외부 네트워크 신뢰성에 의존

원본 README

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

Optimized Cached Image

pub package

❌❌ Important Update ❌❌

This library is no longer being maintained. When I started this library, it was meant to add memory performant extensions which could not be directly added into the parent library. Since then a lot has changed, the parent library has incorporated similar changes, perhaps with the exception of a trivial LayoutBuilder that auto detects image sizes. I feel like this is a good time to deprecate this library in favour of the parent.

Description

A flutter library for loading images from network, resizing and caching them for memory sensitivity. This resizes and stores the images in cache based on parent container constraints and hence loads images of lower size into memory. This is heavily inspired by cached_network_image library.

This library exposes two classes for loading images

  • OptimizedCacheImage which is a 1:1 mapping of CachedNetworkImage.
  • OptimizedCacheImageProvider which is a mapping of CachedNetworkImageProvider.

How to use

The OptimizedCacheImage can be used directly or through the ImageProvider. Both the OptimizedCacheImage as OptimizedCacheImageProvider have minimal support for web. It currently doesn't include caching.

With a placeholder:

OptimizedCacheImage(
        imageUrl: "http://via.placeholder.com/350x150",
        placeholder: (context, url) => CircularProgressIndicator(),
        errorWidget: (context, url, error) => Icon(Icons.error),
     ),

Or with a progress indicator:

OptimizedCacheImage(
       imageUrl: "http://via.placeholder.com/350x150",
       progressIndicatorBuilder: (context, url, downloadProgress) =>
               CircularProgressIndicator(value: downloadProgress.progress),
       errorWidget: (context, url, error) => Icon(Icons.error),
    ),
Image(image: OptimizedCacheImageProvider(url))

When you want to have both the placeholder functionality and want to get the imageprovider to use in another widget you can provide an imageBuilder:

OptimizedCacheImage(
  imageUrl: "http://via.placeholder.com/200x150",
  imageBuilder: (context, imageProvider) => Container(
    decoration: BoxDecoration(
      image: DecorationImage(
          image: imageProvider,
          fit: BoxFit.cover,
          colorFilter:
              ColorFilter.mode(Colors.red, BlendMode.colorBurn)),
    ),
  ),
  placeholder: (context, url) => CircularProgressIndicator(),
  errorWidget: (context, url, error) => Icon(Icons.error),
),

Handling Gifs

OCI uses Flutter Image Compress as the compression library, while being memory efficient this library doesn't provide out of box support for gifs, however it does allow compressing to webp. Hence all gifs are compressed to webp format beginning 2.0.2-alpha.

How it works

The optimized cached network images stores and retrieves files using the flutter_cache_manager.

FAQ

My app crashes when the image loading failed. (I know, this is not really a question.)

Does it really crash though? The debugger might pause, as the Dart VM doesn't recognize it as a caught exception; the console might print errors; even your crash reporting tool might report it (I know, that really sucks). However, does it really crash? Probably everything is just running fine. If you really get an app crashes you are fine to report an issue, but do that with a small example so we can reproduce that crash.

카테고리

의존성

의존성 목록 11 개

소스 저장소

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

아직 데이터가 없습니다.