Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninitialized CameraController after closing and opening the application #133

Open
petodavid opened this issue Dec 14, 2020 · 2 comments
Open

Comments

@petodavid
Copy link

E/flutter (14891): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: CameraException(Uninitialized CameraController, startImageStream was called on uninitialized CameraController.)
E/flutter (14891): #0 CameraController.startImageStream (package:camera/camera.dart:438:7)
E/flutter (14891): #1 CameraMlVisionState._start (package:flutter_camera_ml_vision/flutter_camera_ml_vision.dart:148:23)
E/flutter (14891): #2 CameraMlVisionState.build. (package:flutter_camera_ml_vision/flutter_camera_ml_vision.dart:308:11)
E/flutter (14891): #3 VisibilityDetectorLayer._fireCallback (package:flutter_widgets/src/visibility_detector/src/visibility_detector_layer.dart:268:24)
E/flutter (14891): #4 VisibilityDetectorLayer._processCallbacks (package:flutter_widgets/src/visibility_detector/src/visibility_detector_layer.dart:239:13)
E/flutter (14891): #5 _TaskEntry.run. (package:flutter/src/scheduler/binding.dart:80:34)
E/flutter (14891): #6 Timeline.timeSync (dart:developer/timeline.dart:163:22)
E/flutter (14891): #7 _TaskEntry.run (package:flutter/src/scheduler/binding.dart:77:16)
E/flutter (14891): #8 SchedulerBinding.handleEventLoopCallback (package:flutter/src/scheduler/binding.dart:460:15)
E/flutter (14891): #9 SchedulerBinding._runTasks (package:flutter/src/scheduler/binding.dart:438:9)
E/flutter (14891): #10 _rootRun (dart:async/zone.dart:1182:47)
E/flutter (14891): #11 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (14891): #12 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter (14891): #13 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1037:23)
E/flutter (14891): #14 _rootRun (dart:async/zone.dart:1190:13)
E/flutter (14891): #15 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (14891): #16 _CustomZone.bindCallback. (dart:async/zone.dart:1021:23)
E/flutter (14891): #17 Timer._createTimer. (dart:async-patch/timer_patch.dart:18:15)
E/flutter (14891): #18 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:397:19)
E/flutter (14891): #19 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:428:5)
E/flutter (14891): #20 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)
E/flutter (14891):

class FaceVision extends StatefulWidget {
  @override
  _FaceVisionState createState() => _FaceVisionState();
}

class _FaceVisionState extends State<FaceVision> {
  List<Face> _faces = [];
  final _scanKey = GlobalKey<CameraMlVisionState>();
  CameraLensDirection cameraLensDirection = CameraLensDirection.front;
  FaceDetector detector = FirebaseVision.instance.faceDetector(
    FaceDetectorOptions(
      enableTracking: true,
      mode: FaceDetectorMode.fast,
    ),
  );

  @override
  Widget build(BuildContext context) {
    return CameraMlVision<List<Face>>(
      key: _scanKey,
      resolution: ResolutionPreset.max,
      cameraLensDirection: cameraLensDirection,
      detector: detector.processImage,
      overlayBuilder: (c) {
        return CustomPaint(
          painter: FaceDetectorPainter(
              _scanKey.currentState.cameraValue.previewSize.flipped, _faces,
              reflection: cameraLensDirection == CameraLensDirection.front),
        );
      },
      onResult: (faces) {
        if (faces == null || !mounted) {
          return;
        }
        setState(() {
          _faces = faces;
        });
        sl<RecognitionBloc>()..add(NewFaces(faces: _faces));
      },
      onDispose: () {
        detector.close();
      },
    );
  }

  @override
  void dispose() {
    super.dispose();
  }
}
@petodavid
Copy link
Author

@Kleak

@nirbar89
Copy link

Hey @petodavid did you find a solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants