Reputation: 21
I am developing qr code scanner app using qr_code_scanner flutter package.I am unable to add the pinch zoom functionality on that. Is there anyway to add this functionality or other qr code scanner package which supports pinch zoom function? Please help me on this.
Upvotes: 2
Views: 734
Reputation: 116
InteractiveViewer can help you to implement pinch, zoom. Check this out: https://api.flutter.dev/flutter/widgets/InteractiveViewer-class.html
If you need double tap to zoom, wrap InteractiveViewer with GestureDetector and implement onDoubleTap
onDoubleTapDown: _handleDoubleTapDown,
onDoubleTap: () {
kLogger.i('--> on double tap');
_handleDoubleTap();
},
_____
void _handleDoubleTapDown(TapDownDetails details) {
_doubleTapDetails = details;
}
void _handleDoubleTap() {
if (_transformationController.value != Matrix4.identity()) {
_transformationController.value = Matrix4.identity();
} else {
final position = _doubleTapDetails.localPosition;
// For a 3x zoom
_transformationController.value = Matrix4.identity()
..translate(-position.dx * 2, -position.dy * 2)
..scale(3.0);
// Fox a 2x zoom
// ..translate(-position.dx, -position.dy)
// ..scale(2.0);
}
}
Upvotes: 2