getCamera function
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;
}
}