From a5c1483bb0a68b9d5b21df9116a92fa1e5df6451 Mon Sep 17 00:00:00 2001 From: Gopaul Girish Date: Thu, 19 Nov 2020 11:01:14 +0400 Subject: [PATCH] Send index to loadingBuilder callback in PhotoViewGallery --- lib/photo_view_gallery.dart | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/photo_view_gallery.dart b/lib/photo_view_gallery.dart index a7209e45..f09e0dfa 100644 --- a/lib/photo_view_gallery.dart +++ b/lib/photo_view_gallery.dart @@ -153,8 +153,10 @@ class PhotoViewGallery extends StatefulWidget { /// [ScrollPhysics] for the internal [PageView] final ScrollPhysics scrollPhysics; - /// Mirror to [PhotoView.loadingBuilder] - final LoadingBuilder loadingBuilder; + /// While [imageProvider] is not resolved, [loadingBuilder] is called by [PhotoView] + /// into the screen, by default it is a centered [CircularProgressIndicator] and + /// the index of the currently loading image is passed + final LoadingBuilderWithIndex loadingBuilder; /// Mirror to [PhotoView.backgroundDecoration] final Decoration backgroundDecoration; @@ -265,7 +267,7 @@ class _PhotoViewGalleryState extends State { : PhotoView( key: ObjectKey(index), imageProvider: pageOption.imageProvider, - loadingBuilder: widget.loadingBuilder, + loadingBuilder: (context, imageChunkEvent) => widget.loadingBuilder(context, imageChunkEvent, index), backgroundDecoration: widget.backgroundDecoration, controller: pageOption.controller, scaleStateController: pageOption.scaleStateController, @@ -404,3 +406,10 @@ class PhotoViewGalleryPageOptions { /// Mirror to [PhotoView.errorBuilder] final ImageErrorWidgetBuilder errorBuilder; } + +/// A type definition for a callback to show a widget while the image is loading, an index and [ImageChunkEvent] is passed to inform progress +typedef LoadingBuilderWithIndex = Widget Function( + BuildContext context, + ImageChunkEvent event, + int index, +);