DIGIT Scanner Package

A scanner package used for scanning QR codes and GS1 barcodes.

Link to the Pub Package:

How to Use the Scanner Package

To use the digit_scanner package, add the following dependency to your pubspec.yaml file:

dependencies:
  digit_scanner: ^latest

Initialise DigitScannerBloc Provider

To initialise the DigitScannerBloc provider in your application, add the following code:

BlocProvider(
                create: (_) {
                  return DigitScannerBloc(
                    const DigitScannerState(),
                  );
                },
              ),

Clear the Scanner State

To clear the scanner state, use the following code:

context.read<DigitScannerBloc>().add(
    const DigitScannerEvent.handleScanner(),
);

To navigate to the Digit Scanner page, use this code snippet:

context.router.push(DigitScannerRoute(
                              quantity: 1, // Max no. of codes to be scanned
                              isGS1code: false, // Set Flag to true for scanning GS1 barcode
                              singleValue: true, // Set Flag to false for scanning multiple codes
                            ));

Wrap the DigitScannerListener or DigitScannerBuilder

Wrap the DigitScannerListener or DigitScannerBuilder in your widget tree wherever you need to read the scanned codes from the scanner state:

BlocListener<DigitScannerBloc, DigitScannerState>(
                  listener: (context, scannerState) {
                  if (scannerState.qrCodes.isNotEmpty) {
                  //
                  }
                  },
                  child: BlocBuilder<DigitScannerBloc, DigitScannerState>(
                  builder: (context, scannerState) {
                  if(scannerState.qrCodes.isNotEmpty){
                  return Text(scannerState.qrCodes.last); ///Get the scanned codes after scanning from the scanner State
                  }
                  else {
                  return Container();}
                  }
                  ));

Find out about usage at the example implementation.

Last updated

All content on this page by eGov Foundation is licensed under a Creative Commons Attribution 4.0 International License.