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

PhotoViewGallery.builder uses customChild how to zoom pictures? #509

Open
evanwsu opened this issue Apr 13, 2022 · 2 comments
Open

PhotoViewGallery.builder uses customChild how to zoom pictures? #509

evanwsu opened this issue Apr 13, 2022 · 2 comments
Labels
bug Something isn't working Custom child
Projects

Comments

@evanwsu
Copy link

evanwsu commented Apr 13, 2022

The current picture background is transparent, so I need to set a background color for the picture, which needs to be achieved using PhotoViewGalleryPageOptions.customChild.
There are two problems:

  1. Unable to double-click to zoom the picture.
  2. How to scale the image width and height.

code segment

PhotoViewGallery.builder(
            itemCount: widget.files.length,
            onPageChanged: onPageChanged,
            pageController: pageController,
            gaplessPlayback: true,
            backgroundDecoration: const BoxDecoration(color: Colors.black),
            builder: (BuildContext context, int index) {
              var path = widget.files[index].path;
              ImageProvider imageProvider;
              if (path.startsWith('http')) {
                imageProvider =
                    CachedNetworkImageProvider(path, maxWidth: screenWidth);
              } else {
                imageProvider =
                    ResizeImage(FileImage(File(path)), width: screenWidth);
              }
              return PhotoViewGalleryPageOptions.customChild(
                child: Container(
                  width: 360,
                  color: Colors.white,
                  child: Image(
                    image: imageProvider,
                    gaplessPlayback: true,
                    fit: BoxFit.contain,
                    width: 360,
                  ),
                ),
                // imageProvider: imageProvider,   >>>Using imageProvider can achieve my needs, but can't set background color.
                filterQuality: FilterQuality.low,
                initialScale: PhotoViewComputedScale.contained,
                gestureDetectorBehavior: HitTestBehavior.opaque,
              );
            },
            loadingBuilder: (context, event) {
              double progress = .0;
              if (event != null) {
                var totalBytes = event.expectedTotalBytes;
                if (totalBytes != null) {
                  progress = event.cumulativeBytesLoaded / totalBytes;
                }
              }
              return Center(
                child: Container(
                  width: 24.0,
                  height: 24.0,
                  child: CircularProgressIndicator(
                    strokeWidth: 2.5,
                    color: ComColors.color_FFFFFF,
                    value: progress,
                  ),
                ),
              );
            },
          )

@evanwsu evanwsu added the bug Something isn't working label Apr 13, 2022
@evanwsu
Copy link
Author

evanwsu commented Apr 15, 2022

The custom method is not very convenient, child is a specified widget and cannot follow the specified width and height of the zoom

@renancaraujo renancaraujo added this to Todo in Bug solving via automation May 24, 2022
@renancaraujo renancaraujo moved this from Todo to Needs triage in Bug solving May 24, 2022
@darkstarx
Copy link

Hi @evansherry!
You image doesn't zoom in on double tap because it has original width equal to the constrained box, so the PhotoViewControllerDelegate.nextScaleState goes from PhotoViewScaleState.initial to PhotoViewScaleState.covering (by the defaultScaleStateCycle) and checks the new scale, which equals the prev scale since it's originally covering because the childSize for Image equals constrained box. Then the delegate continues moving by the defaultScaleStateCycle and goes to originalSize which equals to the constrained box as well, after that it goes to PhotoViewScaleState.initial again and checks if it equals to the original state (which is PhotoViewScaleState.initial), and if it does, it just stops.

You have two options:

  1. Set childSize with any rational value greater than screen size.
  2. Don't use the screenWidth but resolve the original image size from you ImageProvider and asynchronously update the state with new resolved size for childSize property for your PhotoViewGalleryPageOptions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Custom child
Projects
Bug solving
  
Needs triage
Development

No branches or pull requests

3 participants