feat : request tagging
This commit is contained in:
@@ -1,22 +1,43 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:rasadyar_core/core.dart';
|
||||
import 'package:rasadyar_livestock/data/model/response/address/address.dart';
|
||||
import 'package:rasadyar_livestock/data/repository/livestock/livestock_repository.dart';
|
||||
import 'package:rasadyar_livestock/injection/live_stock_di.dart';
|
||||
|
||||
class RequestTaggingLogic extends GetxController {
|
||||
RxInt currentIndex = 0.obs;
|
||||
final int maxStep = 3;
|
||||
final int maxStep = 2;
|
||||
|
||||
RxBool nextButtonEnabled = true.obs;
|
||||
|
||||
LivestockRepository livestockRepository = diLiveStock.get<LivestockRepository>();
|
||||
|
||||
//region First Step
|
||||
final TextEditingController phoneController = TextEditingController();
|
||||
final TextEditingController fullNameController = TextEditingController();
|
||||
final TextEditingController addressController = TextEditingController();
|
||||
|
||||
ImagePicker imagePicker = diLiveStock.get<ImagePicker>();
|
||||
Rxn<XFile> rancherImage = Rxn<XFile>(null);
|
||||
|
||||
//endregion
|
||||
|
||||
//region Second Step
|
||||
Rxn<XFile> herdImage = Rxn<XFile>(null);
|
||||
Rx<Resource<LocationDetails>> addressDetails = Rx<Resource<LocationDetails>>(Resource.loading());
|
||||
RxnString addressDetailsValue = RxnString(null);
|
||||
RxnString addressLocationValue = RxnString(null);
|
||||
|
||||
RxInt selectedSegment = 0.obs;
|
||||
RxBool searchIsSelected = false.obs;
|
||||
RxBool filterIsSelected = false.obs;
|
||||
RxList<int> filterSelected = <int>[].obs;
|
||||
|
||||
RxList isExpandedList = <int>[].obs;
|
||||
|
||||
RxBool tst1 = false.obs;
|
||||
|
||||
//endregion
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
@@ -25,6 +46,8 @@ class RequestTaggingLogic extends GetxController {
|
||||
ever(rancherImage, (callback) {
|
||||
setUpNextButtonListeners();
|
||||
});
|
||||
|
||||
determineCurrentPosition();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -52,11 +75,11 @@ class RequestTaggingLogic extends GetxController {
|
||||
|
||||
void setUpNextButtonListeners() {
|
||||
if (currentIndex.value == 0) {
|
||||
nextButtonEnabled.value =
|
||||
/* nextButtonEnabled.value =
|
||||
phoneController.text.isNotEmpty &&
|
||||
fullNameController.text.isNotEmpty &&
|
||||
addressController.text.isNotEmpty &&
|
||||
rancherImage.value != null;
|
||||
rancherImage.value != null;*/
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -94,10 +117,47 @@ class RequestTaggingLogic extends GetxController {
|
||||
getFileSizeInKB(rancherImage.value?.path ?? '', tag: 'Cropped');
|
||||
}
|
||||
|
||||
void getFileSizeInKB(String filePath, {String? tag}) {
|
||||
final file = File(filePath);
|
||||
final bytes = file.lengthSync();
|
||||
var size = (bytes / 1024).ceil();
|
||||
iLog('${tag ?? 'Picked'} image Size: $size');
|
||||
Future<void> determineCurrentPosition() async {
|
||||
final position = await Geolocator.getCurrentPosition(
|
||||
locationSettings: AndroidSettings(accuracy: LocationAccuracy.best),
|
||||
);
|
||||
|
||||
getLocationDetails(position.latitude, position.longitude);
|
||||
}
|
||||
|
||||
Future<void> getLocationDetails(double latitude, double longitude) async {
|
||||
safeCall(
|
||||
call: () => livestockRepository.getLocationDetails(latitude: latitude, longitude: longitude),
|
||||
onSuccess: (result) {
|
||||
if (result != null) {
|
||||
addressDetails.value = Resource.success(result);
|
||||
buildAddressDetails(result);
|
||||
addressLocationValue.value = '$latitude - $longitude';
|
||||
} else {
|
||||
addressDetails.value = Resource.error('Failed to fetch address');
|
||||
}
|
||||
},
|
||||
onError: (error, stackTrace) {
|
||||
addressDetails.value = Resource.error('Error fetching address: ${error.toString()}');
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void buildAddressDetails(LocationDetails result) {
|
||||
final address = result.address;
|
||||
if (address != null) {
|
||||
final addressParts = [
|
||||
address.state,
|
||||
address.county,
|
||||
address.district,
|
||||
address.city,
|
||||
address.suburb,
|
||||
address.neighbourhood,
|
||||
address.road,
|
||||
].where((part) => part != null && part.isNotEmpty).join(', ');
|
||||
addressDetailsValue.value = addressParts;
|
||||
} else {
|
||||
addressDetailsValue.value = 'Address not found';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user