mirror of
https://github.com/openfoodfacts/smooth-app.git
synced 2025-08-26 03:01:45 +08:00
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:
@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user