Open LoicUV opened 2 weeks ago
Thank you for your request. Currently I do not plan to invest time in this issue as it is a very specific case but PRs are welcome. I leave this open for now.
@robingenz I'm having the same issue but in a normal Ionic/Capacitor App. It worked but now I suddenly get this error...
VM3:943 Uncaught (in promise) Error: Attempt to invoke virtual method 'void androidx.camera.view.PreviewView.setScaleType(androidx.camera.view.PreviewView$ScaleType)' on a null object reference
`const startScan = async () => { // eslint-disable-next-line @typescript-eslint/no-unused-vars const { camera } = await BarcodeScanner.checkPermissions(); document.querySelector('body')?.classList.add('barcode-scanner-active');
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const listener = await BarcodeScanner.addListener(
'barcodeScanned',
async result => {
BarcodeScanner.stopScan();
setShowQrLoading(true);
document.querySelector('body')?.classList.remove('barcode-scanner-active');
await loginWithToken(result.barcode.rawValue);
},
);
// Start the barcode scanner
await BarcodeScanner.startScan();
};`
After the startScan() method the error appears...
@robingenz I found the issue:
https://github.com/capawesome-team/capacitor-mlkit/tree/main/packages/barcode-scanning#data-binding
Data binding was not enabled...
Plugin(s)
Version
6.1.0
Platform(s)
Current behavior
Hi there.
So I have kind of a specific android app structure with multiple android fragments, and with capacitor instanciated in one of them using
BridgeFragment
class. The particularity is that plugins are not automatically loaded when using this class, you have to manually add each plugin inside the fragment class as stated here https://github.com/ionic-team/capacitor/issues/5564#issuecomment-1735320796. This works well, except for the barcode scanning plugin, which produces the famousNullPointerException
duringstartScan(...)
despite having data binding enabled.My guess is that the following code breaks because the app doesn't find the preview view since the plugin is instanciated in a fragment ?
I'm a beginner android developer so I'm kind of lost here as to where the problem lies exactly. I'm aware that my app's implementation with fragment is rather advanced so I'll understand if it's not something you want to support in your plugin.
Expected behavior
No error during scan.
Reproduction
https://github.com/LoicUV/scanner-example
Steps to reproduce
SCAN BARCODE
buttonOther information
No response
Capacitor doctor
Before submitting