Code With Bishal
Code With Bishal

Reputation: 156

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);
          },
        );
      }
    }
  }

Upvotes: 4

Views: 14488

Answers (2)

Yuki.M
Yuki.M

Reputation: 435

You can also use mobile_scanner's analyzeImage method.

Upvotes: 0

Kaushik Chandru
Kaushik Chandru

Reputation: 17732

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

https://pub.dev/packages/scan

Upvotes: 1

Related Questions