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?
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,
);
}
}
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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With