Commit 1150a8b4 authored by Dio Maulana's avatar Dio Maulana

tambah dialog konfirmasi ketika submit dia out of range

parent 80696031
......@@ -148,7 +148,8 @@ class Api {
}
static Future<ApiResponse> shiftIn(
String branchId, String nik, String shiftId, String photoBase64) async {
String branchId, String nik, String shiftId, String photoBase64,
{int forceSubmit = 0}) async {
String apiUrl = "$baseUrl${endPoint}clock_in";
Position position = await Geolocator.getCurrentPosition();
IpAddress ipAddress = IpAddress(type: RequestType.json);
......@@ -170,6 +171,7 @@ class Api {
"photo_base64": "data:image/jpeg;base64,$photoBase64",
"ip": dataIp['ip'],
"user_agent": userAgent,
"forced_submit": forceSubmit,
};
String bodies = jsonEncode(data);
dynamic jsonObject =
......@@ -202,6 +204,7 @@ class Api {
return ApiResponse(
error: true,
msg: jsonObject['msg'],
code: jsonObject['code'],
);
}
}
......@@ -211,7 +214,8 @@ class Api {
}
static Future<ApiResponse> shiftOut(
String branchId, String nik, String photoBase64) async {
String branchId, String nik, String photoBase64,
{int forceSubmit = 0}) async {
String apiUrl = "$baseUrl${endPoint}clock_out";
Position position = await Geolocator.getCurrentPosition();
......@@ -233,6 +237,7 @@ class Api {
"photo_base64": photoBase64,
"ip": dataIp['ip'],
"user_agent": userAgent,
"forced_submit": forceSubmit,
};
String bodies = jsonEncode(data);
dynamic jsonObject =
......@@ -260,6 +265,7 @@ class Api {
return ApiResponse(
error: true,
msg: jsonObject['msg'],
code: jsonObject['code'],
);
}
}
......@@ -316,10 +322,12 @@ class ApiResponse {
bool error;
String msg;
dynamic data;
String code;
ApiResponse({
required this.error,
required this.msg,
this.data,
this.code = "",
});
}
......@@ -14,6 +14,7 @@ Future<dynamic> modalDialogGlobal({
bool isActiveCancelButton = false,
bool isCustomSecondButton = false,
String customSecondButtonText = '',
String cancelButtonText = "Batal",
Widget? navigateToCustomButton,
}) async {
return showDialog(
......@@ -61,8 +62,8 @@ Future<dynamic> modalDialogGlobal({
onTap: () {
tapButtonCancel!();
},
child: const CustomButton(
text: "Batal",
child: CustomButton(
text: cancelButtonText,
colorButton: Colors.transparent,
colorText: Colors.black,
),
......
// ignore_for_file: sized_box_for_whitespace
// ignore_for_file: sized_box_for_whitespace, use_build_context_synchronously
import 'dart:async';
import 'dart:convert';
......@@ -453,25 +453,109 @@ class _AbsentCameraViewState extends State<AbsentCameraView> {
CustomButton(
text: "Submit",
onTap: () async {
startTimer();
// startTimer();
await EasyLoading.show(
status: Strings.pleaseWait,
maskType: EasyLoadingMaskType.none,
);
if (widget.isIn) {
Api.shiftIn(
ApiResponse apiResponse =
await Api.shiftIn(
widget.branchModel.id,
widget.nik,
widget.shiftModel!.id,
imageBase64!,
).then((apiResponse) {
stopTimer();
);
// stopTimer();
EasyLoading.dismiss();
if (apiResponse.error) {
// Start modal dialog konfirmasi kalau dia out of range
if (apiResponse.code ==
"DISTANCE_OUT_OF_RANGE") {
modalDialogGlobal(
context: context,
size:
MediaQuery.of(context).size,
title: "Konfirmasi",
contentBody: apiResponse.msg,
buttonText: "YA",
tapButtonOk: () async {
await EasyLoading.show(
status: Strings.pleaseWait,
maskType:
EasyLoadingMaskType
.none,
);
ApiResponse apiResponse =
await Api.shiftIn(
widget.branchModel.id,
widget.nik,
widget.shiftModel!.id,
imageBase64!,
forceSubmit: 1,
);
EasyLoading.dismiss();
if (apiResponse.error) {
modalDialogGlobal(
context: context,
size:
MediaQuery.of(context)
.size,
title: "Gagal",
contentBody:
apiResponse.msg,
buttonText: "OK",
tapButtonOk: () {
Navigator.pop(context);
Navigator.pop(context);
recallCamera();
},
);
return;
} else {
Navigator.pop(context);
AbsentSuccessModel
absentSuccess =
apiResponse.data
as AbsentSuccessModel;
Navigator
.pushNamedAndRemoveUntil(
context,
Routes.absentSuccess,
(route) => false,
arguments: AbsentSuccessArguments(
absentSuccess:
absentSuccess,
profil:
widget.profile,
nik: widget.nik,
isIn: true,
shiftName: widget
.shiftNameSelected,
shiftEnd: widget
.shiftEndTime,
shiftStart: widget
.shiftStartTime),
);
return;
}
},
isActiveCancelButton: true,
cancelButtonText: "Tidak",
tapButtonCancel: () {
// kalau pilih tidak, recall lagi camera suruh foto ulang
Navigator.pop(context);
recallCamera();
},
);
return;
}
// END modal dialog konfirmasi kalau dia out of range
modalDialogGlobal(
context: context,
size: MediaQuery.of(context).size,
title: "Gagal",
contentBody: apiResponse.msg,
buttonText: "OK",
......@@ -500,16 +584,99 @@ class _AbsentCameraViewState extends State<AbsentCameraView> {
shiftStart:
widget.shiftStartTime),
);
});
} else {
Api.shiftOut(
widget.branchModel.id,
widget.nik,
imageBase64!,
).then((apiResponse) {
stopTimer();
// stopTimer();
EasyLoading.dismiss();
if (apiResponse.error) {
// Start modal dialog konfirmasi kalau dia out of range
if (apiResponse.code ==
"DISTANCE_OUT_OF_RANGE") {
modalDialogGlobal(
context: context,
size: MediaQuery.of(context)
.size,
title: "Konfirmasi",
contentBody: apiResponse.msg,
buttonText: "YA",
tapButtonOk: () async {
await EasyLoading.show(
status:
Strings.pleaseWait,
maskType:
EasyLoadingMaskType
.none,
);
ApiResponse apiResponse =
await Api.shiftOut(
widget.branchModel.id,
widget.nik,
imageBase64!,
forceSubmit: 1,
);
EasyLoading.dismiss();
if (apiResponse.error) {
modalDialogGlobal(
context: context,
size: MediaQuery.of(
context)
.size,
title: "Gagal",
contentBody:
apiResponse.msg,
buttonText: "OK",
tapButtonOk: () {
Navigator.pop(
context);
Navigator.pop(
context);
recallCamera();
},
);
return;
} else {
Navigator.pop(context);
AbsentSuccessModel
absentSuccess =
apiResponse.data
as AbsentSuccessModel;
Navigator
.pushNamedAndRemoveUntil(
context,
Routes.absentSuccess,
(route) => false,
arguments: AbsentSuccessArguments(
absentSuccess:
absentSuccess,
profil:
widget.profile,
nik: widget.nik,
isIn: false,
shiftName: widget
.shiftNameSelected,
shiftEnd: widget
.shiftEndTime,
shiftStart: widget
.shiftStartTime),
);
return;
}
},
isActiveCancelButton: true,
cancelButtonText: "Tidak",
tapButtonCancel: () {
// kalau pilih tidak, recall lagi camera suruh foto ulang
Navigator.pop(context);
recallCamera();
},
);
return;
}
// END modal dialog konfirmasi kalau dia out of range
modalDialogGlobal(
context: context,
size:
......@@ -556,104 +723,6 @@ class _AbsentCameraViewState extends State<AbsentCameraView> {
recallCamera();
},
)
// Container(
// width: 100,
// child: CustomButton(
// text: "Submit",
// onTap: () async {
// // startTimer();
// await EasyLoading.show(
// status: Strings.pleaseWait,
// maskType: EasyLoadingMaskType.none,
// );
// if (widget.isIn) {
// Api.shiftIn(
// widget.branchModel.id,
// widget.nik,
// widget.shiftModel!.id,
// imageBase64!,
// ).then((apiResponse) {
// // stopTimer();
// EasyLoading.dismiss();
// if (apiResponse.error) {
// EasyLoading.showToast(
// apiResponse.msg);
// return;
// }
// AbsentSuccessModel absentSuccess =
// apiResponse.data
// as AbsentSuccessModel;
// Navigator.pushNamedAndRemoveUntil(
// context,
// Routes.absentSuccess,
// (route) => false,
// arguments: AbsentSuccessArguments(
// absentSuccess: absentSuccess,
// isIn: true,
// ),
// );
// });
// } else {
// Api.shiftOut(
// widget.branchModel.id,
// widget.nik,
// imageBase64!,
// ).then((apiResponse) {
// // stopTimer();
// EasyLoading.dismiss();
// if (apiResponse.error) {
// EasyLoading.showToast(
// apiResponse.msg,
// );
// return;
// }
// AbsentSuccessModel absentSuccess =
// apiResponse.data
// as AbsentSuccessModel;
// Navigator.pushNamedAndRemoveUntil(
// context,
// Routes.absentSuccess,
// (route) => false,
// arguments: AbsentSuccessArguments(
// absentSuccess: absentSuccess,
// isIn: false,
// ),
// );
// });
// }
// },
// ),
// ),
// Container(
// width: 100,
// margin: const EdgeInsets.only(
// top: 10,
// ),
// child: GestureDetector(
// onTap: () async {
// _controller?.dispose().then((_) {
// setState(() {});
// setState(() {
// pictureIsTaken = false;
// _controller = CameraController(
// // Get a specific camera from the list of available cameras.
// _cameraDescription!,
// // Define the resolution to use.
// ResolutionPreset.medium,
// imageFormatGroup:
// ImageFormatGroup.jpeg,
// enableAudio: false,
// );
// initCamera(_controller!);
// });
// });
// },
// child: CustomButton(
// text: "Foto Ulang",
// colorButton: ColorManager.grey,
// ),
// ),
// ),
],
),
)
......@@ -662,25 +731,6 @@ class _AbsentCameraViewState extends State<AbsentCameraView> {
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
// GestureDetector(
// onTap: () {
// if (flashMode ==
// FlashMode.always) {
// flashMode = FlashMode.off;
// } else {
// flashMode = FlashMode.always;
// }
// setState(() {
// _controller!
// .setFlashMode(flashMode);
// });
// },
// child: Icon(
// Icons.flash_auto,
// size: 35,
// color: ColorManager.primary,
// ),
// ),
const SizedBox(
width: 100,
),
......@@ -787,404 +837,6 @@ class _AbsentCameraViewState extends State<AbsentCameraView> {
),
],
)
// (isPermissionAccept) ?
// (_initializeControllerFuture != null)
// ? FutureBuilder(
// future: _initializeControllerFuture,
// builder: ((context, snapshot) {
// if (snapshot.connectionState == ConnectionState.done) {
// return Stack(
// children: [
// Container(
// width: size.width,
// height: size.height,
// padding: EdgeInsets.only(
// top: AppPadding.safeAreaTop(context) + 40),
// child: (pictureIsTaken)
// ? (isPhone)
// ? Image.file(
// File(imagePathPhone!),
// fit: BoxFit.fill,
// )
// : Image.memory(
// imagePath!,
// // fit: BoxFit.fill,
// )
// : CameraPreview(
// _controller!,
// ),
// ),
// Container(
// width: size.width,
// height: size.height,
// padding: EdgeInsets.only(
// top: AppPadding.safeAreaTop(context) + 40),
// child: Image(
// fit: BoxFit.fill,
// image: AssetImage(Assets.frameOverlay),
// ),
// ),
// Container(
// width: size.width,
// height: size.height,
// child: Column(
// children: [
// Container(
// height: AppPadding.safeAreaTop(context) + 60,
// width: double.infinity,
// decoration: BoxDecoration(
// borderRadius: const BorderRadius.only(
// bottomRight: Radius.circular(20),
// bottomLeft: Radius.circular(20),
// ),
// color: ColorManager.primary,
// ),
// child: Container(
// padding: EdgeInsets.symmetric(
// horizontal: AppPadding.p20),
// margin: EdgeInsets.only(
// top: AppPadding.safeAreaTop(context),
// ),
// child: Row(
// crossAxisAlignment:
// CrossAxisAlignment.center,
// children: [
// GestureDetector(
// onTap: () {
// Navigator.pop(context);
// },
// child: const Icon(
// Icons.arrow_back,
// color: Colors.white,
// size: 24,
// ),
// ),
// Container(
// margin: EdgeInsets.only(
// left: AppMargin.m16,
// ),
// child: Text(
// "Verifikasi Wajah (${cameras!.length})",
// style: getBoldStyle(
// color: Colors.white,
// fontSize: 17,
// ),
// ),
// )
// ],
// ),
// ),
// ),
// const SizedBox(
// height: 15,
// ),
// WidgetAbsentAndTime(
// isIn: widget.isIn,
// outletName: widget.branchModel.code,
// ),
// const Spacer(),
// (pictureIsTaken)
// ? Column(
// crossAxisAlignment:
// CrossAxisAlignment.center,
// children: [
// Container(
// width: 100,
// child: CustomButton(
// text: "Submit",
// onTap: () async {
// // startTimer();
// await EasyLoading.show(
// status: Strings.pleaseWait,
// maskType:
// EasyLoadingMaskType.none,
// );
// if (widget.isIn) {
// Api.shiftIn(
// widget.branchModel.id,
// widget.nik,
// widget.shiftModel!.id,
// imageBase64!,
// ).then((apiResponse) {
// // stopTimer();
// EasyLoading.dismiss();
// if (apiResponse.error) {
// EasyLoading.showToast(
// apiResponse.msg);
// return;
// }
// AbsentSuccessModel
// absentSuccess =
// apiResponse.data
// as AbsentSuccessModel;
// Navigator
// .pushNamedAndRemoveUntil(
// context,
// Routes.absentSuccess,
// (route) => false,
// arguments:
// AbsentSuccessArguments(
// absentSuccess:
// absentSuccess,
// isIn: true,
// ),
// );
// });
// } else {
// Api.shiftOut(
// widget.branchModel.id,
// widget.nik,
// imageBase64!,
// ).then((apiResponse) {
// // stopTimer();
// EasyLoading.dismiss();
// if (apiResponse.error) {
// EasyLoading.showToast(
// apiResponse.msg,
// );
// return;
// }
// AbsentSuccessModel
// absentSuccess =
// apiResponse.data
// as AbsentSuccessModel;
// Navigator
// .pushNamedAndRemoveUntil(
// context,
// Routes.absentSuccess,
// (route) => false,
// arguments:
// AbsentSuccessArguments(
// absentSuccess:
// absentSuccess,
// isIn: false,
// ),
// );
// });
// }
// },
// ),
// ),
// Container(
// width: 100,
// margin: const EdgeInsets.only(
// top: 10,
// ),
// child: GestureDetector(
// onTap: () {
// setState(() {
// pictureIsTaken = false;
// _controller = CameraController(
// // Get a specific camera from the list of available cameras.
// _cameraDescription!,
// // Define the resolution to use.
// ResolutionPreset.medium,
// imageFormatGroup:
// ImageFormatGroup.jpeg,
// );
// _initializeControllerFuture =
// _controller!.initialize();
// });
// },
// child: CustomButton(
// text: "Foto Ulang",
// colorButton: ColorManager.grey,
// ),
// ),
// ),
// ],
// )
// : Stack(
// children: [
// Row(
// mainAxisAlignment:
// MainAxisAlignment.center,
// children: [
// // GestureDetector(
// // onTap: () {
// // if (flashMode ==
// // FlashMode.always) {
// // flashMode = FlashMode.off;
// // } else {
// // flashMode = FlashMode.always;
// // }
// // setState(() {
// // _controller!
// // .setFlashMode(flashMode);
// // });
// // },
// // child: Icon(
// // Icons.flash_auto,
// // size: 35,
// // color: ColorManager.primary,
// // ),
// // ),
// const SizedBox(
// width: 100,
// ),
// InkWell(
// onTap: () async {
// try {
// await _initializeControllerFuture;
// // ambil imagenya
// XFile image =
// await _controller!
// .takePicture();
// String? imageResultPhone;
// Uint8List? imageResultWeb;
// if (isPhone) {
// imageResultPhone =
// image.path;
// imageResultWeb = await image
// .readAsBytes();
// } else {
// imageResultWeb = await image
// .readAsBytes();
// }
// // kalau gak ke ambil gak ngelakuin aksi apa2
// if (!mounted) return;
// setState(() {
// pictureIsTaken = true;
// imagePath = imageResultWeb;
// imagePathPhone =
// imageResultPhone;
// imageBase64 = base64Encode(
// imageResultWeb!);
// });
// } catch (e) {
// if (debug) {
// // ignore: avoid_print
// print(
// "TERJADI KESALAHAAN SAAT AMBIL GAMBER, ERROR: $e");
// }
// }
// },
// child: Container(
// width: 80,
// height: 80,
// decoration: BoxDecoration(
// borderRadius:
// BorderRadius.circular(
// 100),
// border: Border.all(
// width: 1.5,
// color: Colors.black,
// ),
// color: Colors.red,
// ),
// ),
// ),
// const SizedBox(
// width: 60,
// ),
// GestureDetector(
// onTap: () {
// if (cameras!.length > 1) {
// setState(() {
// if (_cameraDescription ==
// cameras![0]) {
// _cameraDescription =
// cameras![1];
// } else {
// _cameraDescription =
// cameras![0];
// }
// _controller =
// CameraController(
// // Get a specific camera from the list of available cameras.
// _cameraDescription!,
// // Define the resolution to use.
// ResolutionPreset.medium,
// imageFormatGroup:
// ImageFormatGroup.jpeg,
// );
// _initializeControllerFuture =
// _controller!
// .initialize();
// });
// } else {
// EasyLoading.showToast(
// "Kamera lain tidak terdeteksi");
// }
// },
// child: Icon(
// Icons.switch_camera_outlined,
// size: 35,
// color: ColorManager.primary,
// ),
// )
// ],
// ),
// ],
// ),
// const SizedBox(
// height: 30,
// )
// ],
// ),
// ),
// ],
// );
// } else {
// return const Center(child: CircularProgressIndicator());
// }
// }),
// )
// : const Center(child: CircularProgressIndicator())
// : Center(
// child: Padding(
// padding: EdgeInsets.symmetric(
// horizontal: AppPadding.p20,
// ),
// child: Column(
// children: [
// Text(
// "Silakan aktifkan permission kamera pada pengaturan browser anda",
// style: getBoldStyle(
// color: Colors.black,
// fontSize: 16,
// ),
// textAlign: TextAlign.center,
// ),
// (errorCamera != null)
// ? Container(
// margin: const EdgeInsets.only(
// top: 10,
// ),
// child: Text(
// "Error; $errorCamera",
// style: getBoldStyle(
// color: Colors.black,
// fontSize: 16,
// ),
// ),
// )
// : const SizedBox(),
// // const SizedBox(
// // height: 10,
// // ),
// // CustomButton(
// // text: "Aktifkan kamera",
// // onTap: () async {
// // final perm = await html.window.navigator.permissions!
// // .query({"name": "camera"});
// // if (perm.state == "denied") {
// // print("DENIED");
// // await html.window.navigator
// // .getUserMedia(audio: true, video: true);
// // return;
// // }
// // final stream = await html.window.navigator
// // .getUserMedia(video: true);
// // },
// // )
// ],
// ),
// ),
// )
],
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment