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

added wantKeepAlive parameter to make it optional #479

Merged
merged 1 commit into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion lib/photo_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ class PhotoView extends StatefulWidget {
required this.imageProvider,
this.loadingBuilder,
this.backgroundDecoration,
this.wantKeepAlive = false,
this.gaplessPlayback = false,
this.heroAttributes,
this.scaleStateChangedCallback,
Expand Down Expand Up @@ -273,6 +274,7 @@ class PhotoView extends StatefulWidget {
required this.child,
this.childSize,
this.backgroundDecoration,
this.wantKeepAlive = false,
this.heroAttributes,
this.scaleStateChangedCallback,
this.enableRotation = false,
Expand Down Expand Up @@ -312,6 +314,11 @@ class PhotoView extends StatefulWidget {
/// Changes the background behind image, defaults to `Colors.black`.
final BoxDecoration? backgroundDecoration;

/// This is used to keep the state of an image in the gallery (e.g. scale state).
/// `false` -> resets the state (default)
/// `true` -> keeps the state
final bool wantKeepAlive;

/// This is used to continue showing the old image (`true`), or briefly show
/// nothing (`false`), when the `imageProvider` changes. By default it's set
/// to `false`.
Expand Down Expand Up @@ -545,7 +552,7 @@ class _PhotoViewState extends State<PhotoView>
}

@override
bool get wantKeepAlive => true;
bool get wantKeepAlive => widget.wantKeepAlive;
}

/// The default [ScaleStateCycle]
Expand Down
7 changes: 7 additions & 0 deletions lib/photo_view_gallery.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class PhotoViewGallery extends StatefulWidget {
required this.pageOptions,
this.loadingBuilder,
this.backgroundDecoration,
this.wantKeepAlive = false,
this.gaplessPlayback = false,
this.reverse = false,
this.pageController,
Expand All @@ -129,6 +130,7 @@ class PhotoViewGallery extends StatefulWidget {
required this.builder,
this.loadingBuilder,
this.backgroundDecoration,
this.wantKeepAlive = false,
this.gaplessPlayback = false,
this.reverse = false,
this.pageController,
Expand Down Expand Up @@ -162,6 +164,9 @@ class PhotoViewGallery extends StatefulWidget {
/// Mirror to [PhotoView.backgroundDecoration]
final BoxDecoration? backgroundDecoration;

/// Mirror to [PhotoView.wantKeepAlive]
final bool wantKeepAlive;

/// Mirror to [PhotoView.gaplessPlayback]
final bool gaplessPlayback;

Expand Down Expand Up @@ -246,6 +251,7 @@ class _PhotoViewGalleryState extends State<PhotoViewGallery> {
child: pageOption.child,
childSize: pageOption.childSize,
backgroundDecoration: widget.backgroundDecoration,
wantKeepAlive: widget.wantKeepAlive,
controller: pageOption.controller,
scaleStateController: pageOption.scaleStateController,
customSize: widget.customSize,
Expand All @@ -270,6 +276,7 @@ class _PhotoViewGalleryState extends State<PhotoViewGallery> {
imageProvider: pageOption.imageProvider,
loadingBuilder: widget.loadingBuilder,
backgroundDecoration: widget.backgroundDecoration,
wantKeepAlive: widget.wantKeepAlive,
controller: pageOption.controller,
scaleStateController: pageOption.scaleStateController,
customSize: widget.customSize,
Expand Down