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:google_sign_in/google_sign_in.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.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) {
|
final googleSignInProvider = StateProvider<GoogleSignIn>((ref) {
|
||||||
return GoogleSignIn(
|
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/app/constant.dart';
|
||||||
import 'package:absensi_sas/provider/current_rekap_kehadiran_home_provider.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:dart_nominatim/dart_nominatim.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
@@ -322,7 +323,16 @@ class HomeScreen extends HookConsumerWidget {
|
|||||||
)
|
)
|
||||||
: FloatingActionButton(
|
: FloatingActionButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
await requestLocationPermission();
|
// await requestLocationPermission();
|
||||||
|
Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(
|
||||||
|
builder: (_) => CustomGoogleMapWidget(
|
||||||
|
positionLastLatitudeParam: positionLatitude,
|
||||||
|
positionLastLongitudeParam: positionLongitude,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
backgroundColor: Color(0xFFFFFFFF),
|
backgroundColor: Color(0xFFFFFFFF),
|
||||||
shape: CircleBorder(),
|
shape: CircleBorder(),
|
||||||
|
|||||||
@@ -30,7 +30,9 @@ import '../../provider/camera_controller_provider.dart';
|
|||||||
import '../../provider/current_check_distance_provider.dart';
|
import '../../provider/current_check_distance_provider.dart';
|
||||||
import '../../provider/current_check_jam_presensi_provider.dart';
|
import '../../provider/current_check_jam_presensi_provider.dart';
|
||||||
import '../../provider/current_user_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_dialog_presensi_selfie_sukses.dart';
|
||||||
|
import '../../widget/custom_google_map_widget.dart';
|
||||||
import '../../widget/real_date.dart';
|
import '../../widget/real_date.dart';
|
||||||
import '../../widget/real_time.dart';
|
import '../../widget/real_time.dart';
|
||||||
import '../../widget/sankbar_widget.dart';
|
import '../../widget/sankbar_widget.dart';
|
||||||
@@ -55,6 +57,10 @@ class PresensiScreen extends HookConsumerWidget {
|
|||||||
|
|
||||||
final positionLatitude = useState<String>("");
|
final positionLatitude = useState<String>("");
|
||||||
final positionLongitude = useState<String>("");
|
final positionLongitude = useState<String>("");
|
||||||
|
|
||||||
|
final currLatProvider = ref.read(currentLatitudeProvider);
|
||||||
|
final currLongProvider = ref.read(currentLongitudeProvider);
|
||||||
|
|
||||||
// final tTransactionCurrentDistance = useState<String>("NULL");
|
// final tTransactionCurrentDistance = useState<String>("NULL");
|
||||||
|
|
||||||
Location location = new Location();
|
Location location = new Location();
|
||||||
@@ -95,23 +101,34 @@ class PresensiScreen extends HookConsumerWidget {
|
|||||||
_locationData = await location.getLocation();
|
_locationData = await location.getLocation();
|
||||||
|
|
||||||
// Mendapatkan alamat dari posisi
|
// Mendapatkan alamat dari posisi
|
||||||
|
// final address = await positionToAddressGoogleApis(
|
||||||
|
// LatLng(_locationData.latitude!, _locationData.longitude!));
|
||||||
|
|
||||||
final address = await positionToAddressGoogleApis(
|
final address = await positionToAddressGoogleApis(
|
||||||
LatLng(_locationData.latitude!, _locationData.longitude!));
|
LatLng(currLatProvider, currLongProvider));
|
||||||
|
|
||||||
if (positionLongitude.value.isEmpty && positionLatitude.value.isEmpty) {
|
if (positionLongitude.value.isEmpty && positionLatitude.value.isEmpty) {
|
||||||
if (address != "") {
|
if (address != "") {
|
||||||
isLoadingAddressUserLocation.value = false;
|
isLoadingAddressUserLocation.value = false;
|
||||||
|
|
||||||
|
// ref.read(googleApisProvider.notifier).getAddressGoogleApis(
|
||||||
|
// latitude: _locationData.latitude.toString(),
|
||||||
|
// longitude: _locationData.longitude.toString(),
|
||||||
|
// );
|
||||||
|
|
||||||
ref.read(googleApisProvider.notifier).getAddressGoogleApis(
|
ref.read(googleApisProvider.notifier).getAddressGoogleApis(
|
||||||
latitude: _locationData.latitude.toString(),
|
latitude: currLatProvider.toString(),
|
||||||
longitude: _locationData.longitude.toString(),
|
longitude: currLongProvider.toString(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// String address =
|
// String address =
|
||||||
// "${placemark.thoroughfare}, ${placemark.locality}, ${placemark.administrativeArea}, ${placemark.country},";
|
// "${placemark.thoroughfare}, ${placemark.locality}, ${placemark.administrativeArea}, ${placemark.country},";
|
||||||
|
|
||||||
positionLatitude.value = _locationData.latitude.toString();
|
// positionLatitude.value = _locationData.latitude.toString();
|
||||||
positionLongitude.value = _locationData.longitude.toString();
|
// positionLongitude.value = _locationData.longitude.toString();
|
||||||
|
|
||||||
|
positionLatitude.value = currLatProvider.toString();
|
||||||
|
positionLongitude.value = currLongProvider.toString();
|
||||||
} else {
|
} else {
|
||||||
isLoadingAddressUserLocation.value = false;
|
isLoadingAddressUserLocation.value = false;
|
||||||
SanckbarWidget(
|
SanckbarWidget(
|
||||||
@@ -511,20 +528,34 @@ class PresensiScreen extends HookConsumerWidget {
|
|||||||
children: [
|
children: [
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () async {
|
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
|
// jika sudah dapat latitude dan logitude baru panggil check distance provider
|
||||||
if (positionLatitude.value.isNotEmpty &&
|
// if (positionLatitude.value.isNotEmpty &&
|
||||||
positionLongitude.value.isNotEmpty) {
|
// positionLongitude.value.isNotEmpty) {
|
||||||
// panggil check distance provider
|
// // panggil check distance provider
|
||||||
ref
|
// ref
|
||||||
.read(checkDistanceProvider.notifier)
|
// .read(checkDistanceProvider.notifier)
|
||||||
.checkDistance(
|
// .checkDistance(
|
||||||
selectedUser?.model.staffId ?? "",
|
// selectedUser?.model.staffId ?? "",
|
||||||
selectedUser?.model.companyId ?? "",
|
// selectedUser?.model.companyId ?? "",
|
||||||
positionLatitude.value,
|
// positionLatitude.value,
|
||||||
positionLongitude.value,
|
// positionLongitude.value,
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
width: Constant.getActualXPhone(
|
width: Constant.getActualXPhone(
|
||||||
|
|||||||
@@ -30,7 +30,9 @@ import '../../provider/camera_controller_provider.dart';
|
|||||||
import '../../provider/current_check_distance_provider.dart';
|
import '../../provider/current_check_distance_provider.dart';
|
||||||
import '../../provider/current_check_jam_presensi_provider.dart';
|
import '../../provider/current_check_jam_presensi_provider.dart';
|
||||||
import '../../provider/current_user_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_dialog_presensi_selfie_sukses.dart';
|
||||||
|
import '../../widget/custom_google_map_widget.dart';
|
||||||
import '../../widget/real_date.dart';
|
import '../../widget/real_date.dart';
|
||||||
import '../../widget/real_time.dart';
|
import '../../widget/real_time.dart';
|
||||||
import '../../widget/sankbar_widget.dart';
|
import '../../widget/sankbar_widget.dart';
|
||||||
@@ -40,8 +42,6 @@ import 'check_presensi_jam_provider.dart';
|
|||||||
import 'googleapis_provider.dart';
|
import 'googleapis_provider.dart';
|
||||||
import 'dart:io' as io;
|
import 'dart:io' as io;
|
||||||
|
|
||||||
import 'presensi_selfie_upload_area_web.dart';
|
|
||||||
|
|
||||||
class PresensiSelfieScreen extends HookConsumerWidget {
|
class PresensiSelfieScreen extends HookConsumerWidget {
|
||||||
const PresensiSelfieScreen({super.key});
|
const PresensiSelfieScreen({super.key});
|
||||||
|
|
||||||
@@ -55,6 +55,9 @@ class PresensiSelfieScreen extends HookConsumerWidget {
|
|||||||
ref.watch(currentCheckJamPresensiProvider);
|
ref.watch(currentCheckJamPresensiProvider);
|
||||||
final selectedUser = ref.watch(currentUserProvider);
|
final selectedUser = ref.watch(currentUserProvider);
|
||||||
|
|
||||||
|
final currLatProvider = ref.read(currentLatitudeProvider);
|
||||||
|
final currLongProvider = ref.read(currentLongitudeProvider);
|
||||||
|
|
||||||
final positionLatitude = useState<String>("");
|
final positionLatitude = useState<String>("");
|
||||||
final positionLongitude = useState<String>("");
|
final positionLongitude = useState<String>("");
|
||||||
|
|
||||||
@@ -195,8 +198,11 @@ class PresensiSelfieScreen extends HookConsumerWidget {
|
|||||||
_locationData = await location.getLocation();
|
_locationData = await location.getLocation();
|
||||||
|
|
||||||
// Mendapatkan alamat dari posisi
|
// Mendapatkan alamat dari posisi
|
||||||
|
// final address = await positionToAddressGoogleApis(
|
||||||
|
// LatLng(_locationData.latitude!, _locationData.longitude!));
|
||||||
|
|
||||||
final address = await positionToAddressGoogleApis(
|
final address = await positionToAddressGoogleApis(
|
||||||
LatLng(_locationData.latitude!, _locationData.longitude!));
|
LatLng(currLatProvider, currLongProvider));
|
||||||
|
|
||||||
// final address = await positionToAddress(
|
// final address = await positionToAddress(
|
||||||
// LatLng(-7.5666203, 110.8083376),
|
// LatLng(-7.5666203, 110.8083376),
|
||||||
@@ -207,16 +213,24 @@ class PresensiSelfieScreen extends HookConsumerWidget {
|
|||||||
if (address != "") {
|
if (address != "") {
|
||||||
isLoadingAddressUserLocation.value = false;
|
isLoadingAddressUserLocation.value = false;
|
||||||
|
|
||||||
|
// ref.read(googleApisProvider.notifier).getAddressGoogleApis(
|
||||||
|
// latitude: _locationData.latitude.toString(),
|
||||||
|
// longitude: _locationData.longitude.toString(),
|
||||||
|
// );
|
||||||
|
|
||||||
ref.read(googleApisProvider.notifier).getAddressGoogleApis(
|
ref.read(googleApisProvider.notifier).getAddressGoogleApis(
|
||||||
latitude: _locationData.latitude.toString(),
|
latitude: currLatProvider.toString(),
|
||||||
longitude: _locationData.longitude.toString(),
|
longitude: currLongProvider.toString(),
|
||||||
);
|
);
|
||||||
|
|
||||||
// String address =
|
// String address =
|
||||||
// "${placemark.thoroughfare}, ${placemark.locality}, ${placemark.administrativeArea}, ${placemark.country},";
|
// "${placemark.thoroughfare}, ${placemark.locality}, ${placemark.administrativeArea}, ${placemark.country},";
|
||||||
|
|
||||||
positionLatitude.value = _locationData.latitude.toString();
|
// positionLatitude.value = _locationData.latitude.toString();
|
||||||
positionLongitude.value = _locationData.longitude.toString();
|
// positionLongitude.value = _locationData.longitude.toString();
|
||||||
|
|
||||||
|
positionLatitude.value = currLatProvider.toString();
|
||||||
|
positionLongitude.value = currLongProvider.toString();
|
||||||
} else {
|
} else {
|
||||||
isLoadingAddressUserLocation.value = false;
|
isLoadingAddressUserLocation.value = false;
|
||||||
SanckbarWidget(
|
SanckbarWidget(
|
||||||
@@ -660,7 +674,21 @@ class PresensiSelfieScreen extends HookConsumerWidget {
|
|||||||
children: [
|
children: [
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () async {
|
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
|
// jika sudah dapat latitude dan logitude baru panggil check distance provider
|
||||||
// if (positionLatitude.value.isNotEmpty &&
|
// if (positionLatitude.value.isNotEmpty &&
|
||||||
// positionLongitude.value.isNotEmpty) {
|
// positionLongitude.value.isNotEmpty) {
|
||||||
|
|||||||
@@ -5,6 +5,12 @@ import 'package:flutter_hooks/flutter_hooks.dart';
|
|||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
|
||||||
import '../app/constant.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 {
|
class CustomGoogleMapWidget extends HookConsumerWidget {
|
||||||
const CustomGoogleMapWidget({
|
const CustomGoogleMapWidget({
|
||||||
@@ -13,8 +19,8 @@ class CustomGoogleMapWidget extends HookConsumerWidget {
|
|||||||
required this.positionLastLongitudeParam,
|
required this.positionLastLongitudeParam,
|
||||||
});
|
});
|
||||||
|
|
||||||
final ValueNotifier<double> positionLastLatitudeParam;
|
final ValueNotifier<String> positionLastLatitudeParam;
|
||||||
final ValueNotifier<double> positionLastLongitudeParam;
|
final ValueNotifier<String> positionLastLongitudeParam;
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final mapController = useState<GoogleMapController?>(null);
|
final mapController = useState<GoogleMapController?>(null);
|
||||||
@@ -28,6 +34,24 @@ class CustomGoogleMapWidget extends HookConsumerWidget {
|
|||||||
Constant.positionLongitudeAwal,
|
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(() {
|
useEffect(() {
|
||||||
Future<void> loadCustomMarker() async {
|
Future<void> loadCustomMarker() async {
|
||||||
final icon = await BitmapDescriptor.asset(
|
final icon = await BitmapDescriptor.asset(
|
||||||
@@ -41,7 +65,7 @@ class CustomGoogleMapWidget extends HookConsumerWidget {
|
|||||||
return null;
|
return null;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
Future<void> getCurrentLocation() async {
|
Future<void> getCurrentLocation(context) async {
|
||||||
try {
|
try {
|
||||||
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
|
||||||
if (!serviceEnabled) return;
|
if (!serviceEnabled) return;
|
||||||
@@ -66,12 +90,58 @@ class CustomGoogleMapWidget extends HookConsumerWidget {
|
|||||||
mapController.value!.animateCamera(
|
mapController.value!.animateCamera(
|
||||||
CameraUpdate.newLatLng(currentPosition.value!),
|
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) {
|
} catch (e) {
|
||||||
print('Error: $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(
|
return Scaffold(
|
||||||
backgroundColor: Constant.textWhite,
|
backgroundColor: Constant.textWhite,
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
@@ -118,7 +188,9 @@ class CustomGoogleMapWidget extends HookConsumerWidget {
|
|||||||
bottom: 20,
|
bottom: 20,
|
||||||
left: 20,
|
left: 20,
|
||||||
child: ElevatedButton(
|
child: ElevatedButton(
|
||||||
onPressed: getCurrentLocation,
|
onPressed: () async {
|
||||||
|
getCurrentLocation(context);
|
||||||
|
},
|
||||||
child: Text('Current Location'),
|
child: Text('Current Location'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user