GSI - Employe Self Service Mobile
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1003 lines
33 KiB

2 months ago
  1. import 'dart:async';
  2. import 'dart:convert';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_map/flutter_map.dart';
  5. import 'package:geolocator/geolocator.dart';
  6. import 'package:google_fonts/google_fonts.dart';
  7. import 'package:employee_selfservice_mobile/Screens/Menu/Absensi/RequestHttp/checkIn_post.dart';
  8. import 'package:employee_selfservice_mobile/Screens/Menu/Absensi/RequestHttp/checkStatus_post.dart';
  9. import 'package:employee_selfservice_mobile/Screens/Menu/Absensi/absensi_history_screen.dart';
  10. import 'package:intl/intl.dart';
  11. import 'package:latlong2/latlong.dart' as latlong;
  12. import 'package:location/location.dart' as loc;
  13. import 'dart:developer' as logDev;
  14. import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart';
  15. import 'package:sliding_up_panel/sliding_up_panel.dart';
  16. import 'RequestHttp/checkOut_post.dart';
  17. import 'RequestHttp/historyAbsensi_post.dart';
  18. class AbsensiScreen extends StatefulWidget {
  19. const AbsensiScreen({Key? key}) : super(key: key);
  20. @override
  21. State<AbsensiScreen> createState() => _AbsensiScreenState();
  22. }
  23. class _AbsensiScreenState extends State<AbsensiScreen> {
  24. //Visibility Button Check In & Check Out
  25. bool visibleCheckIn = false;
  26. bool visibleCheckOut = false;
  27. latlong.LatLng point = latlong.LatLng(-6.183580253674716, 106.93103973792664);
  28. late Position position;
  29. late String showCheckIn_List;
  30. late String showCheckOut_List;
  31. MapController _mapController = MapController();
  32. @override
  33. void initState() {
  34. showCheckIn_List = "";
  35. showCheckOut_List = "";
  36. WidgetsBinding.instance.addPostFrameCallback((_) {
  37. determinePosition();
  38. });
  39. super.initState();
  40. }
  41. determinePosition() async {
  42. StreamSubscription<ServiceStatus> serviceStatusStream = Geolocator.getServiceStatusStream().listen(
  43. (ServiceStatus status) {
  44. print(status);
  45. });
  46. ProgressDialog loading = ProgressDialog(context);
  47. loading = ProgressDialog(context,
  48. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  49. loading.style(
  50. message: 'Please Wait .....',
  51. borderRadius: 3,
  52. backgroundColor: Colors.white,
  53. progressWidget: CircularProgressIndicator(),
  54. elevation: 10.0,
  55. padding: EdgeInsets.all(10),
  56. insetAnimCurve: Curves.easeInOut,
  57. progress: 0.0,
  58. maxProgress: 100.0,
  59. progressTextStyle: TextStyle(
  60. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  61. messageTextStyle: TextStyle(
  62. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  63. await loading.show();
  64. bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
  65. logDev.log(serviceEnabled.toString(), name: "ON/OFF LOCATION SERVICE");
  66. if (!serviceEnabled) {
  67. //return Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => AbsensiScreen()));
  68. //await loading.hide();
  69. //alertDialogEnableLocaionServices(context);
  70. return Future.error('Location services are disabled.');
  71. }
  72. LocationPermission permission = await Geolocator.checkPermission();
  73. if (permission == LocationPermission.deniedForever) {
  74. await loading.hide();
  75. //return Future.error('Location permissions are permanently denied, we cannot request permissions.');
  76. return alertDialogPermissionDeniedForever(context);
  77. } else if (permission == LocationPermission.denied) {
  78. permission = await Geolocator.requestPermission();
  79. if (permission != LocationPermission.whileInUse && permission != LocationPermission.always) {
  80. await loading.hide();
  81. //return Future.error('Location permissions are denied (actual value: $permission).');
  82. return alertDialogPermissionDenied(context);
  83. }
  84. }
  85. position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
  86. logDev.log(position.toString(), name: "Position GEOLOCATOR");
  87. if (position.isMocked) {
  88. await loading.hide();
  89. setState(() {
  90. alertDialogFakeGPSDetected(context);
  91. });
  92. } else {
  93. point = latlong.LatLng(position.latitude, position.longitude);
  94. logDev.log(point.toString(), name: "POINT GEOLOCATOR");
  95. _mapController.move(point, 18);
  96. //Check Status
  97. CheckStatus_Post.connectToAPI().then((valueResult) async {
  98. Map<String, dynamic> object = json.decode(valueResult);
  99. if (object.containsKey("result").toString() == "true") {
  100. String result = object['result'].toString();
  101. logDev.log(result, name: "Status Absensi Result");
  102. if (result.contains("not_checked_in")) {
  103. setState(() {
  104. visibleCheckIn = !visibleCheckIn;
  105. visibleCheckOut = visibleCheckOut;
  106. });
  107. await loading.hide();
  108. } else if (result.contains("checked_in")) {
  109. setState(() {
  110. visibleCheckIn = visibleCheckIn;
  111. visibleCheckOut = !visibleCheckOut;
  112. });
  113. await loading.hide();
  114. } else {
  115. setState(() {
  116. alertDialogFailedResponse(context);
  117. });
  118. await loading.hide();
  119. }
  120. } else {
  121. setState(() {
  122. alertDialogFailedResponse(context);
  123. });
  124. await loading.hide();
  125. }
  126. await loading.hide();
  127. });
  128. //History
  129. HistoryAbsensi_Post.connectToAPI().then((valueResult) async {
  130. Map<String, dynamic> object = jsonDecode(valueResult);
  131. if (object.containsKey("result").toString() == "true") {
  132. String result = object['result'].toString();
  133. if (result.contains("failed")) {
  134. await loading.hide();
  135. alertDialogFailedRetrievedData(context);
  136. } else {
  137. List <dynamic> historyAbsensi = object['result'];
  138. await loading.hide();
  139. setState(() {
  140. String check_in = historyAbsensi[0]['check_in'].toString();
  141. String check_out = historyAbsensi[0]['check_out'].toString();
  142. logDev.log(historyAbsensi[0]['check_in'].toString(), name: "CHECK IN TIME");
  143. if (check_in != "false") {
  144. //Convert UTC to Local Time - Check In Time
  145. DateTime checkInTime = DateFormat("yyyy-MM-dd HH:mm:ss").parse(
  146. check_in, true);
  147. String checkInTimeLocal = checkInTime.toLocal().toString();
  148. String showCheckInTime = checkInTimeLocal.substring(11, 19);
  149. //logDev.log(showCheckInTime.substring(0,5), name: "SHOW CHECK IN TIME");
  150. showCheckIn_List = showCheckInTime.substring(0, 5);
  151. } else if (check_in == "false") {
  152. String show_check_in = "-";
  153. showCheckIn_List = show_check_in;
  154. }
  155. if (check_out != "false") {
  156. //Convert UTC to Local Time - Check Out Time
  157. DateTime checkOutTime = DateFormat("yyyy-MM-dd HH:mm:ss").parse(
  158. check_out, true);
  159. String checkOutTimeLocal = checkOutTime.toLocal().toString();
  160. String showCheckOutTime = checkOutTimeLocal.substring(11, 19);
  161. //logDev.log(showCheckOutTime, name: "SHOW CHECK OUT TIME");
  162. showCheckOut_List = showCheckOutTime.substring(0, 5);
  163. } else if (check_out == "false") {
  164. String show_check_out = "-";
  165. showCheckOut_List = show_check_out;
  166. }
  167. });
  168. }
  169. } else {
  170. alertDialogFailedRetrievedData(context);
  171. }
  172. });
  173. }
  174. }
  175. updatePosition() async {
  176. ProgressDialog loading = ProgressDialog(context);
  177. loading = ProgressDialog(context,
  178. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  179. loading.style(
  180. message: 'Please Wait .....',
  181. borderRadius: 3,
  182. backgroundColor: Colors.white,
  183. progressWidget: CircularProgressIndicator(),
  184. elevation: 10.0,
  185. padding: EdgeInsets.all(10),
  186. insetAnimCurve: Curves.easeInOut,
  187. progress: 0.0,
  188. maxProgress: 100.0,
  189. progressTextStyle: TextStyle(
  190. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  191. messageTextStyle: TextStyle(
  192. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  193. bool serviceEnabled;
  194. LocationPermission permission;
  195. serviceEnabled = await Geolocator.isLocationServiceEnabled();
  196. if (!serviceEnabled) {
  197. await loading.hide();
  198. return Future.error('Location services are disabled.');
  199. }
  200. permission = await Geolocator.checkPermission();
  201. if (permission == LocationPermission.deniedForever) {
  202. await loading.hide();
  203. return alertDialogPermissionDeniedForever(context);
  204. } else if (permission == LocationPermission.denied) {
  205. permission = await Geolocator.requestPermission();
  206. if (permission != LocationPermission.whileInUse && permission != LocationPermission.always) {
  207. await loading.hide();
  208. return alertDialogPermissionDenied(context);
  209. }
  210. }
  211. position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
  212. if (position.isMocked) {
  213. await loading.hide();
  214. setState(() {
  215. alertDialogFakeGPSDetected(context);
  216. });
  217. } else {
  218. await loading.hide();
  219. setState((){
  220. point = latlong.LatLng(position.latitude, position.longitude);
  221. logDev.log(point.toString(), name: "UPDATE POINT GEOLOCATOR");
  222. _mapController.move(point, 18);
  223. });
  224. }
  225. }
  226. goCheckIn() async {
  227. ProgressDialog loading = ProgressDialog(context);
  228. loading = ProgressDialog(context,
  229. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  230. loading.style(
  231. message: 'Please Wait .....',
  232. borderRadius: 3,
  233. backgroundColor: Colors.white,
  234. progressWidget: CircularProgressIndicator(),
  235. elevation: 10.0,
  236. padding: EdgeInsets.all(10),
  237. insetAnimCurve: Curves.easeInOut,
  238. progress: 0.0,
  239. maxProgress: 100.0,
  240. progressTextStyle: TextStyle(
  241. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  242. messageTextStyle: TextStyle(
  243. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  244. await loading.show();
  245. position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
  246. if (position.isMocked) {
  247. await loading.hide();
  248. setState(() {
  249. alertDialogFakeGPSDetected(context);
  250. });
  251. } else {
  252. await loading.hide();
  253. setState((){
  254. point = latlong.LatLng(position.latitude, position.longitude);
  255. _mapController.move(point, 18);
  256. });
  257. }
  258. String coordinate = point.latitude.toString()+", "+ point.longitude.toString();
  259. CheckIn_Post.connectToAPI(coordinate).then((valueResult) async {
  260. Map<String, dynamic> object = json.decode(valueResult);
  261. if (object.containsKey("result").toString() == "true") {
  262. String result = object['result'].toString();
  263. logDev.log(result, name: "Check In Result");
  264. if (result.contains("failed")) {
  265. await loading.hide();
  266. setState(() {
  267. alertDialogFailedRetrievedData(context);
  268. });
  269. } else if (result.contains("Anda sudah check in")) {
  270. await loading.hide();
  271. setState(() {
  272. alertDialogFailedCheckIn(context);
  273. });
  274. } else {
  275. await loading.hide();
  276. setState(() {
  277. alertDialogSuccessCheckIn(context);
  278. });
  279. }
  280. } else {
  281. setState(() {
  282. alertDialogFailedResponse(context);
  283. });
  284. await loading.hide();
  285. }
  286. });
  287. }
  288. goCheckOut() async {
  289. ProgressDialog loading = ProgressDialog(context);
  290. loading = ProgressDialog(context,
  291. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  292. loading.style(
  293. message: 'Please Wait .....',
  294. borderRadius: 3,
  295. backgroundColor: Colors.white,
  296. progressWidget: CircularProgressIndicator(),
  297. elevation: 10.0,
  298. padding: EdgeInsets.all(10),
  299. insetAnimCurve: Curves.easeInOut,
  300. progress: 0.0,
  301. maxProgress: 100.0,
  302. progressTextStyle: TextStyle(
  303. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  304. messageTextStyle: TextStyle(
  305. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  306. await loading.show();
  307. position = await Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.high);
  308. if (position.isMocked) {
  309. await loading.hide();
  310. setState(() {
  311. alertDialogFakeGPSDetected(context);
  312. });
  313. } else {
  314. await loading.hide();
  315. setState((){
  316. point = latlong.LatLng(position.latitude, position.longitude);
  317. _mapController.move(point, 18);
  318. });
  319. }
  320. String coordinate = point.latitude.toString()+", "+ point.longitude.toString();
  321. CheckOut_Post.connectToAPI(coordinate).then((valueResult) async {
  322. Map<String, dynamic> object = json.decode(valueResult);
  323. if (object.containsKey("result").toString() == "true") {
  324. String result = object['result'].toString();
  325. logDev.log(result, name: "Check Out Result");
  326. if (result.contains("failed")) {
  327. await loading.hide();
  328. setState(() {
  329. alertDialogFailedRetrievedData(context);
  330. });
  331. } else if (result.contains("Anda belum check in")) {
  332. await loading.hide();
  333. setState(() {
  334. alertDialogFailedCheckOut(context);
  335. });
  336. } else {
  337. await loading.hide();
  338. setState(() {
  339. alertDialogSuccessCheckOut(context);
  340. });
  341. }
  342. } else {
  343. setState(() {
  344. alertDialogFailedResponse(context);
  345. });
  346. await loading.hide();
  347. }
  348. });
  349. }
  350. PanelController _panelController = PanelController();
  351. void togglePanel() => _panelController.isPanelOpen
  352. ? _panelController.close()
  353. : _panelController.open();
  354. @override
  355. Widget build(BuildContext context) {
  356. var size = MediaQuery.of(context).size;
  357. return Scaffold(
  358. body: SlidingUpPanel(
  359. controller: _panelController,
  360. parallaxEnabled: true,
  361. maxHeight: size.height * 0.5,
  362. minHeight: size.height * 0.3,
  363. body: Container (
  364. child: Stack(
  365. children: [
  366. FlutterMap(
  367. mapController: _mapController,
  368. options: new MapOptions(
  369. onTap: (p, point) async {}, center: point, zoom: 15),
  370. children: [
  371. TileLayer(
  372. minZoom: 1,
  373. maxZoom: 22,
  374. maxNativeZoom: 18,
  375. minNativeZoom: 1,
  376. backgroundColor: Colors.black54,
  377. urlTemplate:
  378. 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
  379. subdomains: ['a', 'b', 'c'],
  380. ),
  381. /*MarkerLayer(markers: [
  382. Marker(child: Container(
  383. child: Icon(
  384. Icons.location_on
  385. ),
  386. ),
  387. width: 135,
  388. height: 135,
  389. point: point,
  390. child: Container(
  391. child: Icon(
  392. Icons.location_on,
  393. color: Colors.red,
  394. ),
  395. ))
  396. ])*/
  397. MarkerLayer(
  398. markers: [
  399. Marker(
  400. width: 135,
  401. height: 135,
  402. point: point, // Ganti latitude dan longitude dengan nilai yang sesuai
  403. child: Container(
  404. child: Icon(
  405. Icons.location_on,
  406. color: Colors.red,
  407. ),
  408. ),
  409. ),
  410. ],
  411. )
  412. ],
  413. ),
  414. Container(
  415. alignment: AlignmentDirectional.bottomEnd,
  416. child: Container(
  417. margin: EdgeInsets.fromLTRB(10, 15, 0, (size.height*0.3) + 15),
  418. child: RawMaterialButton(
  419. onPressed: () {
  420. setState(() {
  421. updatePosition();
  422. });
  423. },
  424. elevation: 5.0,
  425. fillColor: Colors.white,
  426. child: Image.asset('assets/images/location1.png',
  427. height: 40, width: 40),
  428. padding: EdgeInsets.all(5.0),
  429. shape: CircleBorder(),
  430. ),
  431. ),
  432. ),
  433. ],
  434. ),
  435. ),
  436. panel: Center(
  437. child: Column(
  438. children: [
  439. GestureDetector(
  440. onTap: togglePanel,
  441. child: Center(
  442. child: Container(
  443. margin: EdgeInsets.only(top: 15),
  444. height: 5,
  445. width: size.width * 0.1,
  446. decoration: BoxDecoration(
  447. borderRadius: BorderRadius.circular(10),
  448. color: Colors.grey
  449. ),
  450. ),
  451. ),
  452. ),
  453. Container(
  454. margin: EdgeInsets.only(top: 15),
  455. child: Center(
  456. child: Text(
  457. 'ATTENDANCE',
  458. maxLines: 1,
  459. style: GoogleFonts.luckiestGuy(
  460. fontSize: 28,
  461. color: Color(0xFF4858A7),
  462. fontStyle: FontStyle.italic,
  463. ),
  464. ),
  465. ),
  466. ),
  467. Container(
  468. width: double.infinity,
  469. margin: EdgeInsets.fromLTRB(10, 15, 10, 10),
  470. decoration:
  471. BoxDecoration(border: Border.all(color: Colors.black), borderRadius: BorderRadius.all(Radius.circular(15))),
  472. child: Column(
  473. children: <Widget>[
  474. Container(
  475. child: Text(
  476. "Last Attendance",
  477. style: GoogleFonts.patrickHand(
  478. fontSize: 21, color: Colors.white),
  479. ),
  480. width: double.infinity,
  481. alignment: Alignment.center,
  482. decoration: BoxDecoration(
  483. gradient: LinearGradient(
  484. begin: Alignment.topRight,
  485. end: Alignment.bottomRight,
  486. colors: [
  487. /*Color(0xFFD21404),
  488. Color(0xFFFD7267),*/
  489. Color(0xFF4858A7),
  490. Color(0xFF6474C6),
  491. ]),
  492. border: Border.all(color: Colors.black), borderRadius: BorderRadius.only(topLeft: Radius.circular(15), topRight: Radius.circular(15))),
  493. ),
  494. Container(
  495. width: double.infinity,
  496. padding: EdgeInsets.all(15),
  497. decoration:
  498. BoxDecoration(border: Border.all(color: Colors.black), borderRadius: BorderRadius.only(bottomLeft: Radius.circular(15), bottomRight: Radius.circular(15))),
  499. child: Column(
  500. children: [
  501. Row(
  502. mainAxisAlignment: MainAxisAlignment.spaceAround,
  503. children: [
  504. Expanded(
  505. flex: 5,
  506. child: Column(
  507. children: [
  508. Text('Check In',
  509. style: GoogleFonts.fredoka(
  510. fontSize: 19)),
  511. Text(showCheckIn_List,
  512. style: GoogleFonts.barlowSemiCondensed(
  513. fontSize: 19)),
  514. ],
  515. )),
  516. Expanded(
  517. flex: 5,
  518. child: Column(
  519. children: [
  520. Text('Check Out',
  521. style: GoogleFonts.fredoka(
  522. fontSize: 19)),
  523. Text(showCheckOut_List,
  524. style: GoogleFonts.barlowSemiCondensed(
  525. fontSize: 19)),
  526. ],
  527. )),
  528. ],
  529. ),
  530. Row(
  531. children: [
  532. Visibility(
  533. visible: visibleCheckIn,
  534. child: Container(
  535. margin: EdgeInsets.fromLTRB(0, 10, 0, 0),
  536. width: size.width - 54,
  537. child: ElevatedButton(
  538. onPressed: () {
  539. goCheckIn();
  540. },
  541. child: Text('Check In'),
  542. style: ButtonStyle(
  543. backgroundColor: MaterialStateProperty.all(
  544. Color(0xFF6474C6))),
  545. ),
  546. ),
  547. ),
  548. Visibility(
  549. visible: visibleCheckOut,
  550. child: Container(
  551. margin: EdgeInsets.fromLTRB(0, 10, 0, 0),
  552. width: size.width - 54,
  553. child: ElevatedButton(
  554. onPressed: () {
  555. goCheckOut();
  556. },
  557. child: Text('Check Out'),
  558. style: ButtonStyle(
  559. backgroundColor: MaterialStateProperty.all(
  560. Color(0xFF6474C6))),
  561. ),
  562. ),
  563. ),
  564. ],
  565. )
  566. ],
  567. ),
  568. )
  569. ],
  570. ),
  571. ),
  572. Container(
  573. margin: EdgeInsets.fromLTRB(10, 15, 10, 15),
  574. child: InkWell(
  575. child: Container(
  576. padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
  577. width: double.infinity,
  578. decoration: BoxDecoration(
  579. borderRadius: BorderRadius.circular(5),
  580. gradient: LinearGradient(colors: [
  581. Color(0xFF2D4059),
  582. Color(0xFF2D4059),
  583. /*Color(0xFFEAFFD0),
  584. Color(0xFF95E1D3),*/
  585. ])),
  586. child: Row(
  587. mainAxisAlignment: MainAxisAlignment.center,
  588. children: [
  589. Text(' See Attendance History \t\t',
  590. textAlign: TextAlign.center,
  591. style: TextStyle(
  592. color: Colors.white,
  593. fontSize: 17,
  594. fontWeight: FontWeight.w500)),
  595. Image.asset(
  596. 'assets/images/ic_arrow_white.png',
  597. width: 30,
  598. height: 30,
  599. )
  600. ],
  601. )),
  602. onTap: () {
  603. Navigator.push(
  604. context,
  605. MaterialPageRoute(
  606. builder: (context) => HistoryAbsensi()));
  607. },
  608. ),
  609. )
  610. ],
  611. ),
  612. ),
  613. borderRadius: BorderRadius.only(topLeft: Radius.circular(15), topRight: Radius.circular(15)),
  614. ),
  615. );
  616. }
  617. }
  618. alertDialogFailedRetrievedData(BuildContext context) {
  619. Widget okButton = TextButton(
  620. child: Text("Refresh"),
  621. onPressed: () {
  622. Navigator.of(context, rootNavigator: true).pop();
  623. Navigator.pushReplacement(
  624. context, MaterialPageRoute(builder: (context) => AbsensiScreen()));
  625. },
  626. );
  627. Widget noButton = TextButton(
  628. child: Text("Back"),
  629. onPressed: () {
  630. Navigator.of(context, rootNavigator: true).pop();
  631. Navigator.pop(context);
  632. },
  633. );
  634. // set up the AlertDialog
  635. AlertDialog alert = AlertDialog(
  636. title: Text("Employee Self Service"),
  637. content: Text("Failed to Retrieve Data"),
  638. actions: [
  639. noButton,
  640. okButton,
  641. ],
  642. );
  643. // show the dialog
  644. showDialog(
  645. context: context,
  646. barrierDismissible: false,
  647. builder: (BuildContext context) {
  648. return alert;
  649. },
  650. );
  651. }
  652. alertDialogFailedResponse(BuildContext context) {
  653. Widget okButton = TextButton(
  654. child: Text("Refresh"),
  655. onPressed: () {
  656. Navigator.of(context, rootNavigator: true).pop();
  657. Navigator.pushReplacement(
  658. context, MaterialPageRoute(builder: (context) => AbsensiScreen()));
  659. },
  660. );
  661. Widget noButton = TextButton(
  662. child: Text("Back"),
  663. onPressed: () {
  664. Navigator.of(context, rootNavigator: true).pop();
  665. Navigator.pop(context);
  666. },
  667. );
  668. // set up the AlertDialog
  669. AlertDialog alert = AlertDialog(
  670. title: Text("Employee Self Service"),
  671. content: Text("Server Response Error"),
  672. actions: [
  673. noButton,
  674. okButton,
  675. ],
  676. );
  677. // show the dialog
  678. showDialog(
  679. context: context,
  680. barrierDismissible: false,
  681. builder: (BuildContext context) {
  682. return alert;
  683. },
  684. );
  685. }
  686. alertDialogSuccessCheckIn(BuildContext context) {
  687. Widget okButton = TextButton(
  688. child: Text("Ok"),
  689. onPressed: () {
  690. Navigator.of(context, rootNavigator: true).pop();
  691. Navigator.pushReplacement(
  692. context, MaterialPageRoute(builder: (context) => AbsensiScreen()));
  693. },
  694. );
  695. // set up the AlertDialog
  696. AlertDialog alert = AlertDialog(
  697. title: Text("Employee Self Service"),
  698. content: Text("Successfully Checked In"),
  699. actions: [
  700. okButton,
  701. ],
  702. );
  703. // show the dialog
  704. showDialog(
  705. context: context,
  706. barrierDismissible: false,
  707. builder: (BuildContext context) {
  708. return alert;
  709. },
  710. );
  711. }
  712. alertDialogSuccessCheckOut(BuildContext context) {
  713. Widget okButton = TextButton(
  714. child: Text("Ok"),
  715. onPressed: () {
  716. Navigator.of(context, rootNavigator: true).pop();
  717. Navigator.pushReplacement(
  718. context, MaterialPageRoute(builder: (context) => AbsensiScreen()));
  719. },
  720. );
  721. // set up the AlertDialog
  722. AlertDialog alert = AlertDialog(
  723. title: Text("Employee Self Service"),
  724. content: Text("Successfully Checked Out"),
  725. actions: [
  726. okButton,
  727. ],
  728. );
  729. // show the dialog
  730. showDialog(
  731. context: context,
  732. barrierDismissible: false,
  733. builder: (BuildContext context) {
  734. return alert;
  735. },
  736. );
  737. }
  738. alertDialogFailedCheckIn(BuildContext context) {
  739. Widget okButton = TextButton(
  740. child: Text("Ok"),
  741. onPressed: () {
  742. Navigator.of(context, rootNavigator: true).pop();
  743. Navigator.pushReplacement(
  744. context, MaterialPageRoute(builder: (context) => AbsensiScreen()));
  745. },
  746. );
  747. // set up the AlertDialog
  748. AlertDialog alert = AlertDialog(
  749. title: Text("Employee Self Service"),
  750. content: Text("You've already checked in"),
  751. actions: [
  752. okButton,
  753. ],
  754. );
  755. // show the dialog
  756. showDialog(
  757. context: context,
  758. barrierDismissible: false,
  759. builder: (BuildContext context) {
  760. return alert;
  761. },
  762. );
  763. }
  764. alertDialogFailedCheckOut(BuildContext context) {
  765. Widget okButton = TextButton(
  766. child: Text("Ok"),
  767. onPressed: () {
  768. Navigator.of(context, rootNavigator: true).pop();
  769. Navigator.pushReplacement(
  770. context, MaterialPageRoute(builder: (context) => AbsensiScreen()));
  771. },
  772. );
  773. // set up the AlertDialog
  774. AlertDialog alert = AlertDialog(
  775. title: Text("Employee Self Service"),
  776. content: Text("You haven't checked in"),
  777. actions: [
  778. okButton,
  779. ],
  780. );
  781. // show the dialog
  782. showDialog(
  783. context: context,
  784. barrierDismissible: false,
  785. builder: (BuildContext context) {
  786. return alert;
  787. },
  788. );
  789. }
  790. alertDialogFakeGPSDetected(BuildContext context) {
  791. Widget okButton = TextButton(
  792. child: Text("Refresh"),
  793. onPressed: () {
  794. Navigator.of(context, rootNavigator: true).pop();
  795. Navigator.pushReplacement(
  796. context, MaterialPageRoute(builder: (context) => AbsensiScreen()));
  797. },
  798. );
  799. // set up the AlertDialog
  800. AlertDialog alert = AlertDialog(
  801. title: Text("Employee Self Service"),
  802. content: Text("Fake GPS Detected, Please Use Default GPS!"),
  803. actions: [
  804. okButton,
  805. ],
  806. );
  807. // show the dialog
  808. showDialog(
  809. context: context,
  810. barrierDismissible: false,
  811. builder: (BuildContext context) {
  812. return alert;
  813. },
  814. );
  815. }
  816. alertDialogPermissionDenied(BuildContext context) {
  817. Widget okButton = TextButton(
  818. child: Text("Refresh"),
  819. onPressed: () {
  820. Navigator.of(context, rootNavigator: true).pop();
  821. Navigator.pushReplacement(
  822. context, MaterialPageRoute(builder: (context) => AbsensiScreen()));
  823. },
  824. );
  825. Widget noButton = TextButton(
  826. child: Text("Back"),
  827. onPressed: () {
  828. Navigator.of(context, rootNavigator: true).pop();
  829. Navigator.pop(context);
  830. },
  831. );
  832. // set up the AlertDialog
  833. AlertDialog alert = AlertDialog(
  834. title: Text("Employee Self Service"),
  835. content:
  836. Text("Location permissions are denied, we cannot request permissions"),
  837. actions: [
  838. noButton,
  839. okButton,
  840. ],
  841. );
  842. // show the dialog
  843. showDialog(
  844. context: context,
  845. barrierDismissible: false,
  846. builder: (BuildContext context) {
  847. return alert;
  848. },
  849. );
  850. }
  851. alertDialogPermissionDeniedForever(BuildContext context) {
  852. Widget noButton = TextButton(
  853. child: Text("Back"),
  854. onPressed: () {
  855. Navigator.of(context, rootNavigator: true).pop();
  856. Navigator.pop(context);
  857. },
  858. );
  859. // set up the AlertDialog
  860. AlertDialog alert = AlertDialog(
  861. title: Text("Employee Self Service"),
  862. content: Text(
  863. "Location permissions are permanently denied, we cannot request permissions. Please configure it in your device settings."),
  864. actions: [noButton],
  865. );
  866. // show the dialog
  867. showDialog(
  868. context: context,
  869. barrierDismissible: false,
  870. builder: (BuildContext context) {
  871. return alert;
  872. },
  873. );
  874. }
  875. alertDialogEnableLocaionServices(BuildContext context) {
  876. ProgressDialog loading = ProgressDialog(context);
  877. loading = ProgressDialog(context,
  878. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  879. loading.style(
  880. message: 'Please Wait .....',
  881. borderRadius: 3,
  882. backgroundColor: Colors.white,
  883. progressWidget: CircularProgressIndicator(),
  884. elevation: 10.0,
  885. padding: EdgeInsets.all(10),
  886. insetAnimCurve: Curves.easeInOut,
  887. progress: 0.0,
  888. maxProgress: 100.0,
  889. progressTextStyle: TextStyle(
  890. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  891. messageTextStyle: TextStyle(
  892. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  893. Widget okButton = TextButton(
  894. child: Text("Open Settings"),
  895. onPressed: () {
  896. //AppSettings.openLocationSettings();
  897. Navigator.of(context, rootNavigator: true).pop();
  898. loading.hide();
  899. /* Navigator.pushReplacement(
  900. context, MaterialPageRoute(builder: (context) => AbsensiScreen()));*/
  901. },
  902. );
  903. Widget noButton = TextButton(
  904. child: Text("No, thanks"),
  905. onPressed: () {
  906. Navigator.of(context, rootNavigator: true).pop();
  907. Navigator.pop(context);
  908. loading.hide();
  909. },
  910. );
  911. // set up the AlertDialog
  912. AlertDialog alert = AlertDialog(
  913. title: Text("Employee Self Service"),
  914. content:
  915. Text("For a better experience, please turn on your device location"),
  916. actions: [
  917. noButton,
  918. okButton,
  919. ],
  920. );
  921. // show the dialog
  922. showDialog(
  923. context: context,
  924. barrierDismissible: false,
  925. builder: (BuildContext context) {
  926. return alert;
  927. },
  928. );
  929. }