step 7 : presensi selfie get address and coordinate fix
This commit is contained in:
@@ -8,7 +8,7 @@ import 'package:absensi_sas/widget/real_date.dart';
|
||||
import 'package:absensi_sas/widget/sankbar_widget.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:geocoding/geocoding.dart';
|
||||
// import 'package:geocoding/geocoding.dart';
|
||||
import 'package:geolocator/geolocator.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
@@ -55,48 +55,48 @@ class PresensiScreen extends HookConsumerWidget {
|
||||
Position position = await Geolocator.getCurrentPosition(
|
||||
desiredAccuracy: LocationAccuracy.high);
|
||||
|
||||
// Mendapatkan alamat dari posisi
|
||||
List<Placemark> placemarks = await placemarkFromCoordinates(
|
||||
position.latitude, position.longitude);
|
||||
// // Mendapatkan alamat dari posisi
|
||||
// List<Placemark> placemarks = await placemarkFromCoordinates(
|
||||
// position.latitude, position.longitude);
|
||||
|
||||
if (positionLongitude.value.isEmpty && positionLatitude.value.isEmpty) {
|
||||
if (placemarks.isNotEmpty) {
|
||||
isLoadingAddressUserLocation.value = false;
|
||||
Placemark placemark = placemarks.first;
|
||||
// String address =
|
||||
// "${placemark.thoroughfare}, ${placemark.locality}, ${placemark.administrativeArea}, ${placemark.country},";
|
||||
// if (positionLongitude.value.isEmpty && positionLatitude.value.isEmpty) {
|
||||
// if (placemarks.isNotEmpty) {
|
||||
// isLoadingAddressUserLocation.value = false;
|
||||
// Placemark placemark = placemarks.first;
|
||||
// // String address =
|
||||
// // "${placemark.thoroughfare}, ${placemark.locality}, ${placemark.administrativeArea}, ${placemark.country},";
|
||||
|
||||
String address =
|
||||
"${placemark.street}, ${placemark.subLocality}, ${placemark.subAdministrativeArea}, ${placemark.postalCode}";
|
||||
print("Alamat: $address");
|
||||
// String address =
|
||||
// "${placemark.street}, ${placemark.subLocality}, ${placemark.subAdministrativeArea}, ${placemark.postalCode}";
|
||||
// print("Alamat: $address");
|
||||
|
||||
positionLatitude.value = position.latitude.toString();
|
||||
positionLongitude.value = position.longitude.toString();
|
||||
// positionLatitude.value = position.latitude.toString();
|
||||
// positionLongitude.value = position.longitude.toString();
|
||||
|
||||
if (address != "") {
|
||||
currentAddressUserLocation.value = address;
|
||||
}
|
||||
} else {
|
||||
isLoadingAddressUserLocation.value = false;
|
||||
SanckbarWidget(
|
||||
context, 'Tidak dapat menemukan alamat.', snackbarType.error);
|
||||
print("Tidak dapat menemukan alamat.");
|
||||
}
|
||||
} else {
|
||||
// jika sudah dapat latitude dan logitude baru panggil check distance provider
|
||||
if (positionLatitude.value.isNotEmpty &&
|
||||
positionLongitude.value.isNotEmpty) {
|
||||
print('check distance provider');
|
||||
// if (address != "") {
|
||||
// currentAddressUserLocation.value = address;
|
||||
// }
|
||||
// } else {
|
||||
// isLoadingAddressUserLocation.value = false;
|
||||
// SanckbarWidget(
|
||||
// context, 'Tidak dapat menemukan alamat.', snackbarType.error);
|
||||
// print("Tidak dapat menemukan alamat.");
|
||||
// }
|
||||
// } else {
|
||||
// // jika sudah dapat latitude dan logitude baru panggil check distance provider
|
||||
// if (positionLatitude.value.isNotEmpty &&
|
||||
// positionLongitude.value.isNotEmpty) {
|
||||
// print('check distance provider');
|
||||
|
||||
// panggil check distance provider
|
||||
ref.read(checkDistanceProvider.notifier).checkDistance(
|
||||
selectedUser?.model.staffId ?? "",
|
||||
selectedUser?.model.companyId ?? "",
|
||||
positionLatitude.value,
|
||||
positionLongitude.value,
|
||||
);
|
||||
}
|
||||
}
|
||||
// // panggil check distance provider
|
||||
// ref.read(checkDistanceProvider.notifier).checkDistance(
|
||||
// selectedUser?.model.staffId ?? "",
|
||||
// selectedUser?.model.companyId ?? "",
|
||||
// positionLatitude.value,
|
||||
// positionLongitude.value,
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
} catch (e) {
|
||||
print("Error: $e");
|
||||
isLoadingAddressUserLocation.value = false;
|
||||
|
||||
Reference in New Issue
Block a user