Skip to content

Commit

Permalink
fix: Camera not activating directly (#1125)
Browse files Browse the repository at this point in the history
* fix: Camera not activating directly

* Update ml_kit_scan_page.dart

* Update ml_kit_scan_page.dart

* Update ml_kit_scan_page.dart
  • Loading branch information
M123-dev authored Feb 13, 2022
1 parent 4e62659 commit 4ef945a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/smooth_app/lib/pages/scan/ml_kit_scan_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -129,32 +129,36 @@ class MLKitScannerPageState extends State<MLKitScannerPage> {
_controller?.setFocusMode(FocusMode.auto);
_controller?.lockCaptureOrientation(DeviceOrientation.portraitUp);

_controller = _controller;

try {
await _controller!.initialize();
// If the controller is initialized update the UI.
_controller?.addListener(() {
if (mounted) {
setState(() {});
}
if (_controller!.value.hasError) {
// TODO(M123): Handle errors better
debugPrint(_controller!.value.errorDescription);
}
});

try {
await _controller?.initialize();
_controller?.startImageStream(_processCameraImage);
} on CameraException catch (e) {
if (kDebugMode) {
// TODO(M123): Show error message
debugPrint(e.toString());
}
}

if (mounted) {
setState(() {});
}
}

Future<void> _stopImageStream() async {
stoppingCamera = true;
setState(() {});
if (mounted) {
setState(() {});
}
await _controller?.dispose();
_controller = null;
}
Expand Down

0 comments on commit 4ef945a

Please sign in to comment.