Skip to content

Commit

Permalink
chore: minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-alcides committed Oct 11, 2024
1 parent 6ff2a55 commit ac838fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
23 changes: 12 additions & 11 deletions lib/app/features/gallery/providers/camera_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,22 @@ class CameraControllerNotifier extends _$CameraControllerNotifier {
_cameraController = CameraController(
camera,
ResolutionPreset.high,
enableAudio: false,
);

try {
await _cameraController?.initialize();
_cameraController?.addListener(ref.notifyListeners);
return _cameraController;
} catch (e) {
Logger.log('Error initializing camera: $e');
Logger.log('Camera initialization error: $e');

_cameraController?.removeListener(ref.notifyListeners);
await _cameraController?.dispose();
_cameraController = null;
return null;
}
}

Future<bool> handlePermissionChange({required bool hasPermission}) async {
if (hasPermission) {
return resumeCamera();
} else {
await pauseCamera();
return false;
}
}

Future<void> pauseCamera() async {
if (_cameraController != null) {
_cameraController?.removeListener(ref.notifyListeners);
Expand All @@ -103,6 +95,15 @@ class CameraControllerNotifier extends _$CameraControllerNotifier {
return state.value != null;
}

Future<bool> handlePermissionChange({required bool hasPermission}) async {
if (hasPermission) {
return resumeCamera();
} else {
await pauseCamera();
return false;
}
}

Future<void> switchCamera() async {
if (_cameraController == null) return;

Expand Down
6 changes: 2 additions & 4 deletions lib/app/services/media_service/media_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class MediaService {
Future<MediaFile?> _saveCameraVideo(File videoFile) async {
final asset = await PhotoManager.editor.saveVideo(
videoFile,
title: 'Camera_${DateTime.now().millisecondsSinceEpoch}.mp4',
title: 'Camera_${DateTime.now().millisecondsSinceEpoch}',
);

if (asset == null) return null;
Expand All @@ -199,9 +199,7 @@ class MediaService {
);
}

Future<void> saveVideoToGallery(String videoPath) async {
await _saveCameraVideo(File(videoPath));
}
Future<void> saveVideoToGallery(String videoPath) async => _saveCameraVideo(File(videoPath));
}

@riverpod
Expand Down

0 comments on commit ac838fb

Please sign in to comment.