Apparence-io / CamerAwesome

📸 Embedding a camera experience within your own app shouldn't be that hard. A flutter plugin to integrate awesome Android / iOS camera experience.
https://ApparenceKit.dev
MIT License
976 stars 256 forks source link

[CRASH] Error While Navigation to another route with hero and camera #24

Closed shekohex closed 4 years ago

shekohex commented 4 years ago

Awsome Plugin 😄 , I just switched from the official camera plugin in my app to try this plugin, but ... there is an Issue:

Steps to Reproduce

I have a custom gallery UI and the first item in it is a small camera when the user clicks on it, switches to a full view with the camera (also custom UI) Here is a screenshot of the UI:

image

When I click on the camera (the first item) it switches to another route with Hero animation but it throws a lot of errors and event when I get back it crashes the app here is a log:

View Log

```dart [GETX] GOING TO ROUTE /camera [GETX] "CameraController" has been initialized D/com.apparence.camerawesome.CamerawesomePlugin( 3672): _handleCheckPermissions: E/libc ( 3672): Access denied finding property "vendor.camera.aux.packagelist" W/chat.owl.app( 3672): type=1400 audit(0.0:275089): avc: denied { read } for name="u:object_r:persist_camera_prop:s0" dev="tmpfs" ino=19220 scontext=u:r:untrusted_app:s0:c233,c256,c512,c768 tcontext=u:object_r:persist_camera_prop:s0 tclass=file permissive=0 D/com.apparence.camerawesome.CamerawesomePlugin( 3672): _handleCheckPermissions: E/flutter ( 3672): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: A ValueNotifier was used after being disposed. E/flutter ( 3672): Once you have called dispose() on a ValueNotifier, it can no longer be used. E/flutter ( 3672): #0 ChangeNotifier._debugAssertNotDisposed. (package:flutter/src/foundation/change_notifier.dart:117:9) E/flutter ( 3672): #1 ChangeNotifier._debugAssertNotDisposed (package:flutter/src/foundation/change_notifier.dart:123:6) E/flutter ( 3672): #2 ChangeNotifier.addListener (package:flutter/src/foundation/change_notifier.dart:153:12) E/flutter ( 3672): #3 _CameraAwesomeState._initAndroidPhotoSize (package:camerawesome/camerapreview.dart:248:30) E/flutter ( 3672): #4 _CameraAwesomeState.initPlatformState (package:camerawesome/camerapreview.dart:160:5) E/flutter ( 3672): E/flutter ( 3672): #5 _CameraAwesomeState.initState (package:camerawesome/camerapreview.dart:121:5) E/flutter ( 3672): #6 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4765:58) E/flutter ( 3672): #7 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5) E/flutter ( 3672): #8 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter ( 3672): #9 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18) E/flutter ( 3672): #10 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16) E/flutter ( 3672): #11 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11) E/flutter ( 3672): #12 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) E/flutter ( 3672): #13 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5) E/flutter ( 3672): #14 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4791:11) E/flutter ( 3672): #15 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5) E/flutter ( 3672): #16 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter ( 3672): #17 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18) E/flutter ( 3672): #18 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6118:14) E/flutter ( 3672): #19 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter ( 3672): #20 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6236:32) E/flutter ( 3672): #21 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter ( 3672): #22 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18) E/flutter ( 3672): #23 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16) E/flutter ( 3672): #24 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) E/flutter ( 3672): #25 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5) E/flutter ( 3672): #26 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5) E/flutter ( 3672): #27 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter ( 3672): #28 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18) E/flutter ( 3672): #29 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16) E/flutter ( 3672): #30 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) E/flutter ( 3672): #31 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5) E/flutter ( 3672): #32 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5) E/flutter ( 3672): #33 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter ( 3672): #34 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18) E/flutter ( 3672): #35 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16) E/flutter ( 3672): #36 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) E/flutter ( 3672): #37 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5) E/flutter ( 3672): #38 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5) E/flutter ( 3672): #39 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter ( 3672): #40 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18) E/flutter ( 3672): #41 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16) E/flutter ( 3672): #42 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) E/flutter ( 3672): #43 ComponentElement._firstBuild (package:flutter/src/widgets/framewo W/chat.owl.app( 3672): type=1400 audit(0.0:275092): avc: denied { read } for name="u:object_r:persist_camera_prop:s0" dev="tmpfs" ino=19220 scontext=u:r:untrusted_app:s0:c233,c256,c512,c768 tcontext=u:object_r:persist_camera_prop:s0 tclass=file permissive=0 E/libc ( 3672): Access denied finding property "vendor.camera.aux.packagelist" D/com.apparence.camerawesome.CamerawesomePlugin( 3672): _handleCheckPermissions: E/flutter ( 3672): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: A ValueNotifier was used after being disposed. E/flutter ( 3672): Once you have called dispose() on a ValueNotifier, it can no longer be used. E/flutter ( 3672): #0 ChangeNotifier._debugAssertNotDisposed. (package:flutter/src/foundation/change_notifier.dart:117:9) E/flutter ( 3672): #1 ChangeNotifier._debugAssertNotDisposed (package:flutter/src/foundation/change_notifier.dart:123:6) E/flutter ( 3672): #2 ChangeNotifier.addListener (package:flutter/src/foundation/change_notifier.dart:153:12) E/flutter ( 3672): #3 _CameraAwesomeState._initAndroidPhotoSize (package:camerawesome/camerapreview.dart:248:30) E/flutter ( 3672): #4 _CameraAwesomeState.initPlatformState (package:camerawesome/camerapreview.dart:160:5) E/flutter ( 3672): E/flutter ( 3672): #5 _CameraAwesomeState.initState (package:camerawesome/camerapreview.dart:121:5) E/flutter ( 3672): #6 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4765:58) E/flutter ( 3672): #7 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5) E/flutter ( 3672): #8 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter ( 3672): #9 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18) E/flutter ( 3672): #10 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16) E/flutter ( 3672): #11 StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:4800:11) E/flutter ( 3672): #12 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) E/flutter ( 3672): #13 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5) E/flutter ( 3672): #14 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:4791:11) E/flutter ( 3672): #15 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5) E/flutter ( 3672): #16 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter ( 3672): #17 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18) E/flutter ( 3672): #18 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6118:14) E/flutter ( 3672): #19 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter ( 3672): #20 MultiChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:6236:32) E/flutter ( 3672): #21 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter ( 3672): #22 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18) E/flutter ( 3672): #23 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16) E/flutter ( 3672): #24 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) E/flutter ( 3672): #25 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5) E/flutter ( 3672): #26 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5) E/flutter ( 3672): #27 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter ( 3672): #28 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18) E/flutter ( 3672): #29 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16) E/flutter ( 3672): #30 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) E/flutter ( 3672): #31 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5) E/flutter ( 3672): #32 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5) E/flutter ( 3672): #33 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter ( 3672): #34 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18) E/flutter ( 3672): #35 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16) E/flutter ( 3672): #36 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) E/flutter ( 3672): #37 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:4606:5) E/flutter ( 3672): #38 ComponentElement.mount (package:flutter/src/widgets/framework.dart:4601:5) E/flutter ( 3672): #39 Element.inflateWidget (package:flutter/src/widgets/framework.dart:3569:14) E/flutter ( 3672): #40 Element.updateChild (package:flutter/src/widgets/framework.dart:3327:18) E/flutter ( 3672): #41 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:4652:16) E/flutter ( 3672): #42 Element.rebuild (package:flutter/src/widgets/framework.dart:4343:5) E/flutter ( 3672): #43 ComponentElement._firstBuild (package:flutter/src/widgets/framewo W/chat.owl.app( 3672): type=1400 audit(0.0:275093): avc: denied { read } for name="u:object_r:persist_camera_prop:s0" dev="tmpfs" ino=19220 scontext=u:r:untrusted_app:s0:c233,c256,c512,c768 tcontext=u:object_r:persist_camera_prop:s0 tclass=file permissive=0 E/libc ( 3672): Access denied finding property "vendor.camera.aux.packagelist" E/libc ( 3672): Access denied finding property "persist.vendor.camera.privapp.list" W/chat.owl.app( 3672): type=1400 audit(0.0:275094): avc: denied { read } for name="u:object_r:persist_camera_prop:s0" dev="tmpfs" ino=19220 scontext=u:r:untrusted_app:s0:c233,c256,c512,c768 tcontext=u:object_r:persist_camera_prop:s0 tclass=file permissive=0 E/libc ( 3672): Access denied finding property "vendor.camera.aux.packagelist" W/Binder:3672_6( 3672): type=1400 audit(0.0:275097): avc: denied { read } for name="u:object_r:persist_camera_prop:s0" dev="tmpfs" ino=19220 scontext=u:r:untrusted_app:s0:c233,c256,c512,c768 tcontext=u:object_r:persist_camera_prop:s0 tclass=file permissive=0 [GETX] CLOSE TO ROUTE /camera D/com.apparence.camerawesome.CamerawesomePlugin( 3672): _handleCheckPermissions: E/com.apparence.camerawesome.CameraStateManager( 3672): close camera session: failed E/libc ( 3672): Access denied finding property "vendor.camera.aux.packagelist" E/libc ( 3672): Access denied finding property "vendor.camera.aux.packagelist" D/com.apparence.camerawesome.CamerawesomePlugin( 3672): _handleCheckPermissions: [GETX] "CameraController" onClose() called [GETX] "CameraController" deleted from memory E/flutter ( 3672): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: A ValueNotifier was used after being disposed. E/flutter ( 3672): Once you have called dispose() on a ValueNotifier, it can no longer be used. E/flutter ( 3672): #0 ChangeNotifier._debugAssertNotDisposed. (package:flutter/src/foundation/change_notifier.dart:117:9) E/flutter ( 3672): #1 ChangeNotifier._debugAssertNotDisposed (package:flutter/src/foundation/change_notifier.dart:123:6) E/flutter ( 3672): #2 ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:217:12) E/flutter ( 3672): #3 ValueNotifier.value= (package:flutter/src/foundation/change_notifier.dart:292:5) E/flutter ( 3672): #4 _CameraAwesomeState._initPhotoSize. (package:camerawesome/camerapreview.dart:264:32) E/flutter ( 3672): #5 ChangeNotifier.notifyListeners (package:flutter/src/foundation/change_notifier.dart:226:25) E/flutter ( 3672): #6 ValueNotifier.value= (package:flutter/src/foundation/change_notifier.dart:292:5) E/flutter ( 3672): #7 _CameraAwesomeState.initPlatformState (package:camerawesome/camerapreview.dart:164:24) E/flutter ( 3672): #8 _rootRunUnary (dart:async/zone.dart:1198:47) E/flutter ( 3672): #9 _CustomZone.runUnary (dart:async/zone.dart:1100:19) E/flutter ( 3672): #10 _FutureListener.handleValue (dart:async/future_impl.dart:143:18) E/flutter ( 3672): #11 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45) E/flutter ( 3672): #12 Future._propagateToListeners (dart:async/future_impl.dart:725:32) E/flutter ( 3672): #13 Future._completeWithValue (dart:async/future_impl.dart:529:5) E/flutter ( 3672): #14 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15) E/flutter ( 3672): #15 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13) E/flutter ( 3672): #16 CamerawesomePlugin.getSizes (package:camerawesome/camerawesome_plugin.dart) E/flutter ( 3672): #17 _rootRunUnary (dart:async/zone.dart:1198:47) E/flutter ( 3672): #18 _CustomZone.runUnary (dart:async/zone.dart:1100:19) E/flutter ( 3672): #19 _FutureListener.handleValue (dart:async/future_impl.dart:143:18) E/flutter ( 3672): #20 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45) E/flutter ( 3672): #21 Future._propagateToListeners (dart:async/future_impl.dart:725:32) E/flutter ( 3672): #22 Future._completeWithValue (dart:async/future_impl.dart:529:5) E/flutter ( 3672): #23 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:40:15) E/flutter ( 3672): #24 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:311:13) E/flutter ( 3672): #25 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart) E/flutter ( 3672): #26 _rootRunUnary (dart:async/zone.dart:1198:47) E/flutter ( 3672): #27 _CustomZone.runUnary (dart:async/zone.dart:1100:19) E/flutter ( 3672): #28 _FutureListener.handleValue (dart:async/future_impl.dart:143:18) E/flutter ( 3672): #29 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:696:45) E/flutter ( 3672): #30 Future._propagateToListeners (dart:async/future_impl.dart:725:32) E/flutter ( 3672): #31 Future._completeWithValue (dart:async/future_impl.dart:529:5) E/flutter ( 3672): #32 Future._asyncCompleteWithValue. (dart:async/future_impl.dart:567:7) E/flutter ( 3672): #33 _rootRun (dart:async/zone.dart:1190:13) E/flutter ( 3672): #34 _CustomZone.run (dart:async/zone.dart:1093:19) E/flutter ( 3672): #35 _CustomZone.runGuarded (dart:async/zone.dart:997:7) E/flutter ( 3672): #36 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1037:23) E/flutter ( 3672): #37 _microtaskLoop (dart:async/schedule_microtask.dart:41:21) E/flutter ( 3672): #38 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5) E/flutter ( 3672): E/libc ( 3672): Access denied finding property "persist.vendor.camera.privapp.list" E/libc ( 3672): Access denied finding property "vendor.camera.aux.packagelist" E/libc ( 3672): Access denied finding property "vendor.camera.aux.packagelist" D/AndroidRuntime( 3672): Shutting down VM E/AndroidRuntime( 3672): FATAL EXCEPTION: main E/AndroidRuntime( 3672): Process: chat.owl.app, PID: 3672 E/AndroidRuntime( 3672): java.lang.NullPointerException: Attempt to invoke virtual method 'int android.util.Size.getWidth()' on a null object reference E/AndroidRuntime( 3672): at com.apparence.camerawesome.CameraPicture.refresh(CameraPicture.java:74) E/AndroidRuntime( 3672): at com.apparence.camerawesome.CameraStateManager.onOpened(CameraStateManager.java:133) E/AndroidRuntime( 3672): at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:151) E/AndroidRuntime( 3672): at android.os.Handler.handleCallback(Handler.java:883) E/AndroidRuntime( 3672): at android.os.Handler.dispatchMessage(Handler.java:100) E/AndroidRuntime( 3672): at android.os.Looper.loop(Looper.java:214) E/AndroidRuntime( 3672): at android.app.ActivityThread.main(ActivityThread.java:7397) E/AndroidRuntime( 3672): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime( 3672): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) E/AndroidRuntime( 3672): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:935) I/Process ( 3672): Sending signal. PID: 3672 SIG: 9 Lost connection to device. Failed to send request: {"jsonrpc":"2.0","id":"126","method":"resume","params":{"isolateId":"isolates/764243394252463"}} ```

And here is how I use it:

in the gallery view:

...
Hero(
  tag: 'camera',
  child: GestureDetector(
    onTap: () async {
      final result = await Get.toNamed(Routes.camera);
      if (result != null) {
        // ...
      }
    },
    child: Stack(
      alignment: Alignment.center,
      children: [
        CameraAwesome(
          testMode: false,
          sensor: controller.sensor,
          selectDefaultSize: (List<Size> availableSizes) =>
              availableSizes.first ?? Size(1920, 1080),
          onCameraStarted: () {},
          photoSize: ValueNotifier(null),
          switchFlashMode: controller.flash,
          fitted: false,
          orientation: DeviceOrientation.portraitUp,
        ),
        const Icon(
          Icons.camera_alt,
          color: Colors.white,
          size: 42,
        ),
      ],
    ),
  ),
)
...

in the Camera View

...
CameraAwesome(
  testMode: false,
  sensor: controller.sensor,
  selectDefaultSize: (List<Size> availableSizes) =>
      availableSizes.first ?? Size(1920, 1080),
  onCameraStarted: () {},
  photoSize: controller.picSize,
  switchFlashMode: controller.flash,
  fitted: false,
  orientation: DeviceOrientation.portraitUp,
)
...

btw, the controller here is a normal class that holds the state and the ValueNotifiers and only got disposed/deleted when the controller is fully removed from the screen and in my case, the Galler Controller is not removed, it just got overlayed with another route (The Camera View).

Expected results

Switching between routes should work with any issues when there is a camera in it.

Actual results

App Crash!

About your device

Brand Model OS
Xiaomi Mi A3 Android 10
shekohex commented 4 years ago

I guess here should add a default size if it is null? https://github.com/Apparence-io/camera_awesome/blob/9dd9219543a8491d9a5e3e9b1cea406a98ad0d10/android/src/main/java/com/apparence/camerawesome/CameraPicture.java#L74

g-apparence commented 4 years ago

This seems to be a permission problem here. you got this in your error message

[GETX] GOING TO ROUTE /camera
[GETX] "CameraController" has been initialized
D/com.apparence.camerawesome.CamerawesomePlugin( 3672): _handleCheckPermissions: 
E/libc    ( 3672): **Access denied finding property "vendor.camera.aux.packagelist"**
W/chat.owl.app( 3672): type=1400 audit(0.0:275089): avc: denied { read } for name="u:object_r:persist_camera_prop:s0" dev="tmpfs" ino=19220 scontext=u:r:untrusted_app:s0:c233,c256,c512,c768 tcontext=u:object_r:persist_camera_prop:s0 tclass=file permissive=0
D/com.apparence.camerawesome.CamerawesomePlugin( 3672): _handleCheckPermissions:

Please verify you've added the permissions in your android manifest.

I guess here should add a default size if it is null? No you have to put an imageSize in the cameraView then it can't be null.

Also i note in your code:

let me know if this fix your error.

shekohex commented 4 years ago

Now, I don't know why it dispose the ValueNotifier<Size> the selectedAndroidPhotoSize and then reuses it? this time I'm trying on Android Emulator (Android 10). Here is the log:

[GETX] GOING TO ROUTE /camera
[GETX] "CameraController" has been initialized
D/com.apparence.camerawesome.CamerawesomePlugin(20676): _handleCheckPermissions:
D/com.apparence.camerawesome.CamerawesomePlugin(20676): _handleCheckPermissions:
E/flutter (20676): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: A ValueNotifier<Size> was used after being disposed.
E/flutter (20676): Once you have called dispose() on a ValueNotifier<Size>, it can no longer be used.
E/flutter (20676): #0      ChangeNotifier._debugAssertNotDisposed.<anonymous closure>
 package:flutter/…/foundation/change_notifier.dart
E/flutter (20676): #1      ChangeNotifier._debugAssertNotDisposed
 package:flutter/…/foundation/change_notifier.dart
E/flutter (20676): #2      ChangeNotifier.notifyListeners
 package:flutter/…/foundation/change_notifier.dart
E/flutter (20676): #3      ValueNotifier.value=
 package:flutter/…/foundation/change_notifier.dart
E/flutter (20676): #4      _CameraAwesomeState._initPhotoSize.<anonymous closure>
 package:camerawesome/camerapreview.dart
E/flutter (20676): #5      ChangeNotifier.notifyListeners
 package:flutter/…/foundation/change_notifier.dart
E/flutter (20676): #6      ValueNotifier.value=
 package:flutter/…/foundation/change_notifier.dart
E/flutter (20676): #7      _CameraAwesomeState.initPlatformState
 package:camerawesome/camerapreview.dart
E/flutter (20676): <asynchronous suspension>
E/flutter (20676): #8      _CameraAwesomeState.initState
 package:camerawesome/camerapreview.dart
E/flutter (20676): #9      StatefulElement._firstBuild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #10     ComponentElement.mount
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #11     Element.inflateWidget
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #12     Element.updateChild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #13     ComponentElement.performRebuild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #14     StatefulElement.performRebuild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #15     Element.rebuild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #16     ComponentElement._firstBuild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #17     StatefulElement._firstBuild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #18     ComponentElement.mount
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #19     Element.inflateWidget
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #20     Element.updateChild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #21     SingleChildRenderObjectElement.mount
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #22     Element.inflateWidget
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #23     MultiChildRenderObjectElement.mount
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #24     Element.inflateWidget
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #25     Element.updateChild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #26     ComponentElement.performRebuild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #27     Element.rebuild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #28     ComponentElement._firstBuild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #29     ComponentElement.mount
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #30     Element.inflateWidget
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #31     Element.updateChild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #32     ComponentElement.performRebuild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #33     Element.rebuild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #34     ComponentElement._firstBuild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #35     ComponentElement.mount
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #36     Element.inflateWidget
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #37     Element.updateChild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #38     ComponentElement.performRebuild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #39     Element.rebuild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #40     ComponentElement._firstBuild
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #41     ComponentElement.mount
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #42     Element.inflateWidget
 package:flutter/…/widgets/framework.dart
E/flutter (20676): #43     Element.updateChild
D/AndroidRuntime(20676): Shutting down VM
E/AndroidRuntime(20676): FATAL EXCEPTION: main
E/AndroidRuntime(20676): Process: chat.owl.app, PID: 20676
E/AndroidRuntime(20676): java.lang.NullPointerException: Attempt to invoke virtual method 'int android.util.Size.getWidth()' on a null object reference
E/AndroidRuntime(20676):    at com.apparence.camerawesome.CameraPicture.refresh(CameraPicture.java:74)
E/AndroidRuntime(20676):    at com.apparence.camerawesome.CameraStateManager.onOpened(CameraStateManager.java:133)
E/AndroidRuntime(20676):    at android.hardware.camera2.impl.CameraDeviceImpl$1.run(CameraDeviceImpl.java:145)
E/AndroidRuntime(20676):    at android.os.Handler.handleCallback(Handler.java:883)
E/AndroidRuntime(20676):    at android.os.Handler.dispatchMessage(Handler.java:100)
E/AndroidRuntime(20676):    at android.os.Looper.loop(Looper.java:214)
E/AndroidRuntime(20676):    at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AndroidRuntime(20676):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(20676):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime(20676):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/Process (20676): Sending signal. PID: 20676 SIG: 9
Lost connection to device.
Exited (sigterm)

I will try to make a minimal repo to reproduce the issue.

shekohex commented 4 years ago

I made a simple repo with only the code needed to reproduce that issue here https://github.com/shekohex/camera_awesome_hero_issue

also added the steps to the README along with the log.

Please note that with the official camera plugin I haven't faced this issue because every camera preview uses a separate controller and it worked when I switch between routes with no problem. I'm sure that A ValueNotifier<Size> was used after being disposed. is the root of this issue.

Thanks :)

g-apparence commented 4 years ago

Tryed without the hero animations and it works. As the initiation takes time the hero animation seems to dispose our widget before it finished to init. That's the reason of this bug. I search how to fix this.

g-apparence commented 4 years ago

I made it work but I think it's not the best experience. Using a on each CameraPreview

var globalCameraKey = GlobalKey();

But the Hero animation will result in a point because it stop the camera and the preview will be just empty.

The thing is :

Here's how I would implement it :

This will makes hero animation fixed on last frame the device has seen. That's for me the best experience you can build.

But this show that there is a bad experience on our widget build / dispose. We have something to do so, i'll let this open. I have some ideas to improve it.

shekohex commented 4 years ago

in the meantime, I will just disable the hero animation for this tile, it is okay for now.

I noticed another issue where the image gets rotated after being saved, the problem is when I put the image in the Image widget. I will probably open another issue for this to be separate.

g-apparence commented 4 years ago

You can make a try on this branch. This makes camera rebuild much more clean. But still to get a real hero animation you must take a picture before as we stop the camera right at the dispose time on the cameraPreview widget. Hero animation force the first widget to dispose then rebuild and build the resulting widget. (so it ask multiple times to start the camera...). Anyway I believe this helped to make camera way more stable.