feat : some utils
This commit is contained in:
43
packages/core/lib/utils/camera_utils.dart
Normal file
43
packages/core/lib/utils/camera_utils.dart
Normal file
@@ -0,0 +1,43 @@
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
Future<XFile?> pickCameraImage({
|
||||
double? maxWidth,
|
||||
double? maxHeight,
|
||||
int? imageQuality,
|
||||
CameraDevice preferredCameraDevice = CameraDevice.rear,
|
||||
bool requestFullMetadata = true,
|
||||
}) async {
|
||||
ImagePicker picker = diCore<ImagePicker>();
|
||||
var tmpImage = await picker.pickImage(
|
||||
source: ImageSource.camera,
|
||||
imageQuality: imageQuality ?? 90,
|
||||
preferredCameraDevice: CameraDevice.front,
|
||||
maxHeight: maxHeight,
|
||||
maxWidth: maxWidth,
|
||||
);
|
||||
|
||||
getFileSizeInKB(tmpImage?.path ?? '', tag: 'Picked');
|
||||
|
||||
return tmpImage;
|
||||
}
|
||||
|
||||
Future<XFile?> pickGalleryImage({
|
||||
double? maxWidth,
|
||||
double? maxHeight,
|
||||
int? imageQuality,
|
||||
CameraDevice preferredCameraDevice = CameraDevice.rear,
|
||||
bool requestFullMetadata = true,
|
||||
}) async {
|
||||
ImagePicker picker = diCore<ImagePicker>();
|
||||
var tmpImage = await picker.pickImage(
|
||||
source: ImageSource.gallery,
|
||||
imageQuality: imageQuality ?? 90,
|
||||
preferredCameraDevice: CameraDevice.front,
|
||||
maxHeight: maxHeight,
|
||||
maxWidth: maxWidth,
|
||||
);
|
||||
|
||||
getFileSizeInKB(tmpImage?.path ?? '', tag: 'Picked');
|
||||
|
||||
return tmpImage;
|
||||
}
|
||||
42
packages/core/lib/utils/location_utils.dart
Normal file
42
packages/core/lib/utils/location_utils.dart
Normal file
@@ -0,0 +1,42 @@
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
|
||||
Future<bool> checkLocationPermission({bool request = false}) async {
|
||||
try {
|
||||
final LocationPermission permission = await Geolocator.checkPermission();
|
||||
|
||||
switch (permission) {
|
||||
case LocationPermission.denied:
|
||||
final LocationPermission requestResult = await Geolocator.requestPermission();
|
||||
return requestResult != LocationPermission.denied &&
|
||||
requestResult != LocationPermission.deniedForever;
|
||||
|
||||
case LocationPermission.deniedForever:
|
||||
return request ? await Geolocator.openAppSettings() : false;
|
||||
|
||||
case LocationPermission.always:
|
||||
case LocationPermission.whileInUse:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
} catch (e) {
|
||||
eLog(e);
|
||||
return await Geolocator.openLocationSettings();
|
||||
}
|
||||
}
|
||||
|
||||
Future<Position> determineCurrentPosition() async {
|
||||
final position = await Geolocator.getCurrentPosition(
|
||||
locationSettings: AndroidSettings(accuracy: LocationAccuracy.best),
|
||||
);
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
Future<LatLng> determineCurrentLatLng() async {
|
||||
var position = await determineCurrentPosition();
|
||||
final latLng = LatLng(position.latitude, position.longitude);
|
||||
|
||||
return latLng;
|
||||
}
|
||||
Reference in New Issue
Block a user