diff --git a/lib/repository/base_repository.dart b/lib/repository/base_repository.dart index 8ea39be..4bbacc9 100644 --- a/lib/repository/base_repository.dart +++ b/lib/repository/base_repository.dart @@ -18,7 +18,16 @@ abstract class BaseRepository { final QueryResult result = await graphql.mutate(options); if (result.hasException) { - throw BaseRepositoryException(message: result.exception.toString()); + // throw BaseRepositoryException(message: result.exception.toString()); + if (result.exception != null) { + if (result.exception!.graphqlErrors.isNotEmpty) { + String error = ""; + if (result.exception!.graphqlErrors[0].message != "") { + error += result.exception!.graphqlErrors[0].message; + throw BaseRepositoryException(message: error); + } + } + } } // return result.data!; @@ -36,9 +45,20 @@ abstract class BaseRepository { final QueryResult result = await graphql.query(options); if (result.hasException) { - throw BaseRepositoryException(message: result.exception.toString()); + // throw BaseRepositoryException(message: result.exception.toString()); + if (result.exception != null) { + if (result.exception!.graphqlErrors.isNotEmpty) { + if (result.exception!.graphqlErrors[0].message != "") { + throw BaseRepositoryException( + message: result.exception!.graphqlErrors[0].message.toString(), + ); + } + } + } } + // throw BaseRepositoryException(message: result.exception.toString()); + return result.data!; } catch (e) { throw BaseRepositoryException(message: e.toString()); diff --git a/lib/screen/presensi/check_presensi_jam_provider.dart b/lib/screen/presensi/check_presensi_jam_provider.dart index 4e870f6..8d9b785 100644 --- a/lib/screen/presensi/check_presensi_jam_provider.dart +++ b/lib/screen/presensi/check_presensi_jam_provider.dart @@ -66,6 +66,7 @@ class CheckPresensiJamNotifier extends StateNotifier { state = CheckPresensiJamStateDone(model: resp); } catch (e) { if (e is BaseRepositoryException) { + print(e.message); state = CheckPresensiJamStateError(message: e.message ?? ""); } else { state = CheckPresensiJamStateError(message: e.toString()); diff --git a/lib/screen/presensi/presensi_selfie_screen.dart b/lib/screen/presensi/presensi_selfie_screen.dart index b1af355..5067f67 100644 --- a/lib/screen/presensi/presensi_selfie_screen.dart +++ b/lib/screen/presensi/presensi_selfie_screen.dart @@ -290,13 +290,14 @@ class PresensiSelfieScreen extends HookConsumerWidget { context: context, builder: (BuildContext context) { return CustomDialogPresensiSukses( + isLoadingAddressUserLocation: isLoadingAddressUserLocation, isiPesan: 'Pengajuan presensi telah diajukan, mohon menunggu approval team leader! ', messageStatus: 'Clock In Berhasil', ); }, ); - requestLocationPermission(); + // requestLocationPermission(); } // else{ // if(next.model == "WARNING"){ @@ -323,13 +324,14 @@ class PresensiSelfieScreen extends HookConsumerWidget { context: context, builder: (BuildContext context) { return CustomDialogPresensiSukses( + isLoadingAddressUserLocation: isLoadingAddressUserLocation, isiPesan: 'Pengajuan presensi telah diajukan, mohon menunggu approval team leader! ', messageStatus: 'Clock Out Berhasil', ); }, ); - requestLocationPermission(); + // requestLocationPermission(); } // else{ // if(next.model == "WARNING"){ @@ -796,42 +798,48 @@ class PresensiSelfieScreen extends HookConsumerWidget { // onPressed: () { // Navigator.of(context).pushNamed(homeRoute); // }, - onPressed: () { - final T_TransactionM_StaffID = - selectedUser?.model.staffId ?? ""; - final T_TransactionM_CompanyID = - selectedUser?.model.companyId ?? ""; - final T_TransactionCurrentLatitude = - positionLatitude.value; - final T_TransactionCurrentLongitude = - positionLongitude.value; - final T_TransactionCurrentDistance = - varCurrentDistanceProvider - ?.currentDistance ?? - ""; - final T_TransactionSelfiePhoto = - fileDataBase64.value; - final token = selectedUser?.token ?? ""; + onPressed: (fileDataBase64.value.isEmpty) + ? () {} + : () { + final T_TransactionM_StaffID = + selectedUser?.model.staffId ?? ""; + final T_TransactionM_CompanyID = + selectedUser?.model.companyId ?? + ""; + final T_TransactionCurrentLatitude = + positionLatitude.value; + final T_TransactionCurrentLongitude = + positionLongitude.value; + final T_TransactionCurrentDistance = + varCurrentDistanceProvider + ?.currentDistance ?? + ""; + final T_TransactionSelfiePhoto = + fileDataBase64.value; + final token = + selectedUser?.token ?? ""; - showConfirmationDialog( - context, - T_TransactionM_StaffID, - T_TransactionM_CompanyID, - T_TransactionCurrentLatitude, - T_TransactionCurrentLongitude, - T_TransactionCurrentDistance, - T_TransactionSelfiePhoto, - token, - "Clock In"); + showConfirmationDialog( + context, + T_TransactionM_StaffID, + T_TransactionM_CompanyID, + T_TransactionCurrentLatitude, + T_TransactionCurrentLongitude, + T_TransactionCurrentDistance, + T_TransactionSelfiePhoto, + token, + "Clock In"); - // print( - // fileDataBase64.value, - // ); - }, + // print( + // fileDataBase64.value, + // ); + }, style: ButtonStyle( backgroundColor: - MaterialStateColor.resolveWith( - (st) => Constant.textOrange), + MaterialStateColor.resolveWith((st) => + (fileDataBase64.value.isEmpty) + ? Constant.textDarkGrey + : Constant.textOrange), shape: MaterialStateProperty.all< RoundedRectangleBorder>( RoundedRectangleBorder( @@ -917,41 +925,48 @@ class PresensiSelfieScreen extends HookConsumerWidget { // onPressed: () { // Navigator.of(context).pushNamed(homeRoute); // }, - onPressed: () { - final T_TransactionM_StaffID = - selectedUser?.model.staffId ?? ""; - final T_TransactionM_CompanyID = - selectedUser?.model.companyId ?? ""; - final T_TransactionCurrentLatitude = - positionLatitude.value; - final T_TransactionCurrentLongitude = - positionLongitude.value; - final T_TransactionCurrentDistance = - varCurrentDistanceProvider - ?.currentDistance ?? - ""; - final T_TransactionSelfiePhoto = - fileDataBase64.value; - final token = selectedUser?.token ?? ""; + onPressed: (fileDataBase64.value.isEmpty) + ? () {} + : () { + final T_TransactionM_StaffID = + selectedUser?.model.staffId ?? + ""; + final T_TransactionM_CompanyID = + selectedUser?.model.companyId ?? + ""; + final T_TransactionCurrentLatitude = + positionLatitude.value; + final T_TransactionCurrentLongitude = + positionLongitude.value; + final T_TransactionCurrentDistance = + varCurrentDistanceProvider + ?.currentDistance ?? + ""; + final T_TransactionSelfiePhoto = + fileDataBase64.value; + final token = + selectedUser?.token ?? ""; - showConfirmationDialog( - context, - T_TransactionM_StaffID, - T_TransactionM_CompanyID, - T_TransactionCurrentLatitude, - T_TransactionCurrentLongitude, - T_TransactionCurrentDistance, - T_TransactionSelfiePhoto, - token, - "Clock Out"); - // print( - // fileDataBase64.value, - // ); - }, + showConfirmationDialog( + context, + T_TransactionM_StaffID, + T_TransactionM_CompanyID, + T_TransactionCurrentLatitude, + T_TransactionCurrentLongitude, + T_TransactionCurrentDistance, + T_TransactionSelfiePhoto, + token, + "Clock Out"); + // print( + // fileDataBase64.value, + // ); + }, style: ButtonStyle( backgroundColor: - MaterialStateColor.resolveWith( - (st) => Constant.textOrange), + MaterialStateColor.resolveWith((st) => + (fileDataBase64.value.isEmpty) + ? Constant.textDarkGrey + : Constant.textOrange), shape: MaterialStateProperty.all< RoundedRectangleBorder>( RoundedRectangleBorder( diff --git a/lib/widget/custom_dialog_presensi_selfie_sukses.dart b/lib/widget/custom_dialog_presensi_selfie_sukses.dart index ec82125..8d09f56 100644 --- a/lib/widget/custom_dialog_presensi_selfie_sukses.dart +++ b/lib/widget/custom_dialog_presensi_selfie_sukses.dart @@ -1,13 +1,18 @@ +import 'dart:async'; + import 'package:flutter/material.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import '../app/constant.dart'; +import '../app/route.dart'; class CustomDialogPresensiSukses extends HookConsumerWidget { final String messageStatus; final String isiPesan; + final ValueNotifier isLoadingAddressUserLocation; CustomDialogPresensiSukses({ + required this.isLoadingAddressUserLocation, required this.messageStatus, required this.isiPesan, }); @@ -79,7 +84,10 @@ class CustomDialogPresensiSukses extends HookConsumerWidget { ), ElevatedButton( onPressed: () { - Navigator.of(context).pop(); // Close the dialog + Navigator.of(context).pushNamedAndRemoveUntil( + homeRoute, + (route) => false, + ); }, style: ButtonStyle( backgroundColor: MaterialStateColor.resolveWith(