feat: Camera controller as a singleton (#1873)

* Improvements about resuming the camera

* Remove unused print call

* Singleton for the CameraController
This commit is contained in:
Edouard Marquez
2022-05-17 19:55:23 +02:00
committed by GitHub
parent 12b493379a
commit 195f9db6a4
5 changed files with 199 additions and 66 deletions

View File

@ -1,10 +1,15 @@
import 'package:camera/camera.dart';
import 'package:smooth_app/pages/scan/camera_controller.dart';
class CameraHelper {
const CameraHelper._();
static List<CameraDescription>? _cameras;
/// Ensure we have a single instance of this controller
/// /!\ Lazy-loaded
static SmoothCameraController? _controller;
/// Mandatory method to call before [findBestCamera]
static Future<void> init() async {
_cameras = await availableCameras();
@ -48,4 +53,12 @@ class CameraHelper {
return _cameras![cameraIndex];
}
/// Init the controller
/// And prevents the redefinition of it
static void initController(SmoothCameraController controller) {
_controller ??= controller;
}
static SmoothCameraController? get controller => _controller;
}