initPlatformState method

Future<bool> initPlatformState({
  1. required WebviewController controller,
})

Implementation

Future<bool> initPlatformState(
    {required WebviewController controller}) async {
  String? barcodeNumber;

  try {
    await controller.initialize();
    await controller
        .loadUrl(getAssetFileUrl(asset: PackageConstant.barcodeFilePath));

    /// Listen to web to receive barcode
    controller.webMessage.listen((event) {
      if (event['methodName'] == "successCallback") {
        if (event['data'] is String &&
            event['data'].isNotEmpty &&
            barcodeNumber == null) {
          barcodeNumber = event['data'];
          onScanned(barcodeNumber!);
        }
      }
    });
  } catch (e) {
    rethrow;
  }
  return true;
}