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

Add childWrapper to PhotoViewGallery #551

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
24 changes: 22 additions & 2 deletions lib/photo_view_gallery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:photo_view/src/controller/photo_view_controller.dart';
import 'package:photo_view/src/controller/photo_view_scalestate_controller.dart';
import 'package:photo_view/src/core/photo_view_gesture_detector.dart';
import 'package:photo_view/src/photo_view_scale_state.dart';
import 'package:photo_view/src/photo_view_wrappers.dart';
import 'package:photo_view/src/utils/photo_view_hero_attributes.dart';

/// A type definition for a [Function] that receives a index after a page change in [PhotoViewGallery]
Expand All @@ -24,6 +25,11 @@ typedef PhotoViewGalleryPageChangedCallback = void Function(int index);
typedef PhotoViewGalleryBuilder = PhotoViewGalleryPageOptions Function(
BuildContext context, int index);

/// A type definition for a [Function] that wraps the [child] in an other
/// [Widget]. Used to apply an overlay to the items.
typedef PhotoViewGalleryChildWrapper = Widget Function(
BuildContext context, int index, Widget child);

/// 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.
Expand Down Expand Up @@ -117,6 +123,7 @@ class PhotoViewGallery extends StatefulWidget {
this.scrollDirection = Axis.horizontal,
this.customSize,
this.allowImplicitScrolling = false,
this.childWrapper = defaultChildWrapper,
}) : itemCount = null,
builder = null,
super(key: key);
Expand All @@ -141,11 +148,17 @@ class PhotoViewGallery extends StatefulWidget {
this.scrollDirection = Axis.horizontal,
this.customSize,
this.allowImplicitScrolling = false,
this.childWrapper = defaultChildWrapper,
}) : pageOptions = null,
assert(itemCount != null),
assert(builder != null),
super(key: key);

static Widget defaultChildWrapper(
BuildContext context, int index, Widget child) {
return child;
}

/// A list of options to describe the items in the gallery
final List<PhotoViewGalleryPageOptions>? pageOptions;

Expand All @@ -155,6 +168,9 @@ class PhotoViewGallery extends StatefulWidget {
/// Called to build items for the gallery when using [PhotoViewGallery.builder]
final PhotoViewGalleryBuilder? builder;

/// Wraps each item. Useful for applying an overlay to all pictures.
final PhotoViewGalleryChildWrapper childWrapper;

/// [ScrollPhysics] for the internal [PageView]
final ScrollPhysics? scrollPhysics;

Expand Down Expand Up @@ -300,8 +316,12 @@ class _PhotoViewGalleryState extends State<PhotoViewGallery> {
errorBuilder: pageOption.errorBuilder,
);

return ClipRect(
child: photoView,
return widget.childWrapper(
context,
index,
ClipRect(
child: photoView,
),
);
}

Expand Down