Pinch-to-Zoom Images in Flutter with photo_view
photo_view 0.15.0 ships PhotoView, PhotoViewGallery, computed scales, hero tags and controllers — and knows when InteractiveViewer is enough.
Published on • November 5, 2026
AI Assistant

Every photo-heavy Flutter app eventually needs the same thing: an image the user can pinch, pan, double-tap, and inspect at full resolution. photo_view has been the standard answer for years, and the current release on pub.dev is photo_view 0.15.0, published on April 17, 2024 by the verified publisher blue-fire.xyz, supporting Android, iOS, Linux, macOS, web, and Windows with a single flutter dependency.
Adding the package and basic usage
Add it to your dependencies:
dependencies:
photo_view: ^0.15.0
Then wrap any ImageProvider — AssetImage, NetworkImage, FileImage — in a PhotoView:
import 'package:photo_view/photo_view.dart';
PhotoView(
imageProvider: const AssetImage('assets/large-image.jpg'),
loadingBuilder: (context, event) => Center(
child: CircularProgressIndicator(
value: event == null
? null
: event.cumulativeBytesLoaded / event.expectedTotalBytes,
),
),
backgroundDecoration: const BoxDecoration(color: Colors.black),
)
PhotoView.customChild exists for non-image content (SVG, text, containers), and PhotoView can even show PhotoView.customChild-style widgets with a childSize you provide.
Controlling min, max, and initial scale
The scale arguments accept either a plain double or a PhotoViewComputedScale constant multiplied by a factor, as shown in the PhotoView API docs:
PhotoView(
imageProvider: imageProvider,
minScale: PhotoViewComputedScale.contained * 0.8,
maxScale: PhotoViewComputedScale.covered * 1.8,
initialScale: PhotoViewComputedScale.contained * 1.1,
enableRotation: true,
strictScale: true,
)
PhotoViewComputedScale.containedfits the image inside the viewport;coveredfills it.strictScale: truehard-restricts the pinch gesture tominScale/maxScaleinstead of letting the gesture overshoot and spring back.gaplessPlayback(defaultfalse) decides whether the previous image stays visible while a newimageProviderresolves — set it totruefor gallery transitions to avoid flashes.backgroundDecorationdefaults toColors.black, andbasePositiondefaults toAlignment.center.
One practical note from the docs: if the zoomed image must not spill past its container, wrap PhotoView in a ClipRect.
Galleries with PhotoViewGallery
For swipeable sets of images, PhotoViewGallery.builder combines a PageView with per-page PhotoViewGalleryPageOptions:
PhotoViewGallery.builder(
scrollPhysics: const BouncingScrollPhysics(),
itemCount: galleryItems.length,
builder: (context, index) => PhotoViewGalleryPageOptions(
imageProvider: AssetImage(galleryItems[index].image),
initialScale: PhotoViewComputedScale.contained * 0.8,
heroAttributes: PhotoViewHeroAttributes(tag: galleryItems[index].id),
),
loadingBuilder: (context, event) => Center(
child: CircularProgressIndicator(
value: event == null
? null
: event.cumulativeBytesLoaded / event.expectedTotalBytes,
),
),
pageController: pageController,
onPageChanged: onPageChanged,
)
Controllers, heroes, and state
Two controllers expose PhotoView’s internals, and both must be disposed by whoever creates them, following the usual Flutter controller pattern:
late final PhotoViewController controller;
@override
void initState() {
super.initState();
controller = PhotoViewController()
..outputStateStream.listen((value) {
setState(() => currentScale = value.scale);
});
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
PhotoViewController reports the full PhotoViewControllerValue (scale, position, rotation), while PhotoViewScaleStateController tracks just the discrete scale state used by double-tap cycles (scaleStateCycle). For hero animations, pass heroAttributes: const PhotoViewHeroAttributes(tag: 'someTag') on both screens; the docs warn that image retrieval should be synchronous when a hero attribute is set. wantKeepAlive: true preserves zoom state when the page is recycled.
When to prefer InteractiveViewer
Flutter’s built-in InteractiveViewer is a pan-and-zoom container for any child, with minScale = 0.8, maxScale = 2.5, constrained = true, a TransformationController, and a builder constructor for lazily building large content. It has no ImageProvider, no loading progress, no hero integration, and no double-tap scale cycle.
Reach for InteractiveViewer when you want to zoom a map, a canvas, a chart, or a custom widget. Reach for photo_view when the subject is an image (or SVG) and you want computed fit scales, gaplessPlayback, gallery paging, and image-loading feedback out of the box.
Takeaway: photo_view 0.15.0 gives you pinch, pan, rotation, computed min/max scales, hero tags, and gallery support with very little code — keep InteractiveViewer in mind only for non-image content where its simple minScale/maxScale bounds are enough.