getCamera function

Future<CameraDescription?> getCamera(
  1. CameraLensDirection dir
)

Implementation

Future<CameraDescription?> getCamera(CameraLensDirection dir) async {
  try {
    final cameras = await availableCameras();
    if (cameras.length == 1) return cameras[0];
    return cameras.firstWhere(
      (CameraDescription camera) => camera.lensDirection == dir,
    );
  } on CameraException catch (e) {
    debugPrint(e.toString());
    return null;
  }
}