flutter - 如何在 flutter 二维码扫描仪中添加捏合缩放功能?

标签 flutter

我正在使用 qr_code_scanner 开发二维码扫描仪应用程序flutter 包。我无法在其上添加捏缩放功能。是否有添加此功能或其他支持捏缩放功能的二维码扫描器包?请帮我解决这个问题。

最佳答案

InteractiveViewer可以帮助您实现捏合、缩放。 看一下这个: https://api.flutter.dev/flutter/widgets/InteractiveViewer-class.html

如果需要双击缩放,请使用 GestureDetector 包装 InteractiveViewer 并实现 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);
    }
}

关于flutter - 如何在 flutter 二维码扫描仪中添加捏合缩放功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74355480/

相关文章:

android - AAPT : error: attribute fastforward_increment (aka aplicationid. dev:fastforward_increment) 未找到

ios - Sirikit与Flutter集成

list - 如何将多个列表合并为一个列表? Dart

windows - 如何构建 Windows 应用程序的发布版本?

ios - 类 AMSupportURLConnectionDelegate 在两者中都实现

Flutter showSnackBar 在 null 上调用

dart - 可滚动的 flutter 弹出菜单

flutter - 无法在 Flutter TextFormField 中添加 GIF

Flutter 检测到 AVD 但无法连接/定位它

android - 我想从我的 flutter 应用程序启动 WhatsApp 应用程序