2

I am building an app using flutter where I want to scan an image(that includes QR image). I am using packages available to read QR codes, but not working for me. Is there any package/solution to read a QR code from an image?

I Tried package:

qr_code_tools: ^0.0.6`

Future _getPhotoByGallery() async {
     var image = await ImagePicker.pickImage(source: ImageSource.gallery);
 String path = image.path;
 decode(path); 
}


Future decode(String path) async {
  print(path);
  String data = await QrCodeToolsPlugin.decodeFrom(path);
  setState(() {
    _data = data;
  });
}

I expect the output of QRCode from the selected image of Gallery.

But getting error "Null".

NiiLx
  • 606
  • 7
  • 18

2 Answers2

1

You can use Firebase ML Kit. They have barcode scanning, click here to learn more.

Barel13
  • 40
  • 7
1

You can read QR code from device gallery using this package. qr_code_tools

String _data = '';

  void _getQrByGallery() {
    Observable<File>.fromFuture(
            ImagePicker.pickImage(source: ImageSource.gallery))
        .flatMap((File file) {
      return Observable<String>.fromFuture(
        QrCodeToolsPlugin.decodeFrom(file.path),
      );
    }).listen((String data) {
      setState(() {
        _data = data;
      });
    }).onError((dynamic error, dynamic stackTrace) {
      setState(() {
        _data = '';
      });
    });
  }
Parth Bhanderi
  • 2,378
  • 3
  • 15
  • 30