bluefireteam / photo_view

📸 Easy to use yet very customizable zoomable image widget for Flutter, Photo View provides a gesture sensitive zoomable widget. Photo View is largely used to show interacive images and other stuff such as SVG.
MIT License
1.9k stars 546 forks source link

Viewing Stacks #555

Open yakou32 opened 4 months ago

yakou32 commented 4 months ago

I'm trying to render a zoomable/panable Stack - that is a large photo with positioned informations on top of it.

Here is an example:

Stack(
  fit: StackFit.expand,
  clipBehavior: Clip.none,
  children: [
    const Image(
      image: AssetImage(
      'assets/images/some-photo.jpg'), // This may be large (eg. height 5000 x width 3000)
    ),
    Positioned( // The values are based on the photo dimension, in order to inform a specific area
      top: 2500,
      left: 1500,
      child: Container(
        color: Colors.red.withOpacity(0.5),
        width: 380,
        height: 380,
      ),
    ),
  ],
),

Thing is Stack resizes the children to fit its container:

One solution I found was to make the Stack grow as much as needed. This way I ensure the underneath image is not shrinked, and the positionned elements remain correct:

OverflowBox(
  maxWidth: 3000, // Image width
  maxHeight: 5000, // Image height
  child:  Stack(
    // Stack content here
  ),
),

Although content of the Stack is now correct, if I put this in PhotoView, the PhotoViewComputedScale is not correct:

PhotoView.customChild(
  initialScale: PhotoViewComputedScale.contained, // Whole image expected, but it's zoomed in
  minScale: PhotoViewComputedScale.contained * 0.8,
  basePosition: Alignment.center,
  child:  // Overflowbox here
),

Indeed, the Overflowbox dimension seems not to be taken into account. I tried to wrapped it in a SizedBox at image's dimension with no success.

Would you know how to solve this?

Thanks!

yakou32 commented 4 months ago

I found a solution with InteractiveViewer() - that is to set its constrained property to false. This way, the children are not constrained and the Stack layout is respected. And no need to have any Overflowbox messing around.

Is there anything similar for PhotoView?