step 16 : get user location google map, refresh location google map absen selfie dan absen normal (bukan selfie)
This commit is contained in:
@@ -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