refactor : ui and use utils

This commit is contained in:
2025-09-08 10:18:43 +03:30
parent cdde154869
commit 939f287388
6 changed files with 48 additions and 121 deletions

View File

@@ -44,7 +44,8 @@ class InspectionPoultryScienceLogic extends GetxController {
getHatchingList();
getHatchingReport();
checkPermission(request: true);
checkLocationPermission(request: true);
ever(pickedImages, (callback) {
_multiPartPickedImages.clear();
for (var element in pickedImages) {
@@ -143,15 +144,7 @@ class InspectionPoultryScienceLogic extends GetxController {
Future<void> pickImages() async {
determineCurrentPosition();
var tmp = await ImagePicker().pickImage(
source: ImageSource.camera,
imageQuality: 50,
preferredCameraDevice: CameraDevice.front,
maxHeight: 720,
maxWidth: 1080,
);
getFileSizeInKB(tmp?.path ?? '', tag: 'Picked');
var tmp = await pickCameraImage();
if (tmp?.path != null && pickedImages.length < 7) {
pickedImages.add(tmp!);
}
@@ -172,23 +165,16 @@ class InspectionPoultryScienceLogic extends GetxController {
var ls = [];
for (var element in pickedImages) {
ls.add(
await MultipartFile.fromFile(
element.path,
filename: element.name,
),
);
ls.add(await MultipartFile.fromFile(element.path, filename: element.name));
}
var data = FormData.fromMap({
'file':ls,
'file': ls,
'hatching_id': id.toString(),
'lat': currentLocation.value.latitude.toString(),
'log': currentLocation.value.longitude.toString(),
});
safeCall(
call: () async => await rootLogic.poultryRepository.submitPoultryScienceReport(
token: rootLogic.tokenService.accessToken.value!,
@@ -214,41 +200,6 @@ class InspectionPoultryScienceLogic extends GetxController {
);
}
Future<void> determineCurrentPosition() async {
final position = await Geolocator.getCurrentPosition(
locationSettings: AndroidSettings(accuracy: LocationAccuracy.best),
);
final latLng = LatLng(position.latitude, position.longitude);
currentLocation.value = latLng;
}
Future<bool> checkPermission({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();
}
}
void closeBottomSheet() {
Get.back();
}

View File

@@ -15,7 +15,8 @@ class InspectionPoultrySciencePage extends GetView<InspectionPoultryScienceLogic
@override
Widget build(BuildContext context) {
return BasePage(
isBase: true,
hasBack: true,
hasFilter: false,
routesWidget: ObxValue((route) => buildPageRoute(route), controller.routesName),
onBackPressed: () => Get.back(id: 0),
widgets: [