123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469 |
- 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<HistoryST> createState() => _HistoryST();
- }
-
- class _HistoryST extends State<HistoryST> {
- late List <String> id_List;
- late List <String> number_List;
- late List <String> keperluan_List;
- late List <String> tglDibuat_List;
- late List <String> status_List;
-
- late List <String> tglST_List;
- late List <String> uMuka_List;
- late List <String> tglBerangkat_List;
- late List <String> tglKembali_List;
- late List <String> tujuan_List;
-
- late List <String> ticketType_List;
- late List <String> ticketFrom_List;
- late List <String> ticketTo_List;
- late List <String> ticketDate_List;
- late List <String> ticketPrice_List;
-
- late List <Color> statusColor;
- late List <bool> 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<String, dynamic> object = jsonDecode(valueResult);
- if (object.containsKey("result").toString() == "true") {
- String result = object['result'].toString();
- if (result.contains("failed")) {
- loading.hide();
- alertDialogFailedRetrievedData(context);
- } else {
- List <dynamic> 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<String, dynamic> object = jsonDecode(valueResult);
- if (object.containsKey("result").toString() == "true") {
- String result = object['result'].toString();
- if (result.contains("failed")) {
- loading.hide();
- alertDialogFailedRetrievedData(context);
- } else {
- List <dynamic> 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<dynamic> 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<String, dynamic> object = jsonDecode(valueResult);
- if (object.containsKey("result").toString() == "true") {
- String result = object['result'].toString();
- if (result.contains("failed")) {
- loading.hide();
- alertDialogFailedRetrievedData(context);
- } else {
- List <dynamic> 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<dynamic> 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: <Widget>[
- 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: Colors.red,
- 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;
- },
- );
- }
|