Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scan barcode in Android emulator using virtual scene

I'm developing a Flutter project using the flutter_barcode_reader plugin. Everything is working as expected on a physical Android device, but I can't get the QR code scanner to react on the emulator when I try to scan a QR code in the cameras virtual scene.

Is there any way to achieve this without using a webcam or a physical device?

like image 304
Magnus Avatar asked Nov 06 '22 21:11

Magnus


1 Answers

It seems that the flutter_barcode_reader plugin, is no longer available.

Since there are many other libraries which provides more and better functionality in barcode scanning, I decided to discontinue the development of this project.

Just to focus on your question about scanning QR codes using an emulator, I've managed to scan a QR code from a virtual scene.

Here is a sample app that I've used to simulate this:

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:barcode_scan/barcode_scan.dart';
import 'package:flutter/services.dart';

void main() => runApp(MaterialApp(
      debugShowCheckedModeBanner: false,
      home: HomePage(),
    ));

class HomePage extends StatefulWidget {
  @override
  HomePageState createState() {
    return new HomePageState();
  }
}

class HomePageState extends State<HomePage> {
  String result = "Hey there !";

  Future _scanQR() async {
    try {
      String qrResult = await BarcodeScanner.scan();
      setState(() {
        result = qrResult;
      });
    } on PlatformException catch (ex) {
      if (ex.code == BarcodeScanner.CameraAccessDenied) {
        setState(() {
          result = "Camera permission was denied";
        });
      } else {
        setState(() {
          result = "Unknown Error $ex";
        });
      }
    } on FormatException {
      setState(() {
        result = "You pressed the back button before scanning anything";
      });
    } catch (ex) {
      setState(() {
        result = "Unknown Error $ex";
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("QR Scanner"),
      ),
      body: Center(
        child: Text(
          result,
          style: new TextStyle(fontSize: 30.0, fontWeight: FontWeight.bold),
        ),
      ),
      floatingActionButton: FloatingActionButton.extended(
        icon: Icon(Icons.camera_alt),
        label: Text("Scan"),
        onPressed: _scanQR,
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
    );
  }
}

enter image description here

I can't tell if the problem is with the plugin or the implementation since you haven't provided a sample. Maybe you can try other plugins that are available in pub.dev:

enter image description here

like image 54
MαπμQμαπkγVπ.0 Avatar answered Nov 15 '22 10:11

MαπμQμαπkγVπ.0