분류, 패키지 및 저장소 검색

easy_image_viewer 표지
패키지 상세v1.5.1

easy_image_viewer

핀치 앤 줌, 다중 이미지 및 내장된 전체 화면 대화 상자 지원이 있는 간단한 이미지 뷰어입니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
3.6만
좋아요
347
Pub 점수
150

패키지 설치

flutter pub add easy_image_viewer

패키지 개요

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

Easy Image Viewer는 핀치 줌, 다중 이미지 탐색 및 전체 화면 모달 대화 상자와 같은 내장된 기능을 지원하는 Flutter 패키지입니다. 갤러리 형식으로 이미지를 보는 데 직관적인 인터페이스를 제공하여 부드러운 제스처로 이미지를 탐색해야 하는 앱에 적합합니다. Android, iOS, Web, macOS, Windows, Linux 등 모든 주요 플랫폼에서 작동하며 일관된 동작을 보장합니다. 최소한의 설정으로 개발자는 애플리케이션에 반응형 이미지 보기 기능을 신속하게 통합할 수 있습니다.

사용 사례

  • 이미지 갤러리 보기
  • 전체 화면 이미지 미리보기
  • 핀치 줌 이미지 브라우징
  • 다중 이미지 스와이프 탐색
  • 이미지 중심 앱 인터페이스
  • 간단한 이미지 뷰어 통합

주요 기능

  • 핀치 및 줌 제스처
  • 다중 이미지 지원
  • 내장형 전체 화면 대화 상자
  • 크로스 플랫폼 호환성
  • 최소 구성
  • 부드러운 애니메이션

적합한 대상

  • 이미지 콘텐츠를 갖춘 모바일 및 웹 앱
  • 사진 갤러리 기능
  • 전자상거래 제품 이미지 뷰어
  • 사용자 프로필 이미지 표시
  • 간단하면서도 효과적인 이미지 보기 필요 앱

고려 사항

  • 제한된 사용자 정의 옵션
  • 내장된 이미지 캐싱 없음
  • 기본 이미지 보기 요구 사항에 가장 적합
  • 복잡한 UI를 위해 추가적인 스타일링이 필요할 수 있습니다
  • 매우 큰 이미지 컬렉션에 최적화되지 않음

원본 README

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

EasyImageViewer

An easy way to display images in a full-screen dialog, including pinch & zoom.

Pub Tests

Easy Image Viewer Demo

Features

  • Show a single image or a swipeable list of images
  • Use pinch & zoom to zoom in and out of images
  • Optionally allow "double tap to zoom" by passing in doubleTapZoomable: true
  • Optionally allow "swipe down to dismiss" by passing in swipeDismissible: true
  • No dependencies besides Flutter
  • Callbacks for onPageChanged and onViewerDismissed
  • Fully customizable loading/progress indicator

Requirements

EasyImageViewer requires Flutter 3.7.0 and Dart 2.19.0 or higher.

Usage

Show a single image:

final imageProvider = Image.network("https://picsum.photos/id/1001/5616/3744").image;
showImageViewer(context, imageProvider, onViewerDismissed: () {
  print("dismissed");
});

Show a bunch of images:

MultiImageProvider multiImageProvider = MultiImageProvider([
  const NetworkImage("https://picsum.photos/id/1001/4912/3264"),
  const NetworkImage("https://picsum.photos/id/1003/1181/1772"),
  const NetworkImage("https://picsum.photos/id/1004/4912/3264"),
  const NetworkImage("https://picsum.photos/id/1005/4912/3264")
]);

showImageViewerPager(context, multiImageProvider, onPageChanged: (page) {
  print("page changed to $page");
}, onViewerDismissed: (page) {
  print("dismissed while on page $page");
});

Usually you'll want to implement your own EasyImageProvider. Suppose you have a list of Products, each of which has an imagePath property with the path to a local image file. You could create an EasyImageProvider that takes a list of Products like this:

class ProductsImageProvider extends EasyImageProvider {

  final List<Product> products;
  final int initialIndex;

  ProductsImageProvider({ required this.products, this.initialIndex = 0 });

  @override
  ImageProvider<Object> imageBuilder(BuildContext context, int index) {
    String? localImagePath = products[index].imagePath;
    File? imageFile;

    if (localImagePath != null) {
      imageFile = File(localImagePath);
    }

    ImageProvider imageProvider = imageFile != null ? FileImage(imageFile) : AssetImage("assets/images/product_placeholder.jpg") as ImageProvider;

    return imageProvider;
  }

  @override
  int get imageCount => products.length;  
}

You could then use it like this:

ProductsImageProvider productsImageProvider = ProductsImageProvider(products: products);

showImageViewerPager(context, productsImageProvider, onPageChanged: (page) {
  print("page changed to $page");
}, onViewerDismissed: (page) {
  print("dismissed while on page $page");
});

Customizing Progress Indicator and Image Widget

You can subclass EasyImageProvider and override progressIndicatorWidgetBuilder. That way you can provide your own progress indicator when an image is loading. Here's an example for using a linear progress indicator with a label:

class CustomImageWidgetProvider extends EasyImageProvider {
  @override
  final int initialIndex;
  final List<String> imageUrls;

  CustomImageWidgetProvider({required this.imageUrls, this.initialIndex = 0})
      : super();

  @override
  ImageProvider<Object> imageBuilder(BuildContext context, int index) {
    return NetworkImage(imageUrls[index]);
  }

  @override
  Widget progressIndicatorWidgetBuilder(BuildContext context, int index, {double? value}) {
    // Create a custom linear progress indicator
    // with a label showing the progress value
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        LinearProgressIndicator(
          value: value,
        ),
        Text(
          "${(value ?? 0) * 100}%",
          style: const TextStyle(
            color: Colors.white,
            fontWeight: FontWeight.bold,
            fontSize: 20,
          ),
        )
      ],
    );
  }

  @override
  int get imageCount => imageUrls.length;
}

You can also adjust animationDuration and animationCurve for the transition that is used to fade in the loaded image.

Finally, you can even override the imageWidgetBuilder method and completely customize the appearance of each individual image. Keep in mind that it should be an "image-like" widget since it will be treated as such: the user can pinch&zoom the returned widget etc.

Customizing Error Widget

You can subclass EasyImageProvider and override errorWidgetBuilder. That way you can provide your own error widget when an image fails to load. Here's an example that simply displays a centered red error message:

class CustomImageProvider extends EasyImageProvider {
  @override
  final int initialIndex;
  final List<String> imageUrls;

  CustomImageProvider({required this.imageUrls, this.initialIndex = 0})
      : super();

  @override
  ImageProvider<Object> imageBuilder(BuildContext context, int index) {
    return NetworkImage(imageUrls[index]);
  }

  @override
  Widget errorWidgetBuilder(BuildContext context, int index, Object error, StackTrace? stackTrace) {
    return const Center(
      child: Text(
        "Error loading image",
        style: TextStyle(fontSize: 50, color: Colors.red),
      ),
    );
  }

  @override
  int get imageCount => imageUrls.length;
}

The default error widget shows a red Icons.broken_image and '🖼️💥🚫' (image, boom, no entry) as a message underneath.

Default Error Widget

Using Infinite Scroll for Multiple Images

You can use infinitelyScrollable: true to create a "looping" effect with the images. This means that when you reach the end of the image list, you will be taken back to the beginning. This can be useful if you have a small number of images and want to allow the user to scroll through them continuously.

MultiImageProvider multiImageProvider = MultiImageProvider([
  const NetworkImage("https://picsum.photos/id/1001/4912/3264"),
  const NetworkImage("https://picsum.photos/id/1003/1181/1772"),
  const NetworkImage("https://picsum.photos/id/1004/4912/3264"),
  const NetworkImage("https://picsum.photos/id/1005/4912/3264")
]);

showImageViewerPager(context, multiImageProvider, onPageChanged: (page) {
  print("page changed to $page");
}, onViewerDismissed: (page) {
  print("dismissed while on page $page");
}, infinitelyScrollable: true);

How to release a new version on pub.dev

  1. Update the version number in pubspec.yaml.
  2. Add an entry for the new version in CHANGELOG.md.
  3. Make sure flutter test and flutter analyze pass without any issues.
  4. Run dart pub publish --dry-run to ensure all publishing checks pass.
  5. If you haven't installed the pana package analysis tool yet, install it with dart pub global activate pana.
  6. Make sure all changes are committed and run pana . inside the project directory. We are aiming for the highest score.
  7. Address any issues reported by pana.
  8. Create a new branch for your changes, for example by running git checkout -b release-1.1.0.
  9. Commit your changes (formatting changes separately from other changes).
  10. Open a PR with your changes.
  11. Once approved, merge the PR.
  12. Run dart pub publish to publish the new version.
  13. On GitHub, create a new release by visiting Releases. The tag should have the format of v plus the version number, for example v1.1.0. The title of the release should be the version number without a v. Add what you've added to the changelog as the release's description.
  14. That's it.

Credits

EasyImageViewer is a project by TSG, a full-service digital agency taking software from concept to launch. Our powerhouse team of designers and engineers build iOS, Android, and web apps across many industries.

카테고리

소스 저장소

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