搜尋套件、儲存庫與 APP 分類

pinch_zoom_release_unzoom 封面
套件詳情v2.0.0

pinch_zoom_release_unzoom

一個讓您能使用雙指縮放的 Widget,縮放結束後會回復到原來的大小。與在 Instagram 上縮放圖片的方式非常類似。

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
4150
喜歡數
65
Pub 分數
160

安裝套件

flutter pub add pinch_zoom_release_unzoom

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個 Flutter 小部件,可實現捏合縮放功能,在手勢結束後自動恢復到原始大小,模擬 Instagram 的圖片縮放行為。它提供平滑的暫時縮放效果,非常適合不需要保持放大狀態的圖片或內容。該小部件支援所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux,適用於跨平台應用。它輕量且易於整合,設定簡單。

適用情境

  • 臨時縮放的圖像查看
  • 具有動態縮放的互動式 UI 元素
  • 跨平台基於手勢的內容探索
  • 增強照片畫廊的使用者體驗
  • 簡單的縮放效果,無持續縮放

主要特色

  • 捏合後自動回復原始大小
  • 縮放與反縮放過程中的平滑動畫
  • 支援所有主要的Flutter平台
  • 所需的設定最少
  • 直觀的手勢識別

適合對象

  • 開發圖像密集型應用的開發者
  • 需要臨時縮放互動的應用
  • 致力於實現類似 Instagram 操作手勢的專案
  • 尋求直覺式觸控回饋的UI設計師
  • 具有手勢需求的跨平台應用

使用建議

  • 不適用於持續縮放狀態
  • 縮放行為的自訂選項有限
  • 可能需要額外處理複雜版面
  • 最佳搭配靜態或非捲動內容使用
  • 性能可能因大尺寸或高解析度影像而有所不同

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

pub package popularity likes pub points

This package helps to create an instagram like zoom picture. With pinch to zoom and release to unzoom

In this video I explained how to use pinch to zoom, in a flutter project

https://youtu.be/V2DglEpynF8

Zoom_demo

Features

Let's your app show zoomable images in an user friendly way.

It's a container of an uncliped interactive viewer that let's the user zoom the image occupying the entire screen. Once you release the screen and stop the pinch interaction the image/widget will come back to it's original size in an smooth animation.

Getting started

Add the dependency to your pubspec.yaml:

pinch_zoom_release_unzoom: ^1.0.1

Usage


PinchZoomReleaseUnzoomWidget(
  child: Image.network(
    'https://storage.googleapis.com/cms-storage-bucket/70760bf1e88b184bb1bc.png'
  ),
)

Additional information

This package also support some extra params that may be useful depending on what are you trying to achieve

PinchZoomReleaseUnzoomWidget(
    child: Image.network('https://storage.googleapis.com/cms-storage-bucket/70760bf1e88b184bb1bc.png'),
    minScale: 0.8,
    maxScale: 4,
    resetDuration: const Duration(milliseconds: 200),
    boundaryMargin: const EdgeInsets.only(bottom: 0),
    clipBehavior: Clip.none,
    useOverlay: true,
    maxOverlayOpacity: 0.5,
    overlayColor: Colors.black,
    fingersRequiredToPinch: 2
)

Making it work well inside a scroll

I made a video explaining how to solve the pinch to zoom inside a scroll:

https://youtu.be/FUuCOdQerpw

The problem with making a pinch working inside a scroll is that the drag of a screen, as a simple gesture that can be done with just one finger, tends to override the more complex scale gesture that needs two fingers to work well, the best way I found to overcome that challenge is to change the physics of the scroll to NeverScrollableScrollPhysics() when the second finger touch the screen, that way the scroll stops to override the scale gesture and it's easy to interact with the interactive viewer.

Another consideration that you will need to have is that to avoid losing frames of the reset animation, you need to delay the setState that will bring the scroll back to the parent widget

So the scroll build will look like this:

  bool blockScroll = false;
ScrollController controller = ScrollController();

@override
Widget build(BuildContext context) {
  return SingleChildScrollView(
      controller: controller,
      physics: blockScroll ? NeverScrollableScrollPhysics() : ScrollPhysics(),

And the PinchWidget will have this two extra parameters:

twoFingersOn: () => setState(() => blockScroll = true),
twoFingersOff: () => Future.delayed(
PinchZoomReleaseUnzoomWidget.defaultResetDuration,
() => setState(() => blockScroll = false),

For a complete widget example check this one:

class TestSimpleScroll extends StatefulWidget {
  const TestSimpleScroll({super.key});

  @override
  State<TestSimpleScroll> createState() => _TestSimpleScrollState();
}

class _TestSimpleScrollState extends State<TestSimpleScroll> {
  bool blockScroll = false;
  ScrollController controller = ScrollController();

  @override
  Widget build(BuildContext context) {
    return SingleChildScrollView(
      controller: controller,
      physics: blockScroll ? NeverScrollableScrollPhysics() : ScrollPhysics(),
      child: SizedBox(
        width: MediaQuery.of(context).size.width,
        child: Container(
          padding: const EdgeInsets.all(20),
          child: Column(
            children: [
              SizedBox(
                width: 300,
                height: 250,
                child: PinchZoomReleaseUnzoomWidget(
                  child: Image.network(
                    'https://www.animalfriends.co.uk/siteassets/media/images/article-images/cat-articles/38_afi_article1_caring-for-a-kitten-tips-for-the-first-month.png',
                  ),
                  twoFingersOn: () => setState(() => blockScroll = true),
                  twoFingersOff: () => Future.delayed(
                    PinchZoomReleaseUnzoomWidget.defaultResetDuration,
                        () => setState(() => blockScroll = false),
                  ),
                ),
              ),
              const SizedBox(
                height: 5000,
              )
            ],
          ),
        ),
      ),
    );
  }
}

Simulator test

To test in a simulator add a fingersRequiredToPinch to pinch with a -1 to disable the requirement of two fingers to start an interaction

PinchZoomReleaseUnzoomWidget(
    child: Image.network('https://storage.googleapis.com/cms-storage-bucket/70760bf1e88b184bb1bc.png'),
    fingersRequiredToPinch: -1
)

Like us on pub.dev

Package url: https://pub.dev/packages/pinch_zoom_release_unzoom

所屬分類

原始碼儲存庫

使用此套件的專案

暫無相關資料。