juliuscanute / qr_code_scanner

QR Code Scanner for Flutter
BSD 2-Clause "Simplified" License
1.01k stars 799 forks source link

[BUG] Attempt to invoke virtual method 'boolean android.content.Context.isUiContext()' on a null object reference #567

Closed Sachinsowri closed 2 years ago

Sachinsowri commented 2 years ago

I Am using qr_code_scanner package in my app i am getting this error while show drwidget .

Flutter 3.0.2 qr_code_scanner : 1.0.0, device : Android 11

sample code initialQRViewWidget() { if (mounted) { setState(() { isdelaycalled = true; }); } Future.delayed(const Duration(milliseconds: 500), () { if (mounted) { setState(() { this.controller = null; this.qrViewWidget = new QRView( key: new GlobalKey(debugLabel: "QR11"), onQRViewCreated: onQRViewCreated, overlay: QrScannerOverlayShape( borderColor: Colors.greenAccent.shade700, borderRadius: 10, borderLength: 30, borderWidth: 10, cutOutSize: Global.screenSize!.height * 0.35), ); this.isdelaycalled = false; }); } }); }

void onQRViewCreated(QRViewController controller) { if (mounted) setState(() { this.controller = controller; this.controller!.scannedDataStream.first.then((scanData) { scannedCode(scanData); }); }); }

scannedCode(Barcode scanCode) { this.getItem(scanCode); }

Widget build(BuildContext context) { return Scaffold( appBar: new AppBar( title: new TitleText( text: "Scan Code", isBold: true, textcolor: Colors.white, ), backgroundColor: ServiceConstants.defaultColor), body: new Column( children: [ new Expanded( child: this.isdelaycalled || this.isScanLoad ? Center( child: new Container( child: new Icon( FontAwesomeIcons.cameraRetro, size: 50, color: Colors.blue, ), ), ) : this.qrViewWidget!, ) ], ), ); }

this error log E/MethodChannel#flutter/platform_views(14830): Failed to handle method call E/MethodChannel#flutter/platform_views(14830): java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Context.isUiContext()' on a null object reference E/MethodChannel#flutter/platform_views(14830): at android.view.ViewConfiguration.get(ViewConfiguration.java:502) E/MethodChannel#flutter/platform_views(14830): at android.view.View.(View.java:5394) E/MethodChannel#flutter/platform_views(14830): at android.view.View.(View.java:5555) E/MethodChannel#flutter/platform_views(14830): at android.view.ViewGroup.(ViewGroup.java:707) E/MethodChannel#flutter/platform_views(14830): at android.view.ViewGroup.(ViewGroup.java:703) E/MethodChannel#flutter/platform_views(14830): at android.view.ViewGroup.(ViewGroup.java:699) E/MethodChannel#flutter/platform_views(14830): at android.view.ViewGroup.(ViewGroup.java:695) E/MethodChannel#flutter/platform_views(14830): at com.journeyapps.barcodescanner.CameraPreview.(CameraPreview.java:228) E/MethodChannel#flutter/platform_views(14830): at com.journeyapps.barcodescanner.BarcodeView.(BarcodeView.java:76) E/MethodChannel#flutter/platform_views(14830): at net.touchcapture.qr.flutterqr.CustomFramingRectBarcodeView.(CustomFramingRectBarcodeView.kt:12) E/MethodChannel#flutter/platform_views(14830): at net.touchcapture.qr.flutterqr.QRView.initBarCodeView(QRView.kt:117) E/MethodChannel#flutter/platform_views(14830): at net.touchcapture.qr.flutterqr.QRView.getView(QRView.kt:70) E/MethodChannel#flutter/platform_views(14830): at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:227) E/MethodChannel#flutter/platform_views(14830): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:122) E/MethodChannel#flutter/platform_views(14830): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:60) E/MethodChannel#flutter/platform_views(14830): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) E/MethodChannel#flutter/platform_views(14830): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295) E/MethodChannel#flutter/platform_views(14830): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:319) E/MethodChannel#flutter/platform_views(14830): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12) E/MethodChannel#flutter/platform_views(14830): at android.os.Handler.handleCallback(Handler.java:938) E/MethodChannel#flutter/platform_views(14830): at android.os.Handler.dispatchMessage(Handler.java:99) E/MethodChannel#flutter/platform_views(14830): at android.os.Looper.loop(Looper.java:262) E/MethodChannel#flutter/platform_views(14830): at android.app.ActivityThread.main(ActivityThread.java:8248) E/MethodChannel#flutter/platform_views(14830): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#flutter/platform_views(14830): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612) E/MethodChannel#flutter/platform_views(14830): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:992) E/FrameEvents(14830): updateAcquireFence: Did not find frame. E/flutter (14830): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'boolean android.content.Context.isUiContext()' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Context.isUiContext()' on a null object reference E/flutter (14830): at android.view.ViewConfiguration.get(ViewConfiguration.java:502) E/flutter (14830): at android.view.View.(View.java:5394) E/flutter (14830): at android.view.View.(View.java:5555) E/flutter (14830): at android.view.ViewGroup.(ViewGroup.java:707) E/flutter (14830): at android.view.ViewGroup.(ViewGroup.java:703) E/flutter (14830): at android.view.ViewGroup.(ViewGroup.java:699) E/flutter (14830): at android.view.ViewGroup.(ViewGroup.java:695) E/flutter (14830): at com.journeyapps.barcodescanner.CameraPreview.(CameraPreview.java:228) E/flutter (14830): at com.journeyapps.barcodescanner.BarcodeView.(BarcodeView.java:76) E/flutter (14830): at net.touchcapture.qr.flutterqr.CustomFramingRectBarcodeView.(CustomFramingRectBarcodeView.kt:12) E/flutter (14830): at net.touchcapture.qr.flutterqr.QRView.initBarCodeView(QRView.kt:117) E/flutter (14830): at net.touchcapture.qr.flutterqr.QRView.getView(QRView.kt:70) E/flutter (14830): at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:227) E/flutter (14830): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:122) E/flutter (14830): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:60) E/flutter (14830): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) E/flutter (14830): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295) E/flutter (14830): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:319) E/flutter (14830): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12) E/flutter (14830): at android.os.Handler.handleCallback(Handler.java:938) E/flutter (14830): at android.os.Handler.dispatchMessage(Handler.java:99) E/flutter (14830): at android.os.Looper.loop(Looper.java:262) E/flutter (14830): at android.app.ActivityThread.main(ActivityThread.java:8248) E/flutter (14830): at java.lang.reflect.Method.invoke(Native Method) E/flutter (14830): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612) E/flutter (14830): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:992) E/flutter (14830): ) E/flutter (14830): #0 StandardMethodCodec.decodeEnvelope E/flutter (14830): #1 MethodChannel._invokeMethod E/flutter (14830): E/flutter (14830): #2 TextureAndroidViewController._sendCreateMessage E/flutter (14830): E/flutter (14830): #3 AndroidViewController.create E/flutter (14830): E/flutter (14830): #4 TextureAndroidViewController.setSize E/flutter (14830): E/flutter (14830): #5 RenderAndroidView._sizePlatformView E/flutter (14830): E/flutter (14830):

Sachinsowri commented 2 years ago

V/AutofillManager( 2994): requestHideFillUi(null): anchor = null E/MethodChannel#flutter/platform_views( 2994): Failed to handle method call E/MethodChannel#flutter/platform_views( 2994): java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Context.isUiContext()' on a null object reference E/MethodChannel#flutter/platform_views( 2994): at android.view.ViewConfiguration.get(ViewConfiguration.java:519) E/MethodChannel#flutter/platform_views( 2994): at android.view.View.(View.java:5398) E/MethodChannel#flutter/platform_views( 2994): at android.view.View.(View.java:5559) E/MethodChannel#flutter/platform_views( 2994): at android.view.ViewGroup.(ViewGroup.java:707) E/MethodChannel#flutter/platform_views( 2994): at android.view.ViewGroup.(ViewGroup.java:703) E/MethodChannel#flutter/platform_views( 2994): at android.view.ViewGroup.(ViewGroup.java:699) E/MethodChannel#flutter/platform_views( 2994): at android.view.ViewGroup.(ViewGroup.java:695) E/MethodChannel#flutter/platform_views( 2994): at com.journeyapps.barcodescanner.CameraPreview.(CameraPreview.java:228) E/MethodChannel#flutter/platform_views( 2994): at com.journeyapps.barcodescanner.BarcodeView.(BarcodeView.java:76) E/MethodChannel#flutter/platform_views( 2994): at net.touchcapture.qr.flutterqr.CustomFramingRectBarcodeView.(CustomFramingRectBarcodeView.kt:12) E/MethodChannel#flutter/platform_views( 2994): at net.touchcapture.qr.flutterqr.QRView.initBarCodeView(QRView.kt:117) E/MethodChannel#flutter/platform_views( 2994): at net.touchcapture.qr.flutterqr.QRView.getView(QRView.kt:70) E/MethodChannel#flutter/platform_views( 2994): at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:227) E/MethodChannel#flutter/platform_views( 2994): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:122) E/MethodChannel#flutter/platform_views( 2994): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:60) E/MethodChannel#flutter/platform_views( 2994): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) E/MethodChannel#flutter/platform_views( 2994): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295) E/MethodChannel#flutter/platform_views( 2994): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:319) E/MethodChannel#flutter/platform_views( 2994): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12) E/MethodChannel#flutter/platform_views( 2994): at android.os.Handler.handleCallback(Handler.java:938) E/MethodChannel#flutter/platform_views( 2994): at android.os.Handler.dispatchMessage(Handler.java:99) E/MethodChannel#flutter/platform_views( 2994): at android.os.Looper.loop(Looper.java:271) E/MethodChannel#flutter/platform_views( 2994): at android.app.ActivityThread.main(ActivityThread.java:8305) E/MethodChannel#flutter/platform_views( 2994): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#flutter/platform_views( 2994): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612) E/MethodChannel#flutter/platform_views( 2994): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:992) E/FrameEvents( 2994): updateAcquireFence: Did not find frame. E/flutter ( 2994): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'boolean android.content.Context.isUiContext()' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Context.isUiContext()' on a null object reference E/flutter ( 2994): at android.view.ViewConfiguration.get(ViewConfiguration.java:519) E/flutter ( 2994): at android.view.View.(View.java:5398) E/flutter ( 2994): at android.view.View.(View.java:5559) E/flutter ( 2994): at android.view.ViewGroup.(ViewGroup.java:707) E/flutter ( 2994): at android.view.ViewGroup.(ViewGroup.java:703) E/flutter ( 2994): at android.view.ViewGroup.(ViewGroup.java:699) E/flutter ( 2994): at android.view.ViewGroup.(ViewGroup.java:695) E/flutter ( 2994): at com.journeyapps.barcodescanner.CameraPreview.(CameraPreview.java:228) E/flutter ( 2994): at com.journeyapps.barcodescanner.BarcodeView.(BarcodeView.java:76) E/flutter ( 2994): at net.touchcapture.qr.flutterqr.CustomFramingRectBarcodeView.(CustomFramingRectBarcodeView.kt:12) E/flutter ( 2994): at net.touchcapture.qr.flutterqr.QRView.initBarCodeView(QRView.kt:117) E/flutter ( 2994): at net.touchcapture.qr.flutterqr.QRView.getView(QRView.kt:70) E/flutter ( 2994): at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:227) E/flutter ( 2994): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:122) E/flutter ( 2994): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:60) E/flutter ( 2994): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) E/flutter ( 2994): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295) E/flutter ( 2994): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:319) E/flutter ( 2994): at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12) E/flutter ( 2994): at android.os.Handler.handleCallback(Handler.java:938) E/flutter ( 2994): at android.os.Handler.dispatchMessage(Handler.java:99) E/flutter ( 2994): at android.os.Looper.loop(Looper.java:271) E/flutter ( 2994): at android.app.ActivityThread.main(ActivityThread.java:8305) E/flutter ( 2994): at java.lang.reflect.Method.invoke(Native Method) E/flutter ( 2994): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612) E/flutter ( 2994): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:992) E/flutter ( 2994): ) E/flutter ( 2994): #0 StandardMethodCodec.decodeEnvelope E/flutter ( 2994): #1 MethodChannel._invokeMethod E/flutter ( 2994): E/flutter ( 2994): #2 TextureAndroidViewController._sendCreateMessage E/flutter ( 2994): E/flutter ( 2994): #3 AndroidViewController.create E/flutter ( 2994): E/flutter ( 2994): #4 TextureAndroidViewController.setSize E/flutter ( 2994): E/flutter ( 2994): #5 RenderAndroidView._sizePlatformView E/flutter ( 2994): E/flutter ( 2994):

still i have problem

OOTPAppsDotCom commented 2 years ago

Please be more specific.

I assume you upgraded to Flutter version 3.0.4 and are still experiencing the issue?

Try to clear the cache files in your IDE, I use Android Studio and I would go to FIle > Invalidate Caches and follow the dialog. To be clear, I did not need to do anything besides "flutter upgrade" on my second development enviroment, that exhibited this error right before the upgrade, to fix this issue.

I am not 100% confident this issue won't reoccur, if it does, I will be sure to come back and add to this discussion.

OOTPAppsDotCom commented 2 years ago

@Sachinsowri can you please confirm the app has camera permissions on the device your testing your app on?

Sachinsowri commented 2 years ago

yes permission granted in Mobile,

@Sachinsowri can you please confirm the app has camera permissions on the device your testing your app on?

Sachinsowri commented 2 years ago

Please be more specific.

I assume you upgraded to Flutter version 3.0.4 and are still experiencing the issue?

Try to clear the cache files in your IDE, I use Android Studio and I would go to FIle > Invalidate Caches and follow the dialog. To be clear, I did not need to do anything besides "flutter upgrade" on my second development enviroment, that exhibited this error right before the upgrade, to fix this issue.

I am not 100% confident this issue won't reoccur, if it does, I will be sure to come back and add to this discussion.

i am using VS code . will check with android studio .

OOTPAppsDotCom commented 2 years ago

Bug's back on my end too. I uninstalled my app from the emulator and then reinstalled it, ran the qr_code_scanner and received this log:

W/Gralloc4(25771): allocator 3.x is not supported E/FrameEvents(25771): updateAcquireFence: Did not find frame. E/MethodChannel#flutter/platform_views(25771): Failed to handle method call E/MethodChannel#flutter/platform_views(25771): java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Context.isUiContext()' on a null object reference E/MethodChannel#flutter/platform_views(25771): at android.view.ViewConfiguration.get(ViewConfiguration.java:502) E/MethodChannel#flutter/platform_views(25771): at android.view.View.(View.java:5317) E/MethodChannel#flutter/platform_views(25771): at android.view.View.(View.java:5467) E/MethodChannel#flutter/platform_views(25771): at android.view.ViewGroup.(ViewGroup.java:697) E/MethodChannel#flutter/platform_views(25771): at android.view.ViewGroup.(ViewGroup.java:693) E/MethodChannel#flutter/platform_views(25771): at android.view.ViewGroup.(ViewGroup.java:689) E/MethodChannel#flutter/platform_views(25771): at android.view.ViewGroup.(ViewGroup.java:685) E/MethodChannel#flutter/platform_views(25771): at com.journeyapps.barcodescanner.CameraPreview.(CameraPreview.java:228) E/MethodChannel#flutter/platform_views(25771): at com.journeyapps.barcodescanner.BarcodeView.(BarcodeView.java:76) E/MethodChannel#flutter/platform_views(25771): at net.touchcapture.qr.flutterqr.CustomFramingRectBarcodeView.(CustomFramingRectBarcodeView.kt:12) E/MethodChannel#flutter/platform_views(25771): at net.touchcapture.qr.flutterqr.QRView.initBarCodeView(QRView.kt:117) E/MethodChannel#flutter/platform_views(25771): at net.touchcapture.qr.flutterqr.QRView.getView(QRView.kt:70) E/MethodChannel#flutter/platform_views(25771): at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:227) E/MethodChannel#flutter/platform_views(25771): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:122) E/MethodChannel#flutter/platform_views(25771): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:60) E/MethodChannel#flutter/platform_views(25771): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) E/MethodChannel#flutter/platform_views(25771): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295) E/MethodChannel#flutter/platform_views(25771): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319) E/MethodChannel#flutter/platform_views(25771): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) E/MethodChannel#flutter/platform_views(25771): at android.os.Handler.handleCallback(Handler.java:938) E/MethodChannel#flutter/platform_views(25771): at android.os.Handler.dispatchMessage(Handler.java:99) E/MethodChannel#flutter/platform_views(25771): at android.os.Looper.loop(Looper.java:223) E/MethodChannel#flutter/platform_views(25771): at android.app.ActivityThread.main(ActivityThread.java:7656) E/MethodChannel#flutter/platform_views(25771): at java.lang.reflect.Method.invoke(Native Method) E/MethodChannel#flutter/platform_views(25771): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) E/MethodChannel#flutter/platform_views(25771): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) E/flutter (25771): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'boolean android.content.Context.isUiContext()' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Context.isUiContext()' on a null object reference E/flutter (25771): at android.view.ViewConfiguration.get(ViewConfiguration.java:502) E/flutter (25771): at android.view.View.(View.java:5317) E/flutter (25771): at android.view.View.(View.java:5467) E/flutter (25771): at android.view.ViewGroup.(ViewGroup.java:697) E/flutter (25771): at android.view.ViewGroup.(ViewGroup.java:693) E/flutter (25771): at android.view.ViewGroup.(ViewGroup.java:689) E/flutter (25771): at android.view.ViewGroup.(ViewGroup.java:685) E/flutter (25771): at com.journeyapps.barcodescanner.CameraPreview.(CameraPreview.java:228) E/flutter (25771): at com.journeyapps.barcodescanner.BarcodeView.(BarcodeView.java:76) E/flutter (25771): at net.touchcapture.qr.flutterqr.CustomFramingRectBarcodeView.(CustomFramingRectBarcodeView.kt:12) E/flutter (25771): at net.touchcapture.qr.flutterqr.QRView.initBarCodeView(QRView.kt:117) E/flutter (25771): at net.touchcapture.qr.flutterqr.QRView.getView(QRView.kt:70) E/flutter (25771): at io.flutter.plugin.platform.PlatformViewsController$1.createForTextureLayer(PlatformViewsController.java:227) E/flutter (25771): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:122) E/flutter (25771): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:60) E/flutter (25771): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:262) E/flutter (25771): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295) E/flutter (25771): at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:319) E/flutter (25771): at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12) E/flutter (25771): at android.os.Handler.handleCallback(Handler.java:938) E/flutter (25771): at android.os.Handler.dispatchMessage(Handler.java:99) E/flutter (25771): at android.os.Looper.loop(Looper.java:223) E/flutter (25771): at android.app.ActivityThread.main(ActivityThread.java:7656) E/flutter (25771): at java.lang.reflect.Method.invoke(Native Method) E/flutter (25771): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592) E/flutter (25771): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947) E/flutter (25771): ) E/flutter (25771): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7) E/flutter (25771): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:167:18) E/flutter (25771): E/flutter (25771): #2 TextureAndroidViewController._sendCreateMessage (package:flutter/src/services/platform_views.dart:1134:18) E/flutter (25771): E/flutter (25771): #3 AndroidViewController.create (package:flutter/src/services/platform_views.dart:762:5) E/flutter (25771): E/flutter (25771): #4 TextureAndroidViewController.setSize (package:flutter/src/services/platform_views.dart:1062:7) E/flutter (25771): E/flutter (25771): #5 RenderAndroidView._sizePlatformView (package:flutter/src/rendering/platform_view.dart:179:29) E/flutter (25771): E/flutter (25771):

_Update: I then force-closed the app, opened the app, opened qr_codescanner and it worked as expected no errors.

Update 2: I then uninstalled and re-installed the app again, no bug occured. What could be causing this to occur only sometimes with the same environment conditions and code?

Sachinsowri commented 2 years ago

any suggestion to solve this issue

OOTPAppsDotCom commented 2 years ago

I've researched this bug and found the cause is an uninitialized Context var on the Android side, specifically within QrView.kt at line 117 we have the following code:

barcodeView = CustomFramingRectBarcodeView(QrShared.activity).also { this.barcodeView = it }

In my case, after running an Isolate to sync the app's database the value QrShared.activity is null and causes this error. If I do not run my Isolate, then QrShared.activity is not null.

This error occurs anytime after you run an Isolate and then attempt to open the QR Code Scanner, it doesn't matter if you have permissions or not, this error comes before permissions are checked.

Now, we just have to figure out why it's null, if we can't then we have to see how we can obtain a UI Context if this is null. I am trying to find where the QrShared.activity is set, this is where we can override a null and set a proper UI Context to fix this issue.

Sachinsowri commented 2 years ago

I've researched this bug and found the cause is an uninitialized Context var on the Android side, specifically within QrView.kt at line 117 we have the following code:

barcodeView = CustomFramingRectBarcodeView(QrShared.activity).also { this.barcodeView = it }

In my case, after running an Isolate to sync the app's database the value QrShared.activity is null and causes this error. If I do not run my Isolate, then QrShared.activity is not null.

This error occurs anytime after you run an Isolate and then attempt to open the QR Code Scanner, it doesn't matter if you have permissions or not, this error comes before permissions are checked.

Now, we just have to figure out why it's null, if we can't then we have to see how we can obtain a UI Context if this is null. I am trying to find where the QrShared.activity is set, this is where we can override a null and set a proper UI Context to fix this issue.

okay thanks for your valuable time to spend this conversation . can you pls fix this issue as soon as possible.

OOTPAppsDotCom commented 2 years ago

I've researched this bug and found the cause is an uninitialized Context var on the Android side, specifically within QrView.kt at line 117 we have the following code: barcodeView = CustomFramingRectBarcodeView(QrShared.activity).also { this.barcodeView = it } In my case, after running an Isolate to sync the app's database the value QrShared.activity is null and causes this error. If I do not run my Isolate, then QrShared.activity is not null. This error occurs anytime after you run an Isolate and then attempt to open the QR Code Scanner, it doesn't matter if you have permissions or not, this error comes before permissions are checked. Now, we just have to figure out why it's null, if we can't then we have to see how we can obtain a UI Context if this is null. I am trying to find where the QrShared.activity is set, this is where we can override a null and set a proper UI Context to fix this issue.

okay thanks for your valuable time to spend this conversation . can you pls fix this issue as soon as possible.

I have no experience fixing bugs in other people's libraries, I am going to see what I can do to get a valid Context here.

In your case, are you running an Isolate before this error occurs, or please explain when the error occurs for you so. It might help me understand why the Context is null in the first place.

Thaimay commented 2 years ago

For my case fix problem

QRView(
      key: qrKeyHCC,
      onQRViewCreated: _onQRViewCreated,
      overlay: QrScannerOverlayShape(
          borderColor: kRedColor,
          borderRadius: 10,
          borderLength: 30,
          borderWidth: 10,
          cutOutSize: 300),
      onPermissionSet: (ctrl, p) => _onPermissionSet(ctrl, p),
    );

void _onPermissionSet(QRViewController ctrl, bool p) {
    if (!p) {
      showErrorMessage(MSG_CAN_NOT_USE_CAMERA);
    }
    ctrl.resumeCamera();   <---- This fix
  }
Sachinsowri commented 2 years ago

i my app i have barcode scan option when open scan view . initialQRViewWidget called in inistate . no other function called. if permission not gives it worked after allow camera permission . if permission already allowed . i got that error all time

Sachinsowri commented 2 years ago

initialQRViewWidget() { if (mounted) { setState(() { isdelaycalled = true; }); } Future.delayed(const Duration(milliseconds: 500), () { if (mounted) { setState(() { this.controller = null; this.qrViewWidget = new QRView( key: new GlobalKey(debugLabel: "QR11"), onQRViewCreated: onQRViewCreated, overlay: QrScannerOverlayShape( borderColor: Colors.greenAccent.shade700, borderRadius: 10, borderLength: 30, borderWidth: 10, cutOutSize: Global.screenSize!.height * 0.35), ); this.isdelaycalled = false; }); } }); }

void onQRViewCreated(QRViewController controller) { if (mounted) setState(() { this.controller = controller; this.controller!.scannedDataStream.first.then((scanData) { scannedCode(scanData); }); }); }

scannedCode(Barcode scanCode) { this.getItem(scanCode); }

Widget build(BuildContext context) { return Scaffold( appBar: new AppBar( title: new TitleText( text: "Scan Code", isBold: true, textcolor: Colors.white, ), backgroundColor: ServiceConstants.defaultColor), body: new Column( children: [ new Expanded( child: this.isdelaycalled || this.isScanLoad ? Center( child: new Container( child: new Icon( FontAwesomeIcons.cameraRetro, size: 50, color: Colors.blue, ), ), ) : this.qrViewWidget!, ) ], ), ); }

need to change any thing in my sample code

OOTPAppsDotCom commented 2 years ago

For my case fix problem

QRView(
      key: qrKeyHCC,
      onQRViewCreated: _onQRViewCreated,
      overlay: QrScannerOverlayShape(
          borderColor: kRedColor,
          borderRadius: 10,
          borderLength: 30,
          borderWidth: 10,
          cutOutSize: 300),
      onPermissionSet: (ctrl, p) => _onPermissionSet(ctrl, p),
    );

void _onPermissionSet(QRViewController ctrl, bool p) {
    if (!p) {
      showErrorMessage(MSG_CAN_NOT_USE_CAMERA);
    }
    ctrl.resumeCamera();   <---- This fix
  }

Unfortunately that has no effect on this error, are you sure you posted in the correct post?

OOTPAppsDotCom commented 2 years ago

@Sachinsowri I have found the fix, I have no experience in implementing said fix, but if someone would like to help me make my first contribution I would be thrilled to do such. I have commented on the commit itself that broke the plugin, @ the author, so I hope it gets fixed soon.

I reviewed the latest commits and I found an anomoly in a refactoring done. I noticed logic was added to the onDetachedFromEngine() method to nullify QrShared.activity and QrShared.binding, but a refactor shouldn't change state and this changed state.

I noticed that the plugin expects to bind to the engine once, so if any other plugins cause this plugin to detach, the plugin will not initialize correctly the second time. By removing the nulls the engine attachment is essentially immutable from detachments and it works as expected.

The fix for now is to nullify rows 20 and 21 of FlutterQrPlugin.kt such as:

override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
        //QrShared.activity = null
        //QrShared.binding = null
    }
OOTPAppsDotCom commented 2 years ago

I created a fork for this issue, you can find it/use it in your pubspec.yaml by using the following code:

qr_code_scanner:
    git:
      url: https://github.com/OOTPAppsDotCom/qr_code_scanner.git
Sachinsowri commented 2 years ago

I created a fork for this issue, you can find it/use it in your pubspec.yaml by using the following code:

qr_code_scanner:
    git:
      url: https://github.com/OOTPAppsDotCom/qr_code_scanner.git

thanks it works

OOTPAppsDotCom commented 2 years ago

I created a fork for this issue, you can find it/use it in your pubspec.yaml by using the following code:

qr_code_scanner:
    git:
      url: https://github.com/OOTPAppsDotCom/qr_code_scanner.git

thanks it works

You're welcome, my first public library fix! You should update this bug thread to include the Fork I made above.

juliansteenbakker commented 2 years ago

Thank you all for reporting and finding a fix. I have published version 1.0.1 which includes this fix.

SmilingFarood commented 8 months ago

Thank you all for reporting and finding a fix. I have published version 1.0.1 which includes this fix. Hello @juliansteenbakker, I have a similar error on my project but its not a qr code scanning project. I am trying to build a project for a POS terminal using Flutter and I have the terminal SDK which is primarily used in Kotlin. I want to write my functions in Kotlin to access the POS printer and I get this error when I try to print on the device E/flutter ( 8544): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, Attempt to invoke virtual method 'boolean android.content.Context.isUiContext()' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.content.Context.isUiContext()' on a null object reference E/flutter ( 8544): at android.view.ViewConfiguration.get(ViewConfiguration.java:502)