feat: device services implemented

This commit is contained in:
Achintha Isuru
2026-02-25 12:39:25 -05:00
parent e2f3de3a54
commit 19b82ff73a
26 changed files with 348 additions and 0 deletions

View File

@@ -20,3 +20,9 @@ export 'src/services/api_service/core_api_services/llm/llm_service.dart';
export 'src/services/api_service/core_api_services/llm/llm_response.dart';
export 'src/services/api_service/core_api_services/verification/verification_service.dart';
export 'src/services/api_service/core_api_services/verification/verification_response.dart';
// Device Services
export 'src/services/device/camera/camera_service.dart';
export 'src/services/device/gallery/gallery_service.dart';
export 'src/services/device/file/file_picker_service.dart';
export 'src/services/device/file_upload/device_file_upload_service.dart';

View File

@@ -0,0 +1,23 @@
import 'package:image_picker/image_picker.dart';
import 'package:krow_domain/krow_domain.dart';
/// Service for capturing photos and videos using the device camera.
class CameraService extends BaseDeviceService {
/// Creates a [CameraService].
CameraService(this._picker);
final ImagePicker _picker;
/// Captures a photo using the camera.
///
/// Returns the path to the captured image, or null if cancelled.
Future<String?> takePhoto() async {
return action(() async {
final XFile? file = await _picker.pickImage(
source: ImageSource.camera,
imageQuality: 80,
);
return file?.path;
});
}
}

View File

@@ -0,0 +1,22 @@
import 'package:file_picker/file_picker.dart';
import 'package:krow_domain/krow_domain.dart';
/// Service for picking files from the device filesystem.
class FilePickerService extends BaseDeviceService {
/// Creates a [FilePickerService].
const FilePickerService();
/// Picks a single file from the device.
///
/// Returns the path to the selected file, or null if cancelled.
Future<String?> pickFile({List<String>? allowedExtensions}) async {
return action(() async {
final FilePickerResult? result = await FilePicker.platform.pickFiles(
type: allowedExtensions != null ? FileType.custom : FileType.any,
allowedExtensions: allowedExtensions,
);
return result?.files.single.path;
});
}
}

View File

@@ -0,0 +1,59 @@
import 'package:krow_domain/krow_domain.dart';
import '../camera/camera_service.dart';
import '../gallery/gallery_service.dart';
import '../../api_service/core_api_services/file_upload/file_upload_service.dart';
/// Orchestrator service that combines device picking and network uploading.
///
/// This provides a simplified entry point for features to "pick and upload"
/// in a single call.
class DeviceFileUploadService extends BaseDeviceService {
/// Creates a [DeviceFileUploadService].
DeviceFileUploadService({
required this.cameraService,
required this.galleryService,
required this.apiUploadService,
});
final CameraService cameraService;
final GalleryService galleryService;
final FileUploadService apiUploadService;
/// Captures a photo from the camera and uploads it immediately.
Future<ApiResponse?> uploadFromCamera({
required String fileName,
FileVisibility visibility = FileVisibility.private,
String? category,
}) async {
return action(() async {
final String? path = await cameraService.takePhoto();
if (path == null) return null;
return apiUploadService.uploadFile(
filePath: path,
fileName: fileName,
visibility: visibility,
category: category,
);
});
}
/// Picks an image from the gallery and uploads it immediately.
Future<ApiResponse?> uploadFromGallery({
required String fileName,
FileVisibility visibility = FileVisibility.private,
String? category,
}) async {
return action(() async {
final String? path = await galleryService.pickImage();
if (path == null) return null;
return apiUploadService.uploadFile(
filePath: path,
fileName: fileName,
visibility: visibility,
category: category,
);
});
}
}

View File

@@ -0,0 +1,23 @@
import 'package:image_picker/image_picker.dart';
import 'package:krow_domain/krow_domain.dart';
/// Service for picking media from the device gallery.
class GalleryService extends BaseDeviceService {
/// Creates a [GalleryService].
GalleryService(this._picker);
final ImagePicker _picker;
/// Picks an image from the gallery.
///
/// Returns the path to the selected image, or null if cancelled.
Future<String?> pickImage() async {
return action(() async {
final XFile? file = await _picker.pickImage(
source: ImageSource.gallery,
imageQuality: 80,
);
return file?.path;
});
}
}

View File

@@ -22,3 +22,6 @@ dependencies:
equatable: ^2.0.8
flutter_modular: ^6.4.1
dio: ^5.9.1
image_picker: ^1.1.2
path_provider: ^2.1.3
file_picker: ^8.1.7

View File

@@ -6,6 +6,10 @@
#include "generated_plugin_registrant.h"
#include <file_selector_linux/file_selector_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) file_selector_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "FileSelectorPlugin");
file_selector_plugin_register_with_registrar(file_selector_linux_registrar);
}

View File

@@ -3,6 +3,7 @@
#
list(APPEND FLUTTER_PLUGIN_LIST
file_selector_linux
)
list(APPEND FLUTTER_FFI_PLUGIN_LIST

View File

@@ -5,12 +5,16 @@
import FlutterMacOS
import Foundation
import file_picker
import file_selector_macos
import firebase_app_check
import firebase_auth
import firebase_core
import shared_preferences_foundation
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FilePickerPlugin.register(with: registry.registrar(forPlugin: "FilePickerPlugin"))
FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin"))
FLTFirebaseAppCheckPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAppCheckPlugin"))
FLTFirebaseAuthPlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseAuthPlugin"))
FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin"))

View File

@@ -6,10 +6,13 @@
#include "generated_plugin_registrant.h"
#include <file_selector_windows/file_selector_windows.h>
#include <firebase_auth/firebase_auth_plugin_c_api.h>
#include <firebase_core/firebase_core_plugin_c_api.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
FileSelectorWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FileSelectorWindows"));
FirebaseAuthPluginCApiRegisterWithRegistrar(
registry->GetRegistrarForPlugin("FirebaseAuthPluginCApi"));
FirebaseCorePluginCApiRegisterWithRegistrar(

View File

@@ -3,6 +3,7 @@
#
list(APPEND FLUTTER_PLUGIN_LIST
file_selector_windows
firebase_auth
firebase_core
)