Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send index to loadingBuilder callback in PhotoViewGallery #372

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions lib/photo_view_gallery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -265,7 +267,7 @@ class _PhotoViewGalleryState extends State<PhotoViewGallery> {
: 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,
Expand Down Expand Up @@ -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,
);