Reading QR Codes from image file in Flutter

1,616

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

https://pub.dev/packages/scan

Share:
1,616
Code With Bishal
Author by

Code With Bishal

Updated on January 01, 2023

Comments

  • Code With Bishal
    Code With Bishal over 1 year

    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);
              },
            );
          }
        }
      }
    
  • Code With Bishal
    Code With Bishal over 2 years
    I have already tried using the package but the package does not have null safety and gives an error when I run it.
  • Kaushik Chandru
    Kaushik Chandru over 2 years
    pub.dev/packages/flutter_qr_scan/example This one is also good. It's null safe too
  • Code With Bishal
    Code With Bishal over 2 years
    the popularity of the package is not so good
  • Kaushik Chandru
    Kaushik Chandru over 2 years
    Edited my answer. Please check
  • Code With Bishal
    Code With Bishal over 2 years
    the scan package worked please remove the previous answer so I can mark it as an answer
  • Kaushik Chandru
    Kaushik Chandru over 2 years
    Edited my answer. Glad it worked :)