I wish to scan a QR Code in Flutter and I'm running on Linux and Chrome (web) without any mobile device. When I run my code, I get the following error:
Unsupported operation: Trying to use the default qrview implementation for TargetPlatform.linux but there isn't a default one
Here is a snippet of the code to scan the QR code
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:qr_code_scanner/qr_code_scanner.dart';
import 'package:url_launcher/url_launcher.dart';
class Scanner extends StatefulWidget {
const Scanner({super.key});
@override
_ScannerState createState() => _ScannerState();
}
class _ScannerState extends State<Scanner> {
final GlobalKey qrKey = GlobalKey(debugLabel: 'QR');
late QRViewController controller;
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Center(child: Text("Scan the Building QR Code"),),
),
body: Stack(
children: [
Column(
children: <Widget>[
Expanded(
flex: 4,
child: Stack(
children: [
QRView(
key: qrKey,
onQRViewCreated: _onQRViewCreated,
),
Center(
child: Container(
width: 300,
height: 300,
decoration: BoxDecoration(
border: Border.all(
color: Colors.black,
width: 4,
),
borderRadius: BorderRadius.circular(12),
),
),
)
],
),
),
],
),
],
),
);
}
void _onQRViewCreated(QRViewController controller) {
this.controller = controller;
controller.scannedDataStream.listen((scanData) async {
controller.pauseCamera();
// ignore: deprecated_member_use
if (await canLaunch(scanData.code)) {
// ignore: deprecated_member_use
await launch(scanData.code);
controller.resumeCamera();
} else {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Could not find viable URL'),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text('Barcode Type: ${describeEnum(scanData.format)}'),
Text('Data: ${scanData.code}'),
],
),
),
actions: <Widget>[
TextButton(
child: const Text('OK'),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
).then((value) => controller.resumeCamera());
}
});
}
}
And this is the screen that I get:

The package does only support the Android & iOS platform s you can see on https://pub.dev/packages/qr_code_scanner