wu9007 / qrcode_scanner

🛠 Flutter QR code scanner plugin.
MIT License
358 stars 185 forks source link

Null when user cancelled the scan using Back Button #109

Open alvinvin00 opened 3 years ago

alvinvin00 commented 3 years ago

Hello there, i'm having some problems that

a. If user are pressing Back Button (hardware), Null will be returned instead, the problem is scan method expects Future which means anything that nullable will throw NullError. (EDIT : Solved in 0.3.2)

b. If user are pressing Back Button (software, available on ZKing's platform view), the future will never complete

MerdanDev commented 3 years ago

Yes problem b. is very serius. I am having this problem in which I need to return String and when I press back button it will stuck forever. Only solution for android is remove back button because we have hardware back button or software back button, if ios we need to throw error and catch it after that return something.

alvinvin00 commented 3 years ago

what if user cancels QR Scanning process? Should scan method return null in that case?

MerdanDev commented 3 years ago

I think it will throw error. After that we can catch error and we can show that user cancelled scanning or we can check is it null.

mmkumr commented 3 years ago

Check out this https://pub.dev/packages/barcode_scan_fix.

alvinvin00 commented 3 years ago

bruh, that package are not null-safe

Get Outlook for Androidhttps://aka.ms/AAb9ysg


From: M. Mukesh Kumar @.> Sent: Sunday, June 13, 2021 4:39:07 PM To: leyan95/qrcode_scanner @.> Cc: Alvin Leonardo @.>; Author @.> Subject: Re: [leyan95/qrcode_scanner] Null when user cancelled the scan using Back Button (#109)

Check out this https://pub.dev/packages/barcode_scan_fix.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/leyan95/qrcode_scanner/issues/109#issuecomment-860182236, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKUCEFP65W23NOMGTNNTNNTTSR4DXANCNFSM456GQNFQ.

mmkumr commented 3 years ago

I have tried adding the scan function inside try-catch. But still, it fails. So, can you add try-catch in the function?

MerdanDev commented 3 years ago

I have tried adding the scan function inside try-catch. But still, it fails. So, can you add try-catch in the function?

Can you show your code please? Yes it is possible to add try-catch in the function.

alvinvin00 commented 3 years ago

I have tried adding the scan function inside try-catch. But still, it fails. So, can you add try-catch in the function?

try {
    //Scan QR Code
    code = await _qr.scanFromCamera();
} on TypeError {
    //Catch that pesky null thrown from library and do whatever the heck you want
}

This is what i did to deal with them

alvinvin00 commented 3 years ago

so, as of 0.3.2, problem A has been solved but problem B are still there, the soft back button wasn't removed in the latest release