Apparence-io / CamerAwesome

📸 Embedding a camera experience within your own app shouldn't be that hard. A flutter plugin to integrate awesome Android / iOS camera experience.
https://ApparenceKit.dev
MIT License
976 stars 256 forks source link

pinch to zoom #33

Closed jamesdixon closed 2 years ago

jamesdixon commented 4 years ago

Hello! Awesome library. Kudos to your and your team.

Has anyone implemented pinch-to-zoom? I believe the primitives are there but curious if anyone has done it.

Cheers.

g-apparence commented 4 years ago

Hey, thank you @jamesdixon 👍 We love to see our work helps others!

I didn't try myself, but as Flutter has a complete GestureDetector Widget I think it's doable.

jamesdixon commented 4 years ago

Will do! If I get it working, I'll share here for others

bdlukaa commented 4 years ago

Will do! If I get it working, I'll share here for others

Did you get it working already?

rohrz4nge commented 4 years ago

Just implemented it myself. Since the zoomNotifier is initialized with 0 we do need to add 1 in order for the multiplication to work. You need a variable, for example named double _previousScale; to save the scale from the beginning of the zoom event.

    return GestureDetector(
      onScaleStart: (ScaleStartDetails details) {
        _previousScale = _zoomNotifier.value + 1;
      },
      onScaleUpdate: (ScaleUpdateDetails details) {
        double result = _previousScale * details.scale - 1;
        if (result < 1 && result > 0) {
          _zoomNotifier.value = result;
        }
      },
      child: CameraAwesome(
        zoom: _zoomNotifier,
        ...
      ),
    );
ghost commented 2 years ago

Thanks @rohrz4nge, I added this feature to CamerAwesome :)