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

패키지 상세v0.0.13

image_loader_flutter

이 패키지는 이미지 캐싱을 통해 성능을 향상시켜 Flutter 앱에서 이미지를 부드럽고 효율적으로 렌더링할 수 있도록 합니다.

AndroidiOSmacOSWindowsLinux
30일 다운로드
62
좋아요
3
Pub 점수
115

패키지 설치

flutter pub add image_loader_flutter

패키지 개요

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

ImageLoaderFlutter는 효율적인 캐시 메커니즘을 통해 이미지 렌더링을 최적화한 성능 중심의 패키지입니다. 다양한 플랫폼에서 원활하고 빠른 이미지 로딩을 보장하며, 중복된 네트워크 요청을 줄이고 앱의 반응성을 향상시킵니다. 대량의 이미지 콘텐츠를 포함한 앱에 이상적이며, 최소한의 구성으로 기존 프로젝트에 쉽게 통합할 수 있습니다. Android, iOS, macOS, Windows, Linux 등 여러 플랫폼을 지원하여 크로스플랫폼 개발에 유용합니다. 가볍고 신뢰성 있는 설계로 속도에 중점을 두어 이미지 표시 시 사용자 경험을 향상시킵니다.

사용 사례

  • 갤러리에서 고용량 이미지 표시
  • 소셜 미디어 앱에서 원격 이미지 로드하기
  • 전자상거래 제품 목록의 성능 향상
  • 대역폭 사용량을 줄이기 위해 이미지 캐싱
  • 이미지가 많은 인터페이스에서 UI 반응성 향상

주요 기능

  • 내장 이미지 캐싱
  • 크로스 플랫폼 지원
  • 최소한의 설정 필요
  • 성능 최적화
  • 원격 및 로컬 이미지 소스를 지원합니다

적합한 대상

  • 이미지가 풍부한 애플리케이션을 개발하는 개발자
  • 앱 성능을 우선시하는 팀
  • 오프라인 이미지 접근이 필요한 프로젝트
  • 다수의 운영 체제를 대상으로 하는 앱
  • 모바일 및 데스크톱 플러터 애플리케이션

고려 사항

  • 원격 이미지를 위해 인터넷 연결이 필요합니다
  • 대규모 데이터 세트에 대해 캐시 관리는 수동 처리가 필요할 수 있습니다
  • 고급 캐싱 전략을 위한 제한된 사용자 정의 옵션
  • 최적화되지 않은 매우 큰 이미지 파일에는 적합하지 않습니다
  • 초기 로드를 위한 안정적인 네트워크 조건에 의존

원본 README

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

ImageLoaderFlutterWidgets

A versatile Flutter widget for loading and displaying images from various sources (network, assets, or local files) with extensive customization options. It supports circular or rectangular shapes, borders, box shadows, hero animations, and tap-to-view full-screen functionality. The widget leverages the cached_network_image package for efficient network image loading and provides fallback mechanisms for error handling.

Features

Image Source Support
  • Network images: Load images from URLs.
  • Asset images: Load images from the app's asset bundle.
  • Local file images: Load images from the device’s file system.
Customization
  • Circular or rectangular image shapes.
  • Configurable border (color, width, enable/disable).
  • Box shadow effects for elevation.
  • Background color customization.
  • Padding and image alignment.
  • Customizable image fit and clipping behavior.
Interactivity
  • Tap-to-view full-screen image with navigation to a ViewImageScreen.
  • Hero animation support for smooth transitions.
Error Handling
  • Custom placeholder widget during loading.
  • Custom error widget for failed image loads.
Performance
  • Uses cached_network_image for efficient network image loading and caching.

Installation

To use ImageLoaderFlutterWidgets, add the following dependency to your pubspec.yaml:

dependencies:
  image_loader_flutter: ^0.0.11

Run the following command to install the dependency:

flutter pub get

Ensure that the ViewImageScreen widget (used for full-screen image viewing) is implemented in your project or included as part of the package. You may also need to handle file permissions for local images (e.g., using path_provider or similar packages).

Usage

Import the widget into your Dart file:

import 'package:image_loader_flutter_widgets/image_loader_flutter_widgets.dart';

Use the ImageLoaderFlutterWidgets widget in your Flutter app with the desired configuration:

ImageLoaderFlutterWidgets(
  image: 'https://example.com/sample.jpg',
  circle: true,
  radius: 50.0,
  onTap: true,
  enableHero: true,
  placeHolderWidget: const Icon(Icons.image),
  padding: 4.0,
  bgColor: Colors.white,
  height: 100.0,
  width: 100.0,
  fit: BoxFit.cover,
  borderColor: Colors.blue,
  enableBorder: true,
  borderWidth: 2.0,
  boxShadow: [
    BoxShadow(
      color: Colors.black26,
      blurRadius: 4.0,
      offset: Offset(2, 2),
    ),
  ],
  imageAlignment: Alignment.center,
  clipBehavior: Clip.antiAlias,
)

Parameters

The ImageLoaderFlutterWidgets widget accepts the following parameters, each with a specific role in customizing the widget's appearance and behavior:

Parameter Type Description Default Value
image String? The path or URL of the image (network URL, asset path, or file path). null
circle bool Displays the image as a circle if true, or a rectangle if false. false
radius double? Border radius for rectangular images. Ignored if circle is true. null (0 if not specified)
onTap bool Enables tap-to-view full-screen image functionality. true
enableHero bool Enables hero animation for smooth transitions to full-screen view. false
placeHolderWidget Widget Widget displayed while the image is loading or if it fails to load. Icon(Icons.photo)
padding double Padding inside the container around the image. 0
bgColor Color? Background color of the container. Theme.of(context).cardColor
height double? Height of the image container. null (auto-sized)
width double? Width of the image container. null (auto-sized)
fit BoxFit How the image should fit within the container. BoxFit.fill
borderColor Color? Color of the border. Applied only if enableBorder is true. Colors.grey[300]
enableBorder bool Enables or disables the border around the image. true
borderWidth double Width of the border. Applied only if enableBorder is true. 1.0
boxShadow List<BoxShadow>? List of box shadows to apply to the container for elevation effects. null (no shadow)
imageAlignment Alignment Alignment of the image within the container. Alignment.center
backgroundImage DecorationImage? Optional background image for the container (not typically used). null
clipBehavior Clip Clipping behavior for the image (e.g., anti-aliasing for smooth edges). Clip.antiAlias
shapeDecoration BoxShape? Shape of the container. Overrides circle if provided. null
Parameter Details
  • image: Specifies the source of the image. Supports:
    • Network URLs (e.g., https://example.com/image.jpg)
    • Asset paths (e.g., assets/image.png)
    • Local file paths (e.g., /path/to/image.jpg)
    • If null or empty, the placeHolderWidget is displayed.
  • circle: Clips the image into a circular shape if true. If false, uses a rectangle. Ignores radius when true.
  • radius: Sets the corner radius for rectangular images. Ignored if circle is true.
  • onTap: Enables/disables tap gesture to open the image in a full-screen view using ViewImageScreen.
  • enableHero: Wraps the image in a Hero widget for smooth transitions. Uses the image string as the hero tag.
  • placeHolderWidget: Fallback widget displayed during loading (for network images) or if the image fails to load.
  • padding: Adds padding inside the container, affecting space between the image and container edges.
  • bgColor: Sets the container’s background color. Defaults to the theme’s card color if not specified.
  • height and width: Define the container’s dimensions. If unset, the container auto-sizes based on the image.
  • fit: Controls how the image fits within the container (e.g., BoxFit.cover, BoxFit.cover, BoxFit.fill).
  • borderColor: Sets the border color. Applied only if enableBorder is true.
  • enableBorder: Toggles the border on/off. If false, borderColor and borderWidth are ignored.
  • borderWidth: Sets the border thickness when enableBorder is true.
  • boxShadow: Applies shadow effects for a raised appearance.
  • imageAlignment: Aligns the image within the container (e.g., Alignment.topLeft, Alignment.center).
  • backgroundImage: Optional container background image. Rarely used due to potential conflicts with the primary image.
  • clipBehavior: Defines clipping behavior (e.g., Clip.antiAlias for smooth edges, Clip.hardEdge for sharper cuts).
  • shapeDecoration: Overrides the container shape (e.g., BoxShape.circle or BoxShape.rectangle). Takes precedence over circle.

Examples

Below are several examples demonstrating different configurations of the ImageLoaderFlutterWidgets widget.

Example 1: Circular Network Image with Border and Hero Animation

Displays a circular image from a network URL with a border and hero animation for full-screen transitions.

ImageLoaderFlutterWidgets(
  image: 'https://example.com/sample.jpg',
  circle: true,
  radius: 50.0,
  enableHero: true,
  borderColor: Colors.black,
  borderWidth: 2.0,
  fit: BoxFit.cover,
  height: 100.0,
  width: 100.0,
)
Example 2: Rectangular Asset Image with Shadow

Displays a rectangular image from the app’s assets with a shadow effect and no border.

ImageLoaderFlutterWidgets(
  image: 'assets/profile.png',
  circle: false,
  radius: 10.0,
  enableBorder: false,
  boxShadow: [
    BoxShadow(
      color: Colors.black26,
      blurRadius: 6.0,
      offset: Offset(0, 2),
    ),
  ],
  height: 150.0,
  width: 150.0,
  fit: BoxFit.cover,
)
Example 3: Local File Image with Custom Placeholder

Displays an image from the local file system with a custom placeholder widget and padding.

ImageLoaderFlutterWidgets(
  image: '/path/to/local/image.jpg',
  circle: false,
  radius: 8.0,
  placeHolderWidget: const Text('Loading...'),
  padding: 8.0,
  bgColor: Colors.grey[200],
  height: 120.0,
  width: 120.0,
  fit: BoxFit.contain,
)
Example 4: Disabled Tap and No Hero Animation

Displays a network image without tap-to-view functionality or hero animation.

ImageLoaderFlutterWidgets(
  image: 'https://example.com/photo.jpg',
  circle: true,
  onTap: false,
  enableHero: false,
  height: 80.0,
  width: 80.0,
  fit: BoxFit.fill,
)
Example 5: Custom Clipping and Alignment

Displays a network image with custom clipping behavior and top-left alignment.

ImageLoaderFlutterWidgets(
  image: 'https://example.com/image.jpg',
  circle: false,
  radius: 12.0,
  imageAlignment: Alignment.topLeft,
  clipBehavior: Clip.hardEdge,
  height: 200.0,
  width: 200.0,
  fit: BoxFit.cover,
)

Notes

  • Network Images: The cached_network_image package is used for efficient loading and caching of network images. Ensure the dependency is added to your project.
  • Asset Images: Asset images must be declared in your pubspec.yaml under the assets section.
  • Local File Images: Ensure proper file access permissions are configured in your app (e.g., for Android, add storage permissions in AndroidManifest.xml).
  • ViewImageScreen: The full-screen image view functionality relies on a ViewImageScreen widget, which must be implemented separately or provided as part of your package. The widget expects an ImageProvider for rendering the image.
  • Hero Animations: The enableHero option uses the image string as the hero tag. Ensure each image has a unique image value to avoid hero animation conflicts.
  • Error Handling: If the image fails to load or is null, the placeHolderWidget is displayed. Customize this widget to match your app’s design.
  • Performance: The CachedNetworkImage widget caches network images to improve performance. Adjust cache settings in the cached_network_image package if needed.

Dependencies

  • cached_network_image: For loading and caching network images.
  • flutter: Core Flutter framework for widget rendering and theming.
  • dart:io: For handling local file images.

Limitations

  • The backgroundImage parameter is included but not typically used, as it may conflict with the primary image widget. Use with caution.
  • The shapeDecoration parameter overrides the circle parameter if provided, which may lead to unexpected behavior if both are set.
  • The ViewImageScreen widget is not included in the provided code and must be implemented separately.

License

This project is licensed under the MIT License.

카테고리

의존성

의존성 목록 2 개

소스 저장소

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

아직 데이터가 없습니다.