import 'dart:convert'; import 'dart:ui'; import 'package:flutter/material.dart'; import 'package:fluttertoast/fluttertoast.dart'; import 'package:google_fonts/google_fonts.dart'; import 'package:hris_selfservice_mobile/Screens/Menu/SuratTugas/RequestHttp/detailST_post.dart'; import 'package:hris_selfservice_mobile/Screens/Menu/SuratTugas/RequestHttp/historyST_post.dart'; import 'package:progress_dialog_null_safe/progress_dialog_null_safe.dart'; import 'dart:developer' as logDev; import '../AjukanCuti/backgroundHistory.dart'; class HistoryST extends StatefulWidget { const HistoryST({Key? key}) : super(key: key); @override State createState() => _HistoryST(); } class _HistoryST extends State { late List id_List; late List number_List; late List keperluan_List; late List tglDibuat_List; late List status_List; late List tglST_List; late List uMuka_List; late List tglBerangkat_List; late List tglKembali_List; late List tujuan_List; late List ticketType_List; late List ticketFrom_List; late List ticketTo_List; late List ticketDate_List; late List ticketPrice_List; late List statusColor; late List visible; int HistoryLength = 0; @override initState() { id_List = [""]; number_List = [""]; keperluan_List = [""]; tglDibuat_List = [""]; status_List = [""]; tglST_List = [""]; uMuka_List = [""]; tglBerangkat_List = [""]; tglKembali_List = [""]; tujuan_List = [""]; ticketType_List = [""]; ticketFrom_List = [""]; ticketTo_List = [""]; ticketDate_List = [""]; ticketPrice_List = [""]; statusColor = [Colors.black54]; visible = [false]; WidgetsBinding.instance.addPostFrameCallback((_) async { getHistoryData(); }); } getHistoryData() async { ProgressDialog loading = ProgressDialog(context); loading = ProgressDialog(context, type: ProgressDialogType.normal, isDismissible: false, showLogs: true); loading.style( message: 'Please Wait .....', borderRadius: 3, backgroundColor: Colors.white, progressWidget: CircularProgressIndicator(), elevation: 10.0, padding: EdgeInsets.all(10), insetAnimCurve: Curves.easeInOut, progress: 0.0, maxProgress: 100.0, progressTextStyle: TextStyle( color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400), messageTextStyle: TextStyle( color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600)); loading.show(); HistoryST_Post.connectToAPI().then((valueResult) async { Map object = jsonDecode(valueResult); if (object.containsKey("result").toString() == "true") { String result = object['result'].toString(); if (result.contains("failed")) { loading.hide(); alertDialogFailedRetrievedData(context); } else { List historyST = object['result']; setState(() { for (int i = 0; i < historyST.length; i++){ String id = historyST[i]['id'].toString(); String number = historyST[i]['number'].toString(); String keperluan = historyST[i]['keperluan'].toString(); String tglDibuat = historyST[i]['tgl_dibuat'].toString(); String status = historyST[i]['status'].toString(); id_List.add(id); number_List.add(number); keperluan_List.add(keperluan); tglDibuat_List.add(tglDibuat); status_List.add(status); visible.add(false); var statColor; if (status == "draft"){ statColor = Colors.red; } else if (status == "approved"){ statColor = Colors.green; } else if (status == "advacanced"){ statColor = Colors.orangeAccent; } else if (status == "done"){ statColor = Colors.blueAccent; } else if (status == "close"){ statColor = Colors.deepPurple; } statusColor.add(statColor); } id_List.removeAt(0); number_List.removeAt(0); keperluan_List.removeAt(0); tglDibuat_List.removeAt(0); status_List.removeAt(0); statusColor.removeAt(0); visible.removeAt(0); HistoryLength = historyST.length; logDev.log(HistoryLength.toString(), name: "HISTORY LENGTH"); for (int i = 0; i < HistoryLength;i++){ DetailST_Post.connectToAPI(id_List[i]).then((valueResult) async { Map object = jsonDecode(valueResult); if (object.containsKey("result").toString() == "true") { String result = object['result'].toString(); if (result.contains("failed")) { loading.hide(); alertDialogFailedRetrievedData(context); } else { List detailST = object['result']; loading.hide(); setState(() { for (int j = 0; j < HistoryLength; j++){ String tglST = detailST[j]['tgl_st'].toString(); String uMuka = detailST[j]['umuka'].toString(); String tglBerangkat = detailST[j]['tgl_berangkat'].toString(); String tglKembali = detailST[j]['tgl_kembali'].toString(); String tujuan = detailST[j]['tujuan'].toString(); List ticketID = object['result']['ticket_ids']; String ticketType = ticketID[j]['type'].toString(); String ticketFrom = ticketID[j]['from'].toString(); String ticketTo = ticketID[j]['to'].toString(); String ticketDate = ticketID[j]['tgl'].toString(); String ticketPrice = ticketID[j]['harga'].toString(); tglST_List.add(tglST); uMuka_List.add(uMuka); tglBerangkat_List.add(tglBerangkat); tglKembali_List.add(tglKembali); tujuan_List.add(tujuan); ticketType_List.add(ticketType); ticketFrom_List.add(ticketFrom); ticketTo_List.add(ticketTo); ticketDate_List.add(ticketDate); ticketPrice_List.add(ticketPrice); logDev.log(tglST_List.toString(), name:"semua list"); } }); } } else { Fluttertoast.showToast( msg: "Server Response Error", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); } }); } tglST_List.removeAt(0); uMuka_List.removeAt(0); tglBerangkat_List.removeAt(0); tglKembali_List.removeAt(0); tujuan_List.removeAt(0); ticketType_List.removeAt(0); ticketFrom_List.removeAt(0); ticketTo_List.removeAt(0); ticketDate_List.removeAt(0); ticketPrice_List.removeAt(0); loading.hide(); }); } } else { Fluttertoast.showToast( msg: "Server Response Error", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); } loading.hide(); }); } /*getDetailData() async { ProgressDialog loading = ProgressDialog(context); loading = ProgressDialog(context, type: ProgressDialogType.normal, isDismissible: false, showLogs: true); loading.style( message: 'Please Wait .....', borderRadius: 3, backgroundColor: Colors.white, progressWidget: CircularProgressIndicator(), elevation: 10.0, padding: EdgeInsets.all(10), insetAnimCurve: Curves.easeInOut, progress: 0.0, maxProgress: 100.0, progressTextStyle: TextStyle( color: Colors.black, fontSize: 10.0, fontWeight: FontWeight.w400), messageTextStyle: TextStyle( color: Colors.black, fontSize: 15.0, fontWeight: FontWeight.w600)); logDev.log(HistoryLength.toString(), name: "Banyak History"); for (int i = 0; i < HistoryLength;i++){ DetailST_Post.connectToAPI(id_List[i]).then((valueResult) async { Map object = jsonDecode(valueResult); if (object.containsKey("result").toString() == "true") { String result = object['result'].toString(); if (result.contains("failed")) { loading.hide(); alertDialogFailedRetrievedData(context); } else { List detailST = object['result']; loading.hide(); setState(() { for (int j = 0; j < HistoryLength; j++){ String tglST = detailST[j]['tgl_st'].toString(); String uMuka = detailST[j]['umuka'].toString(); String tglBerangkat = detailST[j]['tgl_berangkat'].toString(); String tglKembali = detailST[j]['tgl_kembali'].toString(); String tujuan = detailST[j]['tujuan'].toString(); List ticketID = object['result']['ticket_ids']; String ticketType = ticketID[j]['type'].toString(); String ticketFrom = ticketID[j]['from'].toString(); String ticketTo = ticketID[j]['to'].toString(); String ticketDate = ticketID[j]['tgl'].toString(); String ticketPrice = ticketID[j]['harga'].toString(); tglST_List.add(tglST); uMuka_List.add(uMuka); tglBerangkat_List.add(tglBerangkat); tglKembali_List.add(tglKembali); tujuan_List.add(tujuan); ticketType_List.add(ticketType); ticketFrom_List.add(ticketFrom); ticketTo_List.add(ticketTo); ticketDate_List.add(ticketDate); ticketPrice_List.add(ticketPrice); logDev.log(tglST_List.toString(), name:"semua list"); } }); } } else { Fluttertoast.showToast( msg: "Server Response Error", toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.CENTER, timeInSecForIosWeb: 1, textColor: Colors.white, fontSize: 16.0); } }); } tglST_List.removeAt(0); uMuka_List.removeAt(0); tglBerangkat_List.removeAt(0); tglKembali_List.removeAt(0); tujuan_List.removeAt(0); ticketType_List.removeAt(0); ticketFrom_List.removeAt(0); ticketTo_List.removeAt(0); ticketDate_List.removeAt(0); ticketPrice_List.removeAt(0); loading.hide(); }*/ @override Widget build(BuildContext context) { var size = MediaQuery.of(context).size; return Scaffold( body: Stack( children: [ Column( children: [ Stack( children: [ WavyHeader(), Container( margin: EdgeInsets.only( top: (size.height / 6) - 20), padding: EdgeInsets.fromLTRB(0, 5, 25, 5), child: Row( mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end, children: [ Text( 'History\t\t', maxLines: 1, style: GoogleFonts.luckiestGuy( fontSize: 28, color: Color(0xFF4858A7), fontStyle: FontStyle.italic, ), ), Image.asset( 'assets/images/ic_history.png', width: 40, height: 40, ), ], ) ), ], ), ], ), Container( margin: EdgeInsets.only(top: (MediaQuery.of(context).size.height / 6) + 40, left: 5, right: 5, bottom: 10), child: ListView.builder( scrollDirection: Axis.vertical, shrinkWrap: true, itemCount: HistoryLength, itemBuilder: (context, int i) { return Container( child: InkWell( child: Card( elevation: 10, child: Column( children: [ Row( children: [ Expanded( flex: 8, child: Padding( padding: EdgeInsets.fromLTRB(10, 5, 5, 5), child: Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(number_List[i], style: GoogleFonts.rubikBubbles(fontSize: 16)), Text(keperluan_List[i], style: GoogleFonts.nunito(fontSize: 15)), Text("\nCreated : " + tglDibuat_List[i], style: GoogleFonts.nunito(fontSize: 15)), ], ), ) ), Expanded( flex: 2, child: Padding( padding: EdgeInsets.fromLTRB(5, 5, 5, 5), child: Text(status_List[i], textAlign: TextAlign.center, style: GoogleFonts.lilitaOne(color: statusColor[i], fontSize: 17), ), ) ), ], ), /*Align( alignment: Alignment.centerLeft, child: Visibility( visible: visible[i], child: Padding( padding: EdgeInsets.fromLTRB(10, 5, 5, 5), child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ *//*Text("\nAssignment Letter Date\t : " + tglST_List[i], style: GoogleFonts.josefinSans(fontSize: 15, fontWeight: FontWeight.bold)),*//* Text("Down Payment\t\t : " + uMuka_List[i], style: GoogleFonts.nunito(fontSize: 15)), Text("Departure Date\t\t : " + tglBerangkat_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)), Text("Return Date\t\t : " + tglKembali_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)), Text("Destination\t\t : " + tujuan_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)), *//*Text("Ticket Type\t\t : " + ticketType_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)), Text("From\t\t\t : " + ticketFrom_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)), Text("To\t\t : " + ticketTo_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)), Text("Ticket Date\t\t : " + ticketDate_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)), Text("Ticket Price\t\t\t : " + ticketPrice_List[i], style: GoogleFonts.yeonSung(fontSize: 14, fontStyle: FontStyle.italic)),*//* ], ), ) ), )*/ ], ), ), onTap: (){ setState(() { visible[i] = !visible[i]; }); }, ), ); }, ), ) ]), ); } } alertDialogFailedRetrievedData(BuildContext context) { Widget okButton = TextButton( child: Text("Refresh"), onPressed: () { Navigator.of(context, rootNavigator: true).pop(); Navigator.pushReplacement( context, MaterialPageRoute(builder: (context) => HistoryST())); }, ); Widget noButton = TextButton( child: Text("Back"), onPressed: () { Navigator.of(context, rootNavigator: true).pop(); Navigator.pop(context); }, ); // set up the AlertDialog AlertDialog alert = AlertDialog( title: Text("Employee Self Service"), content: Text("Failed to Retrieve Data"), actions: [ noButton, okButton, ], ); // show the dialog showDialog( context: context, builder: (BuildContext context) { return alert; }, ); }