### Check Available Application Identifiers (AIs) with Dart Source: https://context7.com/mobui/gs1_barcode_parser/llms.txt Demonstrates how to check for the presence of specific Application Identifiers (AIs) in a GS1 barcode and retrieve all available AIs. It also shows how to get all parsed data and parsed elements with their metadata, including raw data and ISO information. ```dart import 'package:gs1_barcode_parser/gs1_barcode_parser.dart'; void main() { final String barcode = '010460714356059821FGXEAGA5A1GAH91EE0692VW/n3g0hYP6kqx1WjVy/fnpKT+i7N3FT8QPUyzzKQT4='; final parser = GS1BarcodeParser.defaultParser(); final result = parser.parse(barcode); // Check for specific AIs if (result.hasAI('01')) { print('Has GTIN: ${result.getAIData('01')}'); } if (result.hasAI('17')) { print('Has expiry date: ${result.getAIData('17')}'); } else { print('No expiry date found'); } // List all available AIs print('Available AIs: ${result.AIs.join(', ')}'); // Output: 01, 21, 91, 92 // Get all parsed data final Map allData = result.getAIsData; print('\nAll parsed data:'); allData.forEach((ai, value) { print(' AI $ai: $value'); }); // Get all parsed elements with metadata final Map allElements = result.getAIsParsedElement; print('\nAll elements:'); allElements.forEach((ai, element) { print(' AI ${element.aiCode} (${AI.AIS[element.aiCode]?.dataTitle}):'); print(' Raw: ${element.rawData}'); print(' Parsed: ${element.data}'); if (element.iso.isNotEmpty) { print(' ISO: ${element.iso}'); } }); // Get all raw data final Map allRawData = result.getAIsRawData; print('\nAll raw data:'); allRawData.forEach((ai, rawValue) { print(' AI $ai: $rawValue'); }); } ``` -------------------------------- ### Parse Product Identification and Dates with Dart Source: https://context7.com/mobui/gs1_barcode_parser/llms.txt Extracts product GTIN, serial number, price, and internal company data from a GS1 barcode. It demonstrates how to use `GS1BarcodeParser.defaultParser()` and `getAIData()` to retrieve specific data fields based on their Application Identifiers (AIs). Includes an example of accessing parsed element metadata like ISO codes. ```dart import 'package:gs1_barcode_parser/gs1_barcode_parser.dart'; void main() { // Tobacco product with production date, batch, and serial number final String tobaccoBarcode = '010460043993125621JgXJ5.T800511200093Mdlr'; final parser = GS1BarcodeParser.defaultParser(); final result = parser.parse(tobaccoBarcode); // Product identification final gtin = result.getAIData('01'); // GTIN: 04600439931256 print('GTIN: $gtin'); // Serial number final serial = result.getAIData('21'); // Serial: JgXJ5.T print('Serial Number: $serial'); // Price per unit final price = result.getAIData('8005'); // 112000 print('Price per unit: $price'); // Internal company data final internal = result.getAIData('93'); // Mdlr print('Internal data: $internal'); // Complete element with ISO and metadata final serialElement = result.getAIParsedElement('21'); if (serialElement != null) { print('AI Code: ${serialElement.aiCode}'); print('Raw Data: ${serialElement.rawData}'); print('Parsed Data: ${serialElement.data}'); print('ISO: ${serialElement.iso}'); } } ``` -------------------------------- ### Parse Variable Measure Trade Items with Dart Source: https://context7.com/mobui/gs1_barcode_parser/llms.txt Handles GS1 barcodes containing variable measure trade items, such as weight and pricing. It shows how to extract net weight (e.g., kg) and price with currency information using AIs like '3103' and '3932'. The example includes accessing raw data and parsed data for these elements. ```dart import 'package:gs1_barcode_parser/gs1_barcode_parser.dart'; void main() { // Milk product with weight measurement final String milkBarcode = '0103041094787443215Qbag!93Zjqw3103000353'; final parser = GS1BarcodeParser.defaultParser(); final result = parser.parse(milkBarcode); // Product identification print('GTIN: ${result.getAIData('01')}'); // 03041094787443 // Serial number print('Serial: ${result.getAIData('21')}'); // 5Qbag! // Net weight in kg with 3 decimal places (AI 3103) final weight = result.getAIData('3103'); // 0.353 kg print('Weight: $weight kg'); print('Raw weight: ${result.getAIRawData('3103')}'); // 000353 // Internal data print('Internal: ${result.getAIData('93')}'); // Zjqw // Example with price final pricedBarcode = ']C101040123456789011715012910ABC1233932971471131030005253922471142127649716'; final pricedResult = parser.parse(pricedBarcode); // Price with ISO currency (AI 3932: 2 decimal places, ISO 971 = AFN currency) final priceElement = pricedResult.getAIParsedElement('3932'); if (priceElement != null) { print('Price: ${priceElement.data}'); // 47.11 print('Currency ISO: ${priceElement.iso}'); // 971 print('Raw price: ${priceElement.rawData}'); // 971471 } } ``` -------------------------------- ### Parse Pharmaceutical and Medical Barcodes in Dart Source: https://context7.com/mobui/gs1_barcode_parser/llms.txt This code snippet shows how to parse GS1 barcodes specific to the pharmaceutical and healthcare industries. It extracts data such as GTIN, serial numbers, expiry dates, and National Healthcare Reimbursement Numbers (NHRNs) using the default GS1 parser. It also includes an example for parsing medical device barcodes with internal identifiers. ```dart import 'package:gs1_barcode_parser/gs1_barcode_parser.dart'; void main() { // Pharmaceutical product with NHRN final String pharmaBarcode = '0105609380810435212674577536673210A2075I0172509307149507343'; final parser = GS1BarcodeParser.defaultParser(); final result = parser.parse(pharmaBarcode); // Product identification print('GTIN: ${result.getAIData('01')}'); // 05609380810435 // Serial number print('Serial: ${result.getAIData('21')}'); // 2674577536673210A2075I0 // Expiry date (AI 17: YYMMDD format) if (result.hasAI('17')) { final expiryDate = result.getAIData('17'); print('Expiry date: $expiryDate'); } // National Healthcare Reimbursement Number (Germany PZN: AI 710) // France CIP: AI 711, Spain CN: AI 712, etc. if (result.hasAI('714')) { print('NHRN Portugal AIM: ${result.getAIData('714')}'); // 9507343 } // Medical device example final String medicalBarcode = '010460714356059821FGXEAGA5A1GAH91EE0692VW/n3g0hYP6kqx1WjVy/fnpKT+i7N3FT8QPUyzzKQT4='; final medResult = parser.parse(medicalBarcode); print(' Medical Device:'); print('GTIN: ${medResult.getAIData('01')}'); // 04607143560598 print('Serial: ${medResult.getAIData('21')}'); // FGXEAGA5A1GAH print('Internal 1: ${medResult.getAIData('91')}'); // EE06 print('Internal 2: ${medResult.getAIData('92')}'); // VW/n3g0hYP6kqx1WjVy/fnpKT+i7N3FT8QPUyzzKQT4= } ``` -------------------------------- ### Initialize GS1 Barcode Parser (Dart) Source: https://context7.com/mobui/gs1_barcode_parser/llms.txt Demonstrates how to initialize the GS1 barcode parser with default settings or a custom configuration. Custom configurations allow for options like allowing empty prefixes, specifying a group separator, and defining custom Application Identifiers (AIs). ```dart import 'package:gs1_barcode_parser/gs1_barcode_parser.dart'; void main() { // Create parser with default configuration final parser = GS1BarcodeParser.defaultParser(); // Create parser with custom configuration final customParser = GS1BarcodeParser.configurableParser( GS1BarcodeParserConfig( allowEmptyPrefix: true, groupSeparator: '\u{001d}', customAIs: { '99': AI( code: '99', dataTitle: 'CUSTOM', type: AIFormatType.VARIABLE_LENGTH, regExpString: r'^99([A-Z0-9]{0,20})$', description: 'Custom application identifier', ), }, ), ); } ``` -------------------------------- ### Handle GS1 Barcode Parsing Errors and Validation in Dart Source: https://context7.com/mobui/gs1_barcode_parser/llms.txt This Dart code demonstrates robust error handling and validation for GS1 barcode parsing using a try-catch mechanism. It illustrates how to catch specific exceptions like `GS1DataException` and `GS1ParseException` for various invalid scenarios, including empty barcodes, incorrect AI formats, and missing prefixes with strict configurations. It also presents a safe parsing pattern function. ```dart import 'package:gs1_barcode_parser/gs1_barcode_parser.dart'; void main() { final parser = GS1BarcodeParser.defaultParser(); try { // Empty barcode final emptyResult = parser.parse(''); print('Parsed empty barcode: $emptyResult'); } catch (e) { print('Error: $e'); // GS1DataException: Barcode is empty } try { // Invalid AI final invalidBarcode = '9904012345678901'; // 99 is valid but wrong format final result = parser.parse(invalidBarcode); print('Parsed: ${result.getAIsData}'); } catch (e) { print('Parse error: $e'); } try { // Missing FNC1 prefix with strict config final strictParser = GS1BarcodeParser.configurableParser( GS1BarcodeParserConfig( allowEmptyPrefix: false, // Require prefix ), ); final noPrefixBarcode = '01040123456789011715012910ABC123'; final result = strictParser.parse(noPrefixBarcode); print('Parsed: $result'); } catch (e) { print('Error: $e'); // GS1DataException: FNC1 prefix not found } // Safe parsing pattern String safeParse(String barcode) { try { final result = parser.parse(barcode); if (result.hasAI('01')) { return 'GTIN: ${result.getAIData('01')}'; } return 'No GTIN found'; } on GS1DataException catch (e) { return 'Invalid barcode: ${e.message}'; } on GS1ParseException catch (e) { return 'Parse error: ${e.message}'; } catch (e) { return 'Unknown error: $e'; } } print(safeParse(']C101040123456789011715012910ABC123')); print(safeParse('invalid')); print(safeParse('')); } ``` -------------------------------- ### Define and Parse Custom Application Identifiers in Dart Source: https://context7.com/mobui/gs1_barcode_parser/llms.txt This snippet demonstrates how to define and use custom Application Identifiers (AIs) with the GS1 Barcode Parser. It involves creating an AI configuration with custom codes, data titles, and validation rules, then using a configurable parser to process barcodes containing these custom AIs. This is useful for proprietary barcode formats. ```dart import 'package:gs1_barcode_parser/gs1_barcode_parser.dart'; void main() { // Define custom AIs final customAIs = { '99': AI( code: '99', dataTitle: 'CUSTOM ID', type: AIFormatType.VARIABLE_LENGTH, regExpString: r'^99([A-Z0-9]{0,20})$', description: 'Custom identifier for internal use', ), '98': AI( code: '98', dataTitle: 'LOCATION', type: AIFormatType.VARIABLE_LENGTH, regExpString: r'^98([A-Z0-9]{0,30})$', description: 'Warehouse location code', ), }; // Create parser with custom AIs final parser = GS1BarcodeParser.configurableParser( GS1BarcodeParserConfig( allowEmptyPrefix: true, groupSeparator: '\u{001d}', customAIs: customAIs, ), ); // Parse barcode with custom AI final String customBarcode = '01040123456789011799CUSTOM12398WAREHOUSE5'; final result = parser.parse(customBarcode); print('GTIN: ${result.getAIData('01')}'); // 04012345678901 print('Custom ID: ${result.getAIData('99')}'); // CUSTOM123 print('Location: ${result.getAIData('98')}'); // WAREHOUSE5 // Access custom AI element final customElement = result.getAIParsedElement('99'); if (customElement != null) { print('Custom AI: ${customElement.aiCode}'); print('Title: ${customAIs['99']?.dataTitle}'); print('Data: ${customElement.data}'); } } ``` -------------------------------- ### Parse Raw Scanner Data with Code Type (Dart) Source: https://context7.com/mobui/gs1_barcode_parser/llms.txt Illustrates how to parse barcode data directly from scanners that may not include the FNC1 prefix. This method requires explicitly specifying the `codeType` (e.g., `CodeType.DATAMATRIX`) when calling the `parse` method to correctly interpret the data. ```dart import 'package:gs1_barcode_parser/gs1_barcode_parser.dart'; void main() { // Raw barcode without prefix (from scanner) final String rawBarcode = '01040123456789011715012910ABC123393297147113103000525392247114212764971691'; final parser = GS1BarcodeParser.defaultParser(); // Specify code type when prefix is missing final result = parser.parse(rawBarcode, codeType: CodeType.DATAMATRIX); print(result.code.type); // Output: CodeType.DATAMATRIX print(result.code.codeTitle); // Output: GS1 DataMatrix // Access parsed data print(result.getAIData('01')); // Output: 04012345678901 print(result.getAIRawData('01')); // Output: 04012345678901 } ``` -------------------------------- ### Parse GS1-128 Barcode with FNC1 in Dart Source: https://github.com/mobui/gs1_barcode_parser/blob/master/README.md Parses a GS1-128 barcode string that includes FNC1 separators. It utilizes the GS1BarcodeParser.defaultParser() to process the barcode and returns a structured representation of the data. Dependencies include the GS1 barcode parsing library. ```dart final String barcode = ']C101040123456789011715012910ABC1233932971471131030005253922471142127649716'; final parser = GS1BarcodeParser.defaultParser(); final result = parser.parse(barcode); print(result); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.