import 'package:barcode_scan/barcode_scan.dart';

Future<String> scanBarcode() async {
  try {
    String barcode = await BarcodeScanner.scan();
    if (barcode == null) return null;

    String gs = String.fromCharCode(29);
    if (barcode.contains(gs)) {
      var codes = barcode.split(gs);
      barcode = codes.length >= 2 ? codes[1] : barcode;
    } else if (barcode.startsWith("96")) {
      if (barcode.length == 34) {
        int start = barcode.length - 12;
        barcode = barcode.substring(start);
      } else if (barcode.length == 22) {
        int start = barcode.length - 15;
        barcode = barcode.substring(start);
      }
    }
    return barcode;
  } catch (e) {
    print('error: $e');
    return null;
  }
}
