No Description
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.

history_cuti.dart 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. import 'dart:convert';
  2. import 'package:flutter/material.dart';
  3. import 'package:fluttertoast/fluttertoast.dart';
  4. import 'package:google_fonts/google_fonts.dart';
  5. import 'package:hris_selfservice_mobile/Screens/Menu/AjukanCuti/RequestHttp/historyCuti_post.dart';
  6. import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart';
  7. import 'dart:developer' as logDev;
  8. import '../AjukanCuti/backgroundHistory.dart';
  9. class HistoryCuti extends StatefulWidget {
  10. const HistoryCuti({Key? key}) : super(key: key);
  11. @override
  12. State<HistoryCuti> createState() => _HistoryCutiState();
  13. }
  14. class _HistoryCutiState extends State<HistoryCuti> {
  15. late List <String> id_List;
  16. late List <String> name_List;
  17. late List <String> type_cuti_List;
  18. late List <String> detail_List;
  19. late List <String> created_on_List;
  20. late List <String> created_by_List;
  21. late List <String> start_date_List;
  22. late List <String> end_date_List;
  23. late List <String> duration_List;
  24. late List <String> status_List;
  25. late List <Color> statusColor;
  26. late List <bool> visible;
  27. int HistoryLength = 0;
  28. @override
  29. initState() {
  30. super.initState();
  31. id_List = [""];
  32. name_List = [""];
  33. type_cuti_List = [""];
  34. detail_List = [""];
  35. created_on_List = [""];
  36. created_by_List = [""];
  37. start_date_List = [""];
  38. end_date_List = [""];
  39. duration_List = [""];
  40. status_List = [""];
  41. statusColor = [Colors.black54];
  42. visible = [false];
  43. WidgetsBinding.instance.addPostFrameCallback((_) async {
  44. getHistoryData();
  45. });
  46. logDev.log(HistoryLength.toString(), name: "Banyak History");
  47. }
  48. getHistoryData() async {
  49. ProgressDialog loading = ProgressDialog(context);
  50. loading = ProgressDialog(context,
  51. type: ProgressDialogType.normal, isDismissible: false, showLogs: true);
  52. loading.style(
  53. message: 'Please Wait .....',
  54. borderRadius: 3,
  55. backgroundColor: Colors.white,
  56. progressWidget: CircularProgressIndicator(),
  57. elevation: 10.0,
  58. padding: EdgeInsets.all(10),
  59. insetAnimCurve: Curves.easeInOut,
  60. progress: 0.0,
  61. maxProgress: 100.0,
  62. progressTextStyle: TextStyle(
  63. color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400),
  64. messageTextStyle: TextStyle(
  65. color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600));
  66. loading.show();
  67. HistoryCuti_Post.connectToAPI().then((valueResult) async {
  68. Map<String, dynamic> object = jsonDecode(valueResult);
  69. if (object.containsKey("result").toString() == "true") {
  70. String result = object['result'].toString();
  71. if (result.contains("Failed")) {
  72. loading.hide();
  73. alertDialogFailedRetrievedData(context);
  74. } else {
  75. List <dynamic> historyCuti = object['result'];
  76. /* logDev.log(historyCuti.toString(), name: "History Cuti");
  77. logDev.log(historyCuti.length.toString(), name: "Banyaknya History Cuti");*/
  78. setState(() {
  79. for (int i = 0; i < historyCuti.length; i++){
  80. String id = historyCuti[i]['id'].toString();
  81. String name = historyCuti[i]['name'].toString();
  82. String type_cuti = historyCuti[i]['type_cuti'].toString();
  83. String detail = historyCuti[i]['detail'].toString();
  84. String created_on = historyCuti[i]['created_on'].toString();
  85. String created_by = historyCuti[i]['created_by'].toString();
  86. String start_date = historyCuti[i]['start_date'].toString();
  87. String end_date = historyCuti[i]['end_date'].toString();
  88. String duration = historyCuti[i]['duration'].toString();
  89. String status = historyCuti[i]['status'].toString();
  90. if (detail == "false"){
  91. detail = "-";
  92. }
  93. id_List.add(id);
  94. name_List.add(name);
  95. type_cuti_List.add(type_cuti);
  96. detail_List.add(detail);
  97. created_on_List.add(created_on);
  98. created_by_List.add(created_by);
  99. start_date_List.add(start_date.substring(0,10));
  100. end_date_List.add(end_date.substring(0,10));
  101. duration_List.add(duration);
  102. status_List.add(status);
  103. visible.add(false);
  104. var statColor;
  105. if (status == "To Approve"){
  106. statColor = Colors.red;
  107. } else if (status == "Second Approval"){
  108. statColor = Colors.green;
  109. } else if (status == "Approved"){
  110. statColor = Colors.blueAccent;
  111. }
  112. statusColor.add(statColor);
  113. }
  114. id_List.removeAt(0);
  115. name_List.removeAt(0);
  116. type_cuti_List.removeAt(0);
  117. detail_List.removeAt(0);
  118. created_on_List.removeAt(0);
  119. created_by_List.removeAt(0);
  120. start_date_List.removeAt(0);
  121. end_date_List.removeAt(0);
  122. duration_List.removeAt(0);
  123. status_List.removeAt(0);
  124. statusColor.removeAt(0);
  125. visible.removeAt(0);
  126. HistoryLength = historyCuti.length;
  127. });
  128. loading.hide();
  129. }
  130. } else {
  131. Fluttertoast.showToast(
  132. msg: "Server Response Error",
  133. toastLength: Toast.LENGTH_SHORT,
  134. gravity: ToastGravity.CENTER,
  135. timeInSecForIosWeb: 1,
  136. textColor: Colors.white,
  137. fontSize: 16.0);
  138. }
  139. });
  140. loading.hide();
  141. }
  142. @override
  143. Widget build(BuildContext context) {
  144. var size = MediaQuery.of(context).size;
  145. return Scaffold(
  146. body: Stack(
  147. children: [
  148. Column(
  149. children: <Widget>[
  150. Stack(
  151. children: [
  152. WavyHeader(),
  153. Container(
  154. margin: EdgeInsets.only(top: (size.height / 6) - 20),
  155. padding: EdgeInsets.fromLTRB(0, 5, 25, 5),
  156. child: Row(
  157. mainAxisAlignment: MainAxisAlignment.end,
  158. crossAxisAlignment: CrossAxisAlignment.end,
  159. children: [
  160. Text(
  161. 'Time Off History\t\t',
  162. maxLines: 1,
  163. style: GoogleFonts.luckiestGuy(
  164. fontSize: 28,
  165. color: Colors.red,
  166. fontStyle: FontStyle.italic,
  167. ),
  168. ),
  169. Image.asset(
  170. 'assets/images/ic_history.png',
  171. width: 40,
  172. height: 40,
  173. ),
  174. ],
  175. )
  176. ),
  177. ],
  178. ),
  179. ],
  180. ),
  181. Container(
  182. margin: EdgeInsets.only(top: (MediaQuery.of(context).size.height / 6) + 40, left: 5, right: 5, bottom: 10),
  183. child: ListView.builder(
  184. scrollDirection: Axis.vertical,
  185. shrinkWrap: true,
  186. itemCount: HistoryLength,
  187. itemBuilder: (context, int i) {
  188. return Container(
  189. child: InkWell(
  190. child: Card(
  191. elevation: 10,
  192. child: Column(
  193. children: [
  194. Row(
  195. children: [
  196. Expanded(
  197. flex: 8,
  198. child: Padding(
  199. padding: EdgeInsets.fromLTRB(10, 5, 5, 5),
  200. child: Column(
  201. mainAxisAlignment: MainAxisAlignment.center,
  202. crossAxisAlignment: CrossAxisAlignment.start,
  203. children: [
  204. Text(type_cuti_List[i], style: GoogleFonts.rubikBubbles(fontSize: 16)),
  205. Text(start_date_List[i] + " - " + end_date_List[i] + " (" + duration_List[i] + ") ", style: GoogleFonts.nunito(fontSize: 15)),
  206. Text("\nDescription : " + detail_List[i], style: GoogleFonts.nunito(fontSize: 15)),
  207. Text("\nCreated : " + created_on_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)),
  208. ],
  209. ),
  210. )
  211. ),
  212. Expanded(
  213. flex: 2,
  214. child: Padding(
  215. padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
  216. child: Text(status_List[i], textAlign: TextAlign.center, style: GoogleFonts.lilitaOne(color: statusColor[i], fontSize: 17),
  217. ),
  218. )
  219. ),
  220. ],
  221. ),
  222. Align(
  223. alignment: Alignment.centerLeft,
  224. child: Visibility(
  225. visible: visible[i],
  226. child: Padding(
  227. padding: EdgeInsets.fromLTRB(10, 5, 5, 5),
  228. child: Column(
  229. mainAxisAlignment: MainAxisAlignment.start,
  230. crossAxisAlignment: CrossAxisAlignment.start,
  231. children: [
  232. Text("\nAttachment : ", style: GoogleFonts.josefinSans(fontSize: 15, fontWeight: FontWeight.bold)),
  233. Text("Created : " + created_on_List[i], style: GoogleFonts.nunito(fontSize: 15, fontStyle: FontStyle.italic)),
  234. ],
  235. ),
  236. )
  237. ),
  238. )
  239. ],
  240. ),
  241. ),
  242. onTap: (){
  243. setState(() {
  244. visible[i] = !visible[i];
  245. });
  246. },
  247. ),
  248. );
  249. },
  250. ),
  251. )
  252. ]),
  253. );
  254. }
  255. }
  256. alertDialogFailedRetrievedData(BuildContext context) {
  257. Widget okButton = TextButton(
  258. child: Text("Refresh"),
  259. onPressed: () {
  260. Navigator.of(context, rootNavigator: true).pop();
  261. Navigator.pushReplacement(
  262. context, MaterialPageRoute(builder: (context) => HistoryCuti()));
  263. },
  264. );
  265. Widget noButton = TextButton(
  266. child: Text("Back"),
  267. onPressed: () {
  268. Navigator.of(context, rootNavigator: true).pop();
  269. Navigator.pop(context);
  270. },
  271. );
  272. // set up the AlertDialog
  273. AlertDialog alert = AlertDialog(
  274. title: Text("Employee Self Service"),
  275. content: Text("Failed to Retrieve Data"),
  276. actions: [
  277. noButton,
  278. okButton,
  279. ],
  280. );
  281. // show the dialog
  282. showDialog(
  283. context: context,
  284. builder: (BuildContext context) {
  285. return alert;
  286. },
  287. );
  288. }