PhotoViewGallery class

A StatefulWidget that shows multiple PhotoView widgets in a PageView

Some of PhotoView constructor options are passed direct to PhotoViewGallery constructor. Those options will affect the gallery in a whole.

Some of the options may be defined to each image individually, such as initialScale or PhotoViewHeroAttributes. Those must be passed via each PhotoViewGalleryPageOptions.

Example of usage as a list of options:

PhotoViewGallery(
  pageOptions: <PhotoViewGalleryPageOptions>[
    PhotoViewGalleryPageOptions(
      imageProvider: AssetImage("assets/gallery1.jpg"),
      heroAttributes: const PhotoViewHeroAttributes(tag: "tag1"),
    ),
    PhotoViewGalleryPageOptions(
      imageProvider: AssetImage("assets/gallery2.jpg"),
      heroAttributes: const PhotoViewHeroAttributes(tag: "tag2"),
      maxScale: PhotoViewComputedScale.contained * 0.3
    ),
    PhotoViewGalleryPageOptions(
      imageProvider: AssetImage("assets/gallery3.jpg"),
      minScale: PhotoViewComputedScale.contained * 0.8,
      maxScale: PhotoViewComputedScale.covered * 1.1,
      heroAttributes: const HeroAttributes(tag: "tag3"),
    ),
  ],
  loadingBuilder: (context, progress) => Center(
           child: Container(
             width: 20.0,
             height: 20.0,
             child: CircularProgressIndicator(
               value: _progress == null
                   ? null
                   : _progress.cumulativeBytesLoaded /
                       _progress.expectedTotalBytes,
             ),
           ),
         ),
  backgroundDecoration: widget.backgroundDecoration,
  pageController: widget.pageController,
  onPageChanged: onPageChanged,
)

Example of usage with builder pattern:

PhotoViewGallery.builder(
  scrollPhysics: const BouncingScrollPhysics(),
  builder: (BuildContext context, int index) {
    return PhotoViewGalleryPageOptions(
      imageProvider: AssetImage(widget.galleryItems[index].image),
      initialScale: PhotoViewComputedScale.contained * 0.8,
      minScale: PhotoViewComputedScale.contained * 0.8,
      maxScale: PhotoViewComputedScale.covered * 1.1,
      heroAttributes: HeroAttributes(tag: galleryItems[index].id),
    );
  },
  itemCount: galleryItems.length,
  loadingBuilder: (context, progress) => Center(
           child: Container(
             width: 20.0,
             height: 20.0,
             child: CircularProgressIndicator(
               value: _progress == null
                   ? null
                   : _progress.cumulativeBytesLoaded /
                       _progress.expectedTotalBytes,
             ),
           ),
         ),
  backgroundDecoration: widget.backgroundDecoration,
  pageController: widget.pageController,
  onPageChanged: onPageChanged,
)
Inheritance

Constructors

PhotoViewGallery({Key? key, required List<PhotoViewGalleryPageOptions>? pageOptions, LoadingBuilder? loadingBuilder, BoxDecoration? backgroundDecoration, bool wantKeepAlive = false, bool gaplessPlayback = false, bool reverse = false, PageController? pageController, PhotoViewGalleryPageChangedCallback? onPageChanged, ValueChanged<PhotoViewScaleState>? scaleStateChangedCallback, bool enableRotation = false, ScrollPhysics? scrollPhysics, Axis scrollDirection = Axis.horizontal, Size? customSize, bool allowImplicitScrolling = false, bool pageSnapping = true})
Construct a gallery with static items through a list of PhotoViewGalleryPageOptions.
const
PhotoViewGallery.builder({Key? key, required int? itemCount, required PhotoViewGalleryBuilder? builder, LoadingBuilder? loadingBuilder, BoxDecoration? backgroundDecoration, bool wantKeepAlive = false, bool gaplessPlayback = false, bool reverse = false, PageController? pageController, PhotoViewGalleryPageChangedCallback? onPageChanged, ValueChanged<PhotoViewScaleState>? scaleStateChangedCallback, bool enableRotation = false, ScrollPhysics? scrollPhysics, Axis scrollDirection = Axis.horizontal, Size? customSize, bool allowImplicitScrolling = false, bool pageSnapping = true})
Construct a gallery with dynamic items.
const

Properties

allowImplicitScrolling bool
When user attempts to move it to the next element, focus will traverse to the next page in the page view.
final
backgroundDecoration BoxDecoration?
Mirror to PhotoView.backgroundDecoration
final
builder PhotoViewGalleryBuilder?
Called to build items for the gallery when using PhotoViewGallery.builder
final
customSize Size?
Mirror to PhotoView.customSize
final
enableRotation bool
Mirror to PhotoView.enableRotation
final
gaplessPlayback bool
Mirror to PhotoView.gaplessPlayback
final
hashCode int
The hash code for this object.
no setterinherited
itemCount int?
The count of items in the gallery, only used when constructed via PhotoViewGallery.builder
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
loadingBuilder LoadingBuilder?
Mirror to PhotoView.loadingBuilder
final
onPageChanged PhotoViewGalleryPageChangedCallback?
An callback to be called on a page change
final
pageController PageController?
An object that controls the PageView inside PhotoViewGallery
final
pageOptions List<PhotoViewGalleryPageOptions>?
A list of options to describe the items in the gallery
final
pageSnapping bool
final
reverse bool
Mirror to PageView.reverse
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scaleStateChangedCallback ValueChanged<PhotoViewScaleState>?
Mirror to PhotoView.scaleStateChangedCallback
final
scrollDirection Axis
The axis along which the PageView scrolls. Mirror to PageView.scrollDirection
final
scrollPhysics ScrollPhysics?
ScrollPhysics for the internal PageView
final
wantKeepAlive bool
Mirror to PhotoView.wantKeepAlive
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<StatefulWidget>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited