Search code examples
flutterdartqr-code

Reading QR Codes from image file in Flutter


I want to read Qr codes from picture files in flutter without using the firebase ML kit.

So far I was able to create the image picker but don't know what to do next.

Dependency: image_picker: ^0.8.4+1

scan.dart:

File? _image;
Container(
      child: Column(
        children: [
          ElevatedButton.icon(
            style: ElevatedButton.styleFrom(
                primary: Theme.of(context).buttonColor),
            onPressed: () async => pickImage(),
            icon: Icon(Icons.image),
            label: Text("Choose an Image from gallery"),
          )
        ],
      ),
    );

Future<void> pickImage() async {
    await Permission.storage.request();
    var status = await Permission.storage.status;

    if (status.isGranted) {
      final pickedFile =
          await ImagePicker().pickImage(source: ImageSource.gallery);
      if (pickedFile != null) {
        setState(
          () {
            this._image = File(pickedFile.path);
          },
        );
      }
    }
  }

Solution

  • Use this package. You can pass the file and read the qr as expected.

    https://pub.dev/packages/scan