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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  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(
  155. top: (size.height / 6) - 20),
  156. padding: EdgeInsets.fromLTRB(0, 5, 25, 5),
  157. child: Row(
  158. mainAxisAlignment: MainAxisAlignment.end,
  159. crossAxisAlignment: CrossAxisAlignment.end,
  160. children: [
  161. Text(
  162. 'Riwayat Cuti\t\t',
  163. maxLines: 1,
  164. style: GoogleFonts.luckiestGuy(
  165. fontSize: 28,
  166. color: Colors.red,
  167. fontStyle: FontStyle.italic,
  168. ),
  169. ),
  170. Image.asset(
  171. 'assets/images/ic_history.png',
  172. width: 40,
  173. height: 40,
  174. ),
  175. ],
  176. )
  177. ),
  178. ],
  179. ),
  180. ],
  181. ),
  182. Container(
  183. margin: EdgeInsets.only(top: (MediaQuery.of(context).size.height / 6) + 40, left: 5, right: 5, bottom: 10),
  184. child: ListView.builder(
  185. scrollDirection: Axis.vertical,
  186. shrinkWrap: true,
  187. itemCount: HistoryLength,
  188. itemBuilder: (context, int i) {
  189. return Container(
  190. child: InkWell(
  191. child: Card(
  192. elevation: 10,
  193. child: Column(
  194. children: [
  195. Row(
  196. children: [
  197. Expanded(
  198. flex: 8,
  199. child: Padding(
  200. padding: EdgeInsets.fromLTRB(10, 5, 5, 5),
  201. child: Column(
  202. mainAxisAlignment: MainAxisAlignment.center,
  203. crossAxisAlignment: CrossAxisAlignment.start,
  204. children: [
  205. Text(type_cuti_List[i], style: GoogleFonts.rubikBubbles(fontSize: 16)),
  206. Text(start_date_List[i] + " - " + end_date_List[i] + " (" + duration_List[i] + ") ", style: GoogleFonts.nunito(fontSize: 15)),
  207. Text("\nKeterangan : " + detail_List[i], style: GoogleFonts.nunito(fontSize: 15)),
  208. Text("\nCreated : " + created_on_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)),
  209. ],
  210. ),
  211. )
  212. ),
  213. Expanded(
  214. flex: 2,
  215. child: Padding(
  216. padding: EdgeInsets.fromLTRB(5, 5, 5, 5),
  217. child: Text(status_List[i], style: GoogleFonts.lilitaOne(color: statusColor[i], fontSize: 17),
  218. ),
  219. )
  220. ),
  221. ],
  222. ),
  223. Align(
  224. alignment: Alignment.centerLeft,
  225. child: Visibility(
  226. visible: visible[i],
  227. child: Padding(
  228. padding: EdgeInsets.fromLTRB(10, 5, 5, 5),
  229. child: Column(
  230. mainAxisAlignment: MainAxisAlignment.start,
  231. crossAxisAlignment: CrossAxisAlignment.start,
  232. children: [
  233. Text("\nAttachment : ", style: GoogleFonts.josefinSans(fontSize: 15, fontWeight: FontWeight.bold)),
  234. Text("Created : " + created_on_List[i], style: GoogleFonts.nunito(fontSize: 15, fontStyle: FontStyle.italic)),
  235. ],
  236. ),
  237. )
  238. ),
  239. )
  240. ],
  241. ),
  242. ),
  243. onTap: (){
  244. setState(() {
  245. visible[i] = !visible[i];
  246. });
  247. },
  248. ),
  249. );
  250. },
  251. ),
  252. )
  253. ]),
  254. );
  255. }
  256. }
  257. alertDialogFailedRetrievedData(BuildContext context) {
  258. Widget okButton = TextButton(
  259. child: Text("Refresh"),
  260. onPressed: () {
  261. Navigator.of(context, rootNavigator: true).pop();
  262. Navigator.pushReplacement(
  263. context, MaterialPageRoute(builder: (context) => HistoryCuti()));
  264. },
  265. );
  266. Widget noButton = TextButton(
  267. child: Text("Back"),
  268. onPressed: () {
  269. Navigator.of(context, rootNavigator: true).pop();
  270. Navigator.pop(context);
  271. },
  272. );
  273. // set up the AlertDialog
  274. AlertDialog alert = AlertDialog(
  275. title: Text("Employee Self Service"),
  276. content: Text("Failed to Retrieve Data"),
  277. actions: [
  278. noButton,
  279. okButton,
  280. ],
  281. );
  282. // show the dialog
  283. showDialog(
  284. context: context,
  285. builder: (BuildContext context) {
  286. return alert;
  287. },
  288. );
  289. }