So I was finally able to get it. I used the flutter_barcode_listener package with a little bit of customization.
void _handleBarcodeScan(String scannedCode) async {
if (!widget.focusNode.hasFocus) {
return;
}
setState(() {
// scannedcode came in with extra whitespace
_scannedText = scannedCode.trim();
// Scanner configured with enter after scan came in with `a` at the end
if (_scannedText.endsWith("`a`")) {
// # was transformed to 3 I needed to only remove the first 3 since
that is the only spot # will be
_scannedText = _scannedText.replaceFirst("3", "#");
}
// If user manually entered text then often times _scannedText would be
// empty so instead I got the text from the widget
if (_scannedText == "" && widget.controller.text != ""){
_scannedText = widget.controller.text.toUpperCase();
}
// Replace all specific characters as needed
_scannedText = _scannedText
.replaceAll("½", "-")
.replaceAll("``a`", "")
.replaceAll(RegExp(r"\s+"), "") // Remove all spaces, including multiple spaces
.replaceAll("¡3", "#"); // # would sometimes come in as that weird
// character as well
});
widget.controller.clear();
widget.onBarcodeComplete(_scannedText);
}
@override
Widget build(BuildContext context) { return BarcodeKeyboardListener( bufferDuration: widget.bufferDuration, onBarcodeScanned: _handleBarcodeScan, child: TextField( controller: widget.controller, focusNode: widget.focusNode, textCapitalization: TextCapitalization.none, decoration: InputDecoration( labelText: widget.labelText, border: const OutlineInputBorder(), prefixIcon: IconButton( icon: Icon(Icons.clear), onPressed: () { widget.controller.clear(); setState(() { _scannedText = ''; }); }, ), ), onChanged: _onTextChanged, onSubmitted: (value) { }, ), ); } }