I'm trying to print some receipts using a thermal printer from the web platform of my Flutterflow app. I'm using the following flutter package for it: https://github.com/usmannaushahi/usb_thermal_printer_web
I'm able to create a custom widget with this code:
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/schema/structs/index.dart';
import '/backend/schema/enums/enums.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/widgets/index.dart'; // Imports other custom widgets
import '/custom_code/actions/index.dart'; // Imports custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom widget code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!
import 'package:usb_thermal_printer_web/usb_thermal_printer_web.dart';
import 'package:usb_device/usb_device.dart';
class OrderReceiptPrint extends StatefulWidget {
const OrderReceiptPrint({
super.key,
this.width,
this.height,
});
final double? width;
final double? height;
@override
State<OrderReceiptPrint> createState() => _OrderReceiptPrintState();
}
class _OrderReceiptPrintState extends State<OrderReceiptPrint> {
printReceipt() async {
WebThermalPrinter _printer = WebThermalPrinter();
//Pairing Device is required.
await _printer.pairDevice(vendorId: 0x4070, productId: 0x33054);
await _printer.printText('DKT Mart', bold: true, centerAlign: true);
await _printer.printEmptyLine();
await _printer.printRow("Products", "Sale");
await _printer.printEmptyLine();
for (int i = 0; i < 10; i++) {
await _printer.printRow(
'A big title very big title ${i + 1}', '${(i + 1) * 510}.00 AED');
await _printer.printEmptyLine();
}
await _printer.printEmptyLine();
await _printer.closePrinter();
}
@override
Widget build(BuildContext context) {
return Column(children: [
ElevatedButton(
onPressed: () {
// startScan();
printReceipt();
},
child: const Text('Test Print'),
),
]);
}
}The widget compiles successfully. However, when I try to use it, I get the following error in the browser console:
Upon doing some reading, I got to understand that the package needs to ask for a WebUSB permission but it's not doing that.
Can someone suggest how to proceed from here?
Serge Middendorf Pooja Bhaumik any help is appreciated. ๐