Skip to content

Commit

Permalink
Merge pull request #13 from LeBzul/feature/refacto
Browse files Browse the repository at this point in the history
fix du crash si on pas un iOS ou android
  • Loading branch information
LeBzul authored Jul 20, 2023
2 parents 914d1a6 + cf26fd2 commit 5aaf72b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lib/ocr_scan/widget/live_scan_widget.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:async';
import 'dart:io';

import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -50,10 +51,14 @@ class LiveScanWidgetState extends ScanWidgetState<LiveScanWidget> {
final CameraController? cameraController = _controller;
cameraController?.lockCaptureOrientation(DeviceOrientation.portraitUp);

final size = MediaQuery.of(context).size;
if (cameraController == null || !cameraController.value.isInitialized) {
return Container();
return Container(
width: size.width,
height: size.height,
color: Colors.black,
);
} else {
final size = MediaQuery.of(context).size;
CustomPaint? customPaint = this.customPaint;

/// Preview de la camera
Expand Down Expand Up @@ -139,6 +144,9 @@ class LiveScanWidgetState extends ScanWidgetState<LiveScanWidget> {

/// Demarrage de la camera
Future _startCamera() async {
if (!Platform.isAndroid && !Platform.isIOS) {
return;
}
_cameras = await availableCameras();
_controller = CameraController(_cameras[0], ResolutionPreset.max);
final camera = _cameras[0];
Expand Down Expand Up @@ -167,6 +175,9 @@ class LiveScanWidgetState extends ScanWidgetState<LiveScanWidget> {

/// Arret de la camera
Future _stopCamera() async {
if (!Platform.isAndroid && !Platform.isIOS) {
return;
}
await _controller?.stopImageStream();
await _controller?.dispose();
_controller = null;
Expand Down

0 comments on commit 5aaf72b

Please sign in to comment.