Skip to content

Commit

Permalink
🚸 Switching between different lens with single camera by default
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 committed Aug 21, 2024
1 parent 4a9ff4e commit 61ae1f7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
16 changes: 12 additions & 4 deletions lib/src/states/camera_picker_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'dart:math' as math;

import 'package:camera/camera.dart';
import 'package:camera_platform_interface/camera_platform_interface.dart';
import 'package:collection/collection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -605,10 +606,17 @@ class CameraPickerState extends State<CameraPicker>
if (controller.value.isTakingPicture || controller.value.isRecordingVideo) {
return;
}
++currentCameraIndex;
if (currentCameraIndex == cameras.length) {
currentCameraIndex = 0;
}
final preferredCameras = CameraLensDirection.values
.map((e) => cameras.firstWhereOrNull((c) => c.lensDirection == e))
.whereType<CameraDescription>()
.map((e) => cameras.indexOf(e))
.toList();
int index = preferredCameras.indexOf(currentCameraIndex);
++index;
if (index == preferredCameras.length) {
index = 0;
}
currentCameraIndex = preferredCameras[index];
initCameras(cameraDescription: currentCamera);
}

Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies:
camera_android: '>=0.10.0 <0.10.9+4'
camera_platform_interface: ^2.1.5

collection: '>=1.18.0 <2.0.0'
path: ^1.8.0
photo_manager: ^3.0.0
photo_manager_image_provider: ^2.0.0
Expand Down

0 comments on commit 61ae1f7

Please sign in to comment.