step 16 : get user location google map, refresh location google map absen selfie dan absen normal (bukan selfie)
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import 'package:google_sign_in/google_sign_in.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
const String googleClientID = "856240587825-klh0dfjc44bovajg1rpq5vbvs4g7rh5j.apps.googleusercontent.com";
|
||||
const String googleClientID =
|
||||
"856240587825-klh0dfjc44bovajg1rpq5vbvs4g7rh5j.apps.googleusercontent.com";
|
||||
|
||||
final googleSignInProvider = StateProvider<GoogleSignIn>((ref) {
|
||||
return GoogleSignIn(
|
||||
@@ -13,6 +14,10 @@ final googleSignInProvider = StateProvider<GoogleSignIn>((ref) {
|
||||
);
|
||||
});
|
||||
|
||||
final currentUserGoogleProvider = StateProvider<GoogleSignInAccount?>((ref) => null);
|
||||
final currentUserGoogleProvider =
|
||||
StateProvider<GoogleSignInAccount?>((ref) => null);
|
||||
|
||||
final isNotifyFromLogout = StateProvider<bool>((ref) => false);
|
||||
final isNotifyFromLogout = StateProvider<bool>((ref) => false);
|
||||
|
||||
final currentLatitudeProvider = StateProvider<double>((ref) => 0.0);
|
||||
final currentLongitudeProvider = StateProvider<double>((ref) => 0.0);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:absensi_sas/app/constant.dart';
|
||||
import 'package:absensi_sas/provider/current_rekap_kehadiran_home_provider.dart';
|
||||
import 'package:absensi_sas/widget/custom_google_map_widget.dart';
|
||||
import 'package:dart_nominatim/dart_nominatim.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
@@ -322,7 +323,16 @@ class HomeScreen extends HookConsumerWidget {
|
||||
)
|
||||
: FloatingActionButton(
|
||||
onPressed: () async {
|
||||
await requestLocationPermission();
|
||||
// await requestLocationPermission();
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => CustomGoogleMapWidget(
|
||||
positionLastLatitudeParam: positionLatitude,
|
||||
positionLastLongitudeParam: positionLongitude,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
backgroundColor: Color(0xFFFFFFFF),
|
||||
shape: CircleBorder(),
|
||||
|
||||
@@ -30,7 +30,9 @@ import '../../provider/camera_controller_provider.dart';
|
||||
import '../../provider/current_check_distance_provider.dart';
|
||||
import '../../provider/current_check_jam_presensi_provider.dart';
|
||||
import '../../provider/current_user_provider.dart';
|
||||
import '../../provider/google_login_provider.dart';
|
||||
import '../../widget/custom_dialog_presensi_selfie_sukses.dart';
|
||||
import '../../widget/custom_google_map_widget.dart';
|
||||
import '../../widget/real_date.dart';
|
||||
import '../../widget/real_time.dart';
|
||||
import '../../widget/sankbar_widget.dart';
|
||||
@@ -55,6 +57,10 @@ class PresensiScreen extends HookConsumerWidget {
|
||||
|
||||
final positionLatitude = useState<String>("");
|
||||
final positionLongitude = useState<String>("");
|
||||
|
||||
final currLatProvider = ref.read(currentLatitudeProvider);
|
||||
final currLongProvider = ref.read(currentLongitudeProvider);
|
||||
|
||||
// final tTransactionCurrentDistance = useState<String>("NULL");
|
||||
|
||||
Location location = new Location();
|
||||
@@ -95,23 +101,34 @@ class PresensiScreen extends HookConsumerWidget {
|
||||
_locationData = await location.getLocation();
|
||||
|
||||
// Mendapatkan alamat dari posisi
|
||||
// final address = await positionToAddressGoogleApis(
|
||||
// LatLng(_locationData.latitude!, _locationData.longitude!));
|
||||
|
||||
final address = await positionToAddressGoogleApis(
|
||||
LatLng(_locationData.latitude!, _locationData.longitude!));
|
||||
LatLng(currLatProvider, currLongProvider));
|
||||
|
||||
if (positionLongitude.value.isEmpty && positionLatitude.value.isEmpty) {
|
||||
if (address != "") {
|
||||
isLoadingAddressUserLocation.value = false;
|
||||
|
||||
// ref.read(googleApisProvider.notifier).getAddressGoogleApis(
|
||||
// latitude: _locationData.latitude.toString(),
|
||||
// longitude: _locationData.longitude.toString(),
|
||||
// );
|
||||
|
||||
ref.read(googleApisProvider.notifier).getAddressGoogleApis(
|
||||
latitude: _locationData.latitude.toString(),
|
||||
longitude: _locationData.longitude.toString(),
|
||||
latitude: currLatProvider.toString(),
|
||||
longitude: currLongProvider.toString(),
|
||||
);
|
||||
|
||||
// String address =
|
||||
// "${placemark.thoroughfare}, ${placemark.locality}, ${placemark.administrativeArea}, ${placemark.country},";
|
||||
|
||||
positionLatitude.value = _locationData.latitude.toString();
|
||||
positionLongitude.value = _locationData.longitude.toString();
|
||||
// positionLatitude.value = _locationData.latitude.toString();
|
||||
// positionLongitude.value = _locationData.longitude.toString();
|
||||
|
||||
positionLatitude.value = currLatProvider.toString();
|
||||
positionLongitude.value = currLongProvider.toString();
|
||||
} else {
|
||||
isLoadingAddressUserLocation.value = false;
|
||||
SanckbarWidget(
|
||||
@@ -511,20 +528,34 @@ class PresensiScreen extends HookConsumerWidget {
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
getAddressFromLocation();
|
||||
// getAddressFromLocation();
|
||||
|
||||
// refresh location
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => CustomGoogleMapWidget(
|
||||
positionLastLatitudeParam:
|
||||
positionLatitude,
|
||||
positionLastLongitudeParam:
|
||||
positionLongitude,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// jika sudah dapat latitude dan logitude baru panggil check distance provider
|
||||
if (positionLatitude.value.isNotEmpty &&
|
||||
positionLongitude.value.isNotEmpty) {
|
||||
// panggil check distance provider
|
||||
ref
|
||||
.read(checkDistanceProvider.notifier)
|
||||
.checkDistance(
|
||||
selectedUser?.model.staffId ?? "",
|
||||
selectedUser?.model.companyId ?? "",
|
||||
positionLatitude.value,
|
||||
positionLongitude.value,
|
||||
);
|
||||
}
|
||||
// if (positionLatitude.value.isNotEmpty &&
|
||||
// positionLongitude.value.isNotEmpty) {
|
||||
// // panggil check distance provider
|
||||
// ref
|
||||
// .read(checkDistanceProvider.notifier)
|
||||
// .checkDistance(
|
||||
// selectedUser?.model.staffId ?? "",
|
||||
// selectedUser?.model.companyId ?? "",
|
||||
// positionLatitude.value,
|
||||
// positionLongitude.value,
|
||||
// );
|
||||
// }
|
||||
},
|
||||
child: Container(
|
||||
width: Constant.getActualXPhone(
|
||||
|
||||
@@ -30,7 +30,9 @@ import '../../provider/camera_controller_provider.dart';
|
||||
import '../../provider/current_check_distance_provider.dart';
|
||||
import '../../provider/current_check_jam_presensi_provider.dart';
|
||||
import '../../provider/current_user_provider.dart';
|
||||
import '../../provider/google_login_provider.dart';
|
||||
import '../../widget/custom_dialog_presensi_selfie_sukses.dart';
|
||||
import '../../widget/custom_google_map_widget.dart';
|
||||
import '../../widget/real_date.dart';
|
||||
import '../../widget/real_time.dart';
|
||||
import '../../widget/sankbar_widget.dart';
|
||||
@@ -40,8 +42,6 @@ import 'check_presensi_jam_provider.dart';
|
||||
import 'googleapis_provider.dart';
|
||||
import 'dart:io' as io;
|
||||
|
||||
import 'presensi_selfie_upload_area_web.dart';
|
||||
|
||||
class PresensiSelfieScreen extends HookConsumerWidget {
|
||||
const PresensiSelfieScreen({super.key});
|
||||
|
||||
@@ -55,6 +55,9 @@ class PresensiSelfieScreen extends HookConsumerWidget {
|
||||
ref.watch(currentCheckJamPresensiProvider);
|
||||
final selectedUser = ref.watch(currentUserProvider);
|
||||
|
||||
final currLatProvider = ref.read(currentLatitudeProvider);
|
||||
final currLongProvider = ref.read(currentLongitudeProvider);
|
||||
|
||||
final positionLatitude = useState<String>("");
|
||||
final positionLongitude = useState<String>("");
|
||||
|
||||
@@ -195,8 +198,11 @@ class PresensiSelfieScreen extends HookConsumerWidget {
|
||||
_locationData = await location.getLocation();
|
||||
|
||||
// Mendapatkan alamat dari posisi
|
||||
// final address = await positionToAddressGoogleApis(
|
||||
// LatLng(_locationData.latitude!, _locationData.longitude!));
|
||||
|
||||
final address = await positionToAddressGoogleApis(
|
||||
LatLng(_locationData.latitude!, _locationData.longitude!));
|
||||
LatLng(currLatProvider, currLongProvider));
|
||||
|
||||
// final address = await positionToAddress(
|
||||
// LatLng(-7.5666203, 110.8083376),
|
||||
@@ -207,16 +213,24 @@ class PresensiSelfieScreen extends HookConsumerWidget {
|
||||
if (address != "") {
|
||||
isLoadingAddressUserLocation.value = false;
|
||||
|
||||
// ref.read(googleApisProvider.notifier).getAddressGoogleApis(
|
||||
// latitude: _locationData.latitude.toString(),
|
||||
// longitude: _locationData.longitude.toString(),
|
||||
// );
|
||||
|
||||
ref.read(googleApisProvider.notifier).getAddressGoogleApis(
|
||||
latitude: _locationData.latitude.toString(),
|
||||
longitude: _locationData.longitude.toString(),
|
||||
latitude: currLatProvider.toString(),
|
||||
longitude: currLongProvider.toString(),
|
||||
);
|
||||
|
||||
// String address =
|
||||
// "${placemark.thoroughfare}, ${placemark.locality}, ${placemark.administrativeArea}, ${placemark.country},";
|
||||
|
||||
positionLatitude.value = _locationData.latitude.toString();
|
||||
positionLongitude.value = _locationData.longitude.toString();
|
||||
// positionLatitude.value = _locationData.latitude.toString();
|
||||
// positionLongitude.value = _locationData.longitude.toString();
|
||||
|
||||
positionLatitude.value = currLatProvider.toString();
|
||||
positionLongitude.value = currLongProvider.toString();
|
||||
} else {
|
||||
isLoadingAddressUserLocation.value = false;
|
||||
SanckbarWidget(
|
||||
@@ -660,7 +674,21 @@ class PresensiSelfieScreen extends HookConsumerWidget {
|
||||
children: [
|
||||
InkWell(
|
||||
onTap: () async {
|
||||
getAddressFromLocation();
|
||||
// getAddressFromLocation();
|
||||
|
||||
// refresh location
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (_) => CustomGoogleMapWidget(
|
||||
positionLastLatitudeParam:
|
||||
positionLatitude,
|
||||
positionLastLongitudeParam:
|
||||
positionLongitude,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// jika sudah dapat latitude dan logitude baru panggil check distance provider
|
||||
// if (positionLatitude.value.isNotEmpty &&
|
||||
// positionLongitude.value.isNotEmpty) {
|
||||
|
||||
@@ -5,6 +5,12 @@ import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
|
||||
import '../app/constant.dart';
|
||||
import '../app/route.dart';
|
||||
import '../provider/current_menu_provider.dart';
|
||||
import '../provider/current_user_provider.dart';
|
||||
import '../provider/google_login_provider.dart';
|
||||
import '../screen/presensi/check_distance_provider.dart';
|
||||
import 'sankbar_widget.dart';
|
||||
|
||||
class CustomGoogleMapWidget extends HookConsumerWidget {
|
||||
const CustomGoogleMapWidget({
|
||||
@@ -13,8 +19,8 @@ class CustomGoogleMapWidget extends HookConsumerWidget {
|
||||
required this.positionLastLongitudeParam,
|
||||
});
|
||||
|
||||
final ValueNotifier<double> positionLastLatitudeParam;
|
||||
final ValueNotifier<double> positionLastLongitudeParam;
|
||||
final ValueNotifier<String> positionLastLatitudeParam;
|
||||
final ValueNotifier<String> positionLastLongitudeParam;
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final mapController = useState<GoogleMapController?>(null);
|
||||
@@ -28,6 +34,24 @@ class CustomGoogleMapWidget extends HookConsumerWidget {
|
||||
Constant.positionLongitudeAwal,
|
||||
);
|
||||
|
||||
final selectedUser = ref.read(currentUserProvider);
|
||||
final isLoadingProsesCheckDistance = useState<bool>(false);
|
||||
|
||||
useEffect(() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) async {
|
||||
final staffID = ref.read(currentUserProvider)?.model.staffId ?? "0";
|
||||
if (staffID == "0") {
|
||||
//not login
|
||||
Navigator.of(context)
|
||||
.pushNamedAndRemoveUntil(loginRoute, (route) => true);
|
||||
|
||||
// Navigator.popAndPushNamed(context, loginRoute);
|
||||
return;
|
||||
}
|
||||
});
|
||||
return () {};
|
||||
}, []);
|
||||
|
||||
useEffect(() {
|
||||
Future<void> loadCustomMarker() async {
|
||||
final icon = await BitmapDescriptor.asset(
|
||||
@@ -41,7 +65,7 @@ class CustomGoogleMapWidget extends HookConsumerWidget {
|
||||
return null;
|
||||
}, []);
|
||||
|
||||
Future<void> getCurrentLocation() async {
|
||||
Future<void> getCurrentLocation(context) async {
|
||||
try {
|
||||
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||
if (!serviceEnabled) return;
|
||||
@@ -66,12 +90,58 @@ class CustomGoogleMapWidget extends HookConsumerWidget {
|
||||
mapController.value!.animateCamera(
|
||||
CameraUpdate.newLatLng(currentPosition.value!),
|
||||
);
|
||||
|
||||
// change current position
|
||||
final currentLat = currentPosition.value!.latitude;
|
||||
final currentLong = currentPosition.value!.longitude;
|
||||
|
||||
// update parameter di home
|
||||
positionLastLatitudeParam.value = currentLat.toString();
|
||||
positionLastLongitudeParam.value = currentLong.toString();
|
||||
|
||||
// update ke state provider
|
||||
ref.read(currentLatitudeProvider.notifier).state = currentLat;
|
||||
ref.read(currentLongitudeProvider.notifier).state = currentLong;
|
||||
|
||||
print("LATITUDE PRESENSI ${currentLat.toString()}");
|
||||
print("LONGITUDE PRESENSI ${currentLong.toString()}");
|
||||
|
||||
// check distance
|
||||
ref.read(checkDistanceProvider.notifier).checkDistance(
|
||||
selectedUser?.model.staffId ?? "",
|
||||
selectedUser?.model.companyId ?? "",
|
||||
currentLat.toString(),
|
||||
currentLong.toString(),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
print('Error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
// check distance provider
|
||||
ref.listen(checkDistanceProvider, (prev, next) {
|
||||
if (next is CheckDistanceStateLoading) {
|
||||
isLoadingProsesCheckDistance.value = true;
|
||||
} else if (next is CheckDistanceStateError) {
|
||||
isLoadingProsesCheckDistance.value = false;
|
||||
SanckbarWidget(context, next.message, snackbarType.warning);
|
||||
} else if (next is CheckDistanceStateDone) {
|
||||
isLoadingProsesCheckDistance.value = false;
|
||||
|
||||
if (next.model.selfie == "TRUE") {
|
||||
ref.read(currentPageProvider.notifier).update((state) => 99);
|
||||
// Navigator.of(context).pop();
|
||||
Navigator.of(context).restorablePushNamed(presensiSelfieRoute);
|
||||
} else {
|
||||
if (next.model.selfie == "FALSE") {
|
||||
ref.read(currentPageProvider.notifier).update((state) => 99);
|
||||
Navigator.of(context).restorablePushNamed(presensiRoute);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Constant.textWhite,
|
||||
appBar: AppBar(
|
||||
@@ -118,7 +188,9 @@ class CustomGoogleMapWidget extends HookConsumerWidget {
|
||||
bottom: 20,
|
||||
left: 20,
|
||||
child: ElevatedButton(
|
||||
onPressed: getCurrentLocation,
|
||||
onPressed: () async {
|
||||
getCurrentLocation(context);
|
||||
},
|
||||
child: Text('Current Location'),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user