Home > database >  Flutter: How to make camera scan QR Code and capture any image at the same time?
Flutter: How to make camera scan QR Code and capture any image at the same time?

Time:01-23

If the camera detects a QR Code create a callback and if there is none, I should still be able to take a picture of what the camera is seeing, is there a package for this functionality? Thanks

CodePudding user response:

For scan a QR Code you can use this library in pub dev

https://pub.dev/packages/qr_code_scanner

CodePudding user response:

you can use the "qr_mobile_vision" package to scan QR codes and capture images simultaneously. This package uses the device's camera to scan QR codes and also allows you to take pictures. To use it, you'll need to add the package to your dependencies in your pubspec.yaml file, import it in your code, and then call the appropriate functions to start scanning and capturing images.

Here is an example of how you could use the package to scan a QR code and capture an image at the same time:

import 'package:qr_mobile_vision/qr_camera.dart';
import 'package:qr_mobile_vision/qr_mobile_vision.dart';

QRCamera(
qrCodeCallback: (code) {
print(code);
},
child: Column(
children: <Widget>[
  Expanded(
    child: Container(
      child: Padding(
        padding: const EdgeInsets.all(1.0),
        child: Center(
          child: AspectRatio(
            aspectRatio: 1.0,
            child: QRScannerPreview(
              key: qrTextKey,
            ),
          ),
        ),
      ),
      decoration: BoxDecoration(
        color: Colors.black,
        border: Border.all(
          color: Colors.grey,
          width: 1.0,
        ),
      ),
    ),
  ),
],
),
),

You can use the QRCamera widget, You can also use the QRScannerPreview widget to show the camera preview and qrCodeCallback function to get the QR code scanned.

Additionally, you can use other packages like camera or image_picker to capture images.

  • Related