Advertisement
andresual

EbmListPage

Mar 20th, 2020
491
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 23.54 KB | None | 0 0
  1. import 'package:flutter/material.dart';
  2. import 'package:loading/loading.dart';
  3. import 'package:pull_to_refresh/pull_to_refresh.dart';
  4. import 'package:loading/indicator/ball_pulse_indicator.dart';
  5. import 'package:shared_preferences/shared_preferences.dart';
  6.  
  7. import 'package:http/http.dart' as http;
  8. import 'dart:async';
  9. import 'dart:convert';
  10.  
  11. class EbmListPage extends StatefulWidget {
  12.   @override
  13.   _EbmListPageState createState() => _EbmListPageState();
  14. }
  15.  
  16. class _EbmListPageState extends State<EbmListPage> {
  17.   //Untuk List Data
  18.   Map data;
  19.   List ebmListData;
  20.   bool kedatangan;
  21.   Map dataJenis;
  22.   List jenisList;
  23.   List<dynamic> jenisListFilter = [];
  24.   String filter;
  25.   String messageInfo = "Tekan tombol filter diatas untuk menampilkan data";
  26.  
  27.   //Variables
  28.   String baseUrl, serverCode;
  29.   bool loading = true;
  30.   String tanggal;
  31.   String _currentJenisId, _currentJenis;
  32.   String _isButtonEnabled = "N";
  33.   String fromDetail;
  34.  
  35.   RefreshController _refreshController =
  36.       RefreshController(initialRefresh: false);
  37.  
  38.   //void _onChangedKedatangan(bool value) => setState(() => kedatangan = value);
  39.  
  40.   @override
  41.   void initState() {
  42.     super.initState();
  43.     getServerUrl();
  44.   }
  45.  
  46.   @override
  47.   Widget build(BuildContext context) {
  48.  
  49.     final containerLoading = Center(
  50.         child: Column(mainAxisSize: MainAxisSize.max, children: <Widget>[
  51.       Padding(
  52.         padding: EdgeInsets.only(top: MediaQuery.of(context).size.height / 2.2),
  53.       ),
  54.       Loading(
  55.         indicator: BallPulseIndicator(),
  56.         size: 50.0,
  57.         color: Colors.lightBlue,
  58.       ),
  59.       Text("Memuat Data")
  60.     ]));
  61.  
  62.     final containerNoData = Center(
  63.         child: Text(messageInfo,
  64.             style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)));
  65.  
  66.     final containerListData = SmartRefresher(
  67.         enablePullDown: true,
  68.         enablePullUp: false,
  69.         header: WaterDropHeader(waterDropColor: Colors.lightBlue),
  70.         footer: CustomFooter(
  71.           builder: (BuildContext context, LoadStatus mode) {
  72.             Widget body;
  73.             if (mode == LoadStatus.noMore) {
  74.               body = Text("No more Data");
  75.             } else if (mode == LoadStatus.loading) {
  76.               body = Loading(
  77.                 indicator: BallPulseIndicator(),
  78.                 size: 50.0,
  79.                 color: Colors.lightBlue,
  80.               );
  81.             } else if (mode == LoadStatus.failed) {
  82.               body = Text("Load Failed!Click retry!");
  83.             } else if (mode == LoadStatus.canLoading) {
  84.               body = Text("release to load more");
  85.             } else {
  86.               body = Text("pull up load");
  87.             }
  88.             return Container(
  89.               height: 55.0,
  90.               child: Center(child: body),
  91.             );
  92.           },
  93.         ),
  94.         controller: _refreshController,
  95.         onRefresh: _onRefresh,
  96.         onLoading: _onLoading,
  97.         child: ListView.builder(
  98.             itemCount: (ebmListData == null) ? 0 : ebmListData.length,
  99.             itemBuilder: (BuildContext context, int index) {
  100.               return InkWell(
  101.                   highlightColor: Colors.white.withAlpha(30),
  102.                   splashColor: Colors.white.withAlpha(20),
  103.                   child: Card(
  104.                       color: (ebmListData[index]["ebm_kedatangan"] == 'Y')
  105.                           ? Colors.lightBlue
  106.                           : (ebmListData[index]["ebm_kedatangan"] == 'N')
  107.                               ? Colors.orange
  108.                               : Colors.red,
  109.                       margin: EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
  110.                       elevation: 3,
  111.                       shape: RoundedRectangleBorder(
  112.                           borderRadius: BorderRadius.circular(7.0)),
  113.                       child: Container(
  114.                           decoration: BoxDecoration(
  115.                               color: Colors.white,
  116.                               borderRadius: BorderRadius.only(
  117.                                 topRight: Radius.circular(7.0),
  118.                                 bottomRight: Radius.circular(7.0),
  119.                               )),
  120.                           margin: EdgeInsets.only(left: 10),
  121.                           child: Padding(
  122.                               padding: EdgeInsets.all(10.0),
  123.                               child: Column(
  124.                                 crossAxisAlignment: CrossAxisAlignment.start,
  125.                                 children: <Widget>[
  126.                                   Row(
  127.                                     mainAxisAlignment:
  128.                                         MainAxisAlignment.spaceBetween,
  129.                                     children: <Widget>[
  130.                                       Text(
  131.                                           "${ebmListData[index]["personal_nama"]}",
  132.                                           style: TextStyle(
  133.                                               fontWeight: FontWeight.bold)),
  134.                                       Row(
  135.                                         children: <Widget>[
  136.                                           Image.asset(
  137.                                             (ebmListData[index]
  138.                                                         ["ebm_kedatangan"] ==
  139.                                                     'Y')
  140.                                                 ? 'assets/images/tick.png'
  141.                                                 : (ebmListData[index][
  142.                                                             "ebm_kedatangan"] ==
  143.                                                         'N')
  144.                                                     ? 'assets/images/hourglass.png'
  145.                                                     : 'assets/images/cancel.png',
  146.                                             height: 15,
  147.                                             width: 15,
  148.                                             color: (ebmListData[index]
  149.                                                         ["ebm_kedatangan"] ==
  150.                                                     'Y')
  151.                                                 ? Colors.lightBlue
  152.                                                 : (ebmListData[index][
  153.                                                             "ebm_kedatangan"] ==
  154.                                                         'N')
  155.                                                     ? Colors.orange
  156.                                                     : Colors.red,
  157.                                           ),
  158.                                           Text(
  159.                                               (ebmListData[index]
  160.                                                           ["ebm_kedatangan"] ==
  161.                                                       'Y')
  162.                                                   ? "OK"
  163.                                                   : (ebmListData[index][
  164.                                                               "ebm_kedatangan"] ==
  165.                                                           'N')
  166.                                                       ? "Belum"
  167.                                                       : "Batal",
  168.                                               style: TextStyle(
  169.                                                 color: (ebmListData[index][
  170.                                                             "ebm_kedatangan"] ==
  171.                                                         'Y')
  172.                                                     ? Colors.lightBlue
  173.                                                     : (ebmListData[index][
  174.                                                                 "ebm_kedatangan"] ==
  175.                                                             'N')
  176.                                                         ? Colors.orange
  177.                                                         : Colors.red,
  178.                                               ))
  179.                                         ],
  180.                                       )
  181.                                     ],
  182.                                   ),
  183.                                   Text("${ebmListData[index]["ebm_tanggal"]}"),
  184.                                   SizedBox(height: 10),
  185.                                   Text(
  186.                                       "Jenis: ${ebmListData[index]["jenis_nama"]}"),
  187.                                   Text(
  188.                                       "Estimasi: ${ebmListData[index]["ebm_est_jml_box"]} Box / ${ebmListData[index]["ebm_est_jml_kg"]} Kg")
  189.                                 ],
  190.                               )))),
  191.                   onTap: () => Navigator.of(context)
  192.                           .pushNamed('/EbmDetailPage', arguments: {
  193.                         'post2db': "UPDATE",
  194.                         'ebmId': ebmListData[index]["ebm_id"],
  195.                         'ebmTanggal': ebmListData[index]["ebm_tanggal"],
  196.                         'ebmPersonalId': ebmListData[index]["pkode_id"],
  197.                         'ebmPersonalNama': ebmListData[index]["personal_nama"],
  198.                         'ebmJenisId': ebmListData[index]["jenis_id"],
  199.                         'ebmJenisNama': ebmListData[index]["jenis_nama"],
  200.                         'ebmKedatangan': ebmListData[index]["ebm_kedatangan"],
  201.                         'ebmJmlKg': ebmListData[index]["ebm_est_jml_kg"],
  202.                         'ebmKetLapangan': ebmListData[index]
  203.                             ["ebm_keterangan_lapangan"],
  204.                         'ebmKetAdmin': ebmListData[index]["ebm_keterangan"],
  205.                         'ebmjmlBox': ebmListData[index]["ebm_est_jml_box"],
  206.                         'ebmRevised': ebmListData[index]["ebm_revised"],
  207.                       }));
  208.             }));
  209.  
  210.     final body = Container(
  211.         padding: EdgeInsets.only(top: 10, bottom: 10),
  212.         color: Colors.grey[100],
  213.         child: (loading)
  214.             ? containerLoading
  215.             : (ebmListData == null) ? containerNoData : containerListData);
  216.  
  217.     return Scaffold(
  218.         appBar: new AppBar(
  219.           actions: <Widget>[
  220.             new IconButton(
  221.                 icon: new Icon(Icons.tune, color: Colors.white),
  222.                 onPressed: () => {
  223.                   print(_isButtonEnabled),
  224.                       if (_isButtonEnabled == "Y") {
  225.                         showDialogListJenis(context, "Jenis")
  226.                       } else {
  227. //                          null,
  228. //                        print(_isButtonDisabled)
  229. //                        showDialogListJenis(context, "Jenis")
  230.                         }
  231.                     }),
  232.           ],
  233.           title: Container(
  234.             width: double.infinity,
  235.             child: Column(
  236.               crossAxisAlignment: CrossAxisAlignment.start,
  237.               children: <Widget>[
  238.                 Text(
  239.                   'Daftar Estimasi Barang Masuk',
  240.                   textAlign: TextAlign.left,
  241.                 ),
  242.                 Text(
  243.                   'Tanggal $tanggal',
  244.                   textAlign: TextAlign.left,
  245.                   style: TextStyle(fontSize: 13),
  246.                 ),
  247.               ],
  248.             ),
  249.           ),
  250.           elevation: 3,
  251.         ),
  252.         body: body);
  253.   }
  254.  
  255.   //All Function
  256.   Future getServerUrl() async {
  257.     SharedPreferences prefs = await SharedPreferences.getInstance();
  258.     setState(() {
  259.       if (prefs.getString("login_jaringan") == "Lokal") {
  260.         baseUrl = "http://192.168.1.200/";
  261.       } else {
  262.         baseUrl = "http://koffiesoftmjw.ngrok.io/";
  263.       }
  264.  
  265.       if (prefs.getString("login_cabang") == 'MJWJKT') {
  266.         serverCode =
  267.             "koffie_mjw/index.php?c=c_estimasi_barang_masuk&m=get_action";
  268.       } else if (prefs.getString("login_cabang") == 'MJWSBY') {
  269.         serverCode =
  270.             "koffie_mjw_sby/index.php?c=c_estimasi_barang_masuk&m=get_action";
  271.       } else {
  272.         serverCode =
  273.             "koffie_mjw_testing/index.php?c=c_estimasi_barang_masuk&m=get_action";
  274.       }
  275.  
  276. //      getEbmList("");
  277.       getJenisList();
  278.  
  279.       final Map arguments = ModalRoute.of(context).settings.arguments as Map;
  280.       setState(() {
  281.         tanggal = arguments["tanggal"];
  282.         fromDetail = arguments["fromDetail"];
  283.         print("kunam $fromDetail");
  284.         if (fromDetail != null) {
  285.           getEbmList("0");
  286.         }
  287.       });
  288.     });
  289.   }
  290.  
  291.   Future getEbmList(String id) async {
  292.     loading = true;
  293.     http.Response response = await http.post("$baseUrl$serverCode", body: {
  294.       "task": "LIST",
  295.       "jenis_id": id,
  296.       "ebm_start_date": tanggal,
  297.       "ebm_end_date": tanggal,
  298.       "ebm_tahun": "",
  299.       "ebm_bulan": "",
  300.       "start": "0",
  301.       "end": "100",
  302.     });
  303.  
  304.     if (response.statusCode == 200) {
  305.       data = json.decode(response.body);
  306.       setState(() {
  307.         ebmListData = (data["total"] == "0") ? null : data["results"];
  308.         messageInfo = "Tidak ada barang masuk untuk jenis ini";
  309.         loading = false;
  310.       });
  311.  
  312.       print('Url : $baseUrl$serverCode');
  313.       print('ResponseData : $ebmListData');
  314.     } else {
  315.       return null;
  316.     }
  317.   }
  318.  
  319.   Future getJenisList() async {
  320.     http.Response response = await http.post(
  321.         "$baseUrl${serverCode}index.php?c=c_estimasi_barang_masuk&m=get_ebm_jenis",
  322.         body: {});
  323.  
  324.     if (response.statusCode == 200) {
  325.       dataJenis = json.decode(response.body);
  326.       setState(() {
  327.         jenisList = (dataJenis["total"] == "0") ? null : dataJenis["results"];
  328.         loading = false;
  329.         _isButtonEnabled = "Y";
  330.       });
  331.     } else {
  332.       return null;
  333.     }
  334.   }
  335.  
  336.   void _onRefresh() async {
  337.     await Future.delayed(Duration(milliseconds: 1000));
  338.  
  339.     _refreshController.refreshCompleted();
  340.  
  341.     getEbmList("");
  342.   }
  343.  
  344.   void _onLoading() async {
  345.     await Future.delayed(Duration(milliseconds: 1000));
  346.     setState(() {});
  347.  
  348.     _refreshController.loadComplete();
  349.   }
  350.  
  351.   void onSearchTextChanged(String text, String dataList) async {
  352.     jenisListFilter.clear();
  353.  
  354.     setState(() {
  355.       filter = text.toUpperCase();
  356.     });
  357.  
  358.     if (text.isEmpty) {
  359.       setState(() {});
  360.       return;
  361.     }
  362.     for (var i = 0; i < jenisList.length; i++) {
  363.       if (jenisList[i]["jenis_nama"].contains(filter)) {
  364.         jenisListFilter.add(jenisList[i]);
  365.       }
  366.     }
  367.  
  368.     print('new list: ' + jenisListFilter.toString());
  369.     print('new length: ' + jenisListFilter.length.toString());
  370.     print(filter);
  371.  
  372.     setState(() {});
  373.   }
  374.  
  375.   void showDialogListJenis(BuildContext context, dataList) {
  376.     AlertDialog dialog = new AlertDialog(
  377.         shape: RoundedRectangleBorder(
  378.           borderRadius: BorderRadius.circular(10.0),
  379.         ),
  380.         elevation: 0.0,
  381.         backgroundColor: Colors.transparent,
  382.         content: dialogContent(context, dataList));
  383.  
  384.     showDialog(context: context, child: dialog);
  385.   }
  386.  
  387.   dialogContent(context, dataList) {
  388.     return Container(
  389.         height: 390,
  390.         width: MediaQuery.of(context).size.width,
  391.         decoration: new BoxDecoration(
  392.           color: Colors.blue,
  393.           shape: BoxShape.rectangle,
  394.           borderRadius: BorderRadius.circular(20.0),
  395.           boxShadow: [
  396.             BoxShadow(
  397.               color: Colors.black26,
  398.               blurRadius: 10.0,
  399.               offset: const Offset(0.0, 10.0),
  400.             ),
  401.           ],
  402.         ),
  403.         child: Column(children: <Widget>[
  404.           Container(
  405.             padding: EdgeInsets.only(top: 10, bottom: 10),
  406.             child: Text("Daftar $dataList",
  407.                 style: TextStyle(
  408.                     color: Colors.white, fontWeight: FontWeight.bold)),
  409.           ),
  410.           Container(
  411.               decoration: new BoxDecoration(
  412.                   color: Colors.white,
  413.                   shape: BoxShape.rectangle,
  414.                   borderRadius: BorderRadius.only(
  415.                       bottomLeft: const Radius.circular(20.0),
  416.                       bottomRight: const Radius.circular(20.0))),
  417.               padding: EdgeInsets.only(bottom: 10),
  418.               child: Column(children: <Widget>[
  419.                 Row(
  420.                   mainAxisAlignment: MainAxisAlignment.spaceBetween,
  421.                   children: <Widget>[
  422.                     Container(
  423.                         height: 30,
  424.                         width: MediaQuery.of(context).size.width / 1.8,
  425.                         margin: EdgeInsets.all(5),
  426.                         child: TextFormField(
  427. //                                  controller: filterSupplier,
  428.                           onChanged: (text) {
  429.                             onSearchTextChanged(text, dataList);
  430.                           },
  431.                           autofocus: false,
  432.                           decoration: InputDecoration(
  433.                               contentPadding:
  434.                                   EdgeInsets.fromLTRB(10.0, 5.0, 5.0, 10.0),
  435.                               hintText: "Cari $dataList"),
  436.                         )),
  437.                     InkWell(
  438.                         onTap: () {
  439.                           Navigator.of(context).pop();
  440.                           showDialogListJenis(context, dataList);
  441.                         },
  442.                         child: Container(
  443.                           padding: EdgeInsets.only(right: 20),
  444.                           height: 30,
  445.                           width: 35,
  446.                           //color: Colors.red,
  447.                           child: Icon(Icons.search, color: Colors.black),
  448.                         ))
  449.                   ],
  450.                 ),
  451.                 Container(
  452.                   width: MediaQuery.of(context).size.width,
  453.                   height: 298,
  454.                   child: SmartRefresher(
  455.                     enablePullDown: true,
  456.                     enablePullUp: false,
  457.                     header: WaterDropHeader(waterDropColor: Colors.lightBlue),
  458.                     footer: CustomFooter(
  459.                       builder: (BuildContext context, LoadStatus mode) {
  460.                         Widget body;
  461.                         if (mode == LoadStatus.noMore) {
  462.                           body = Text("No more Data");
  463.                         } else if (mode == LoadStatus.loading) {
  464.                           body = Loading(
  465.                             indicator: BallPulseIndicator(),
  466.                             size: 50.0,
  467.                             color: Colors.lightBlue,
  468.                           );
  469.                         } else if (mode == LoadStatus.failed) {
  470.                           body = Text("Load Failed!Click retry!");
  471.                         } else if (mode == LoadStatus.canLoading) {
  472.                           body = Text("release to load more");
  473.                         } else {
  474.                           body = Text("pull up load");
  475.                         }
  476.                         return Container(
  477.                           height: 55.0,
  478.                           child: Center(child: body),
  479.                         );
  480.                       },
  481.                     ),
  482.                     controller: _refreshController,
  483.                     onRefresh: () => _onRefresh(),
  484.                     onLoading: _onLoading,
  485.                     child: ListView.builder(
  486.                         shrinkWrap: true,
  487. //                                itemCount: (dataList == 'Supplier') ?
  488. //                                (filter == null || filter == "") ? (supplierList == null) ? 0 : supplierList.length : supplierListFilter.length :
  489. //                                (filter == null || filter == "") ? (jenisList == null) ? 0 : jenisList.length : jenisListFilter.length,
  490.                         itemBuilder: (BuildContext context, int index) {
  491.                           return InkWell(
  492.                             highlightColor: Colors.white.withAlpha(30),
  493.                             splashColor: Colors.white.withAlpha(20),
  494.                             child: Padding(
  495.                               padding: EdgeInsets.all(5),
  496.                               child: (dataList == 'Supplier')
  497.                                   ? Column(
  498.                                       crossAxisAlignment:
  499.                                           CrossAxisAlignment.start,
  500.                                       children: <Widget>[
  501.                                         Row(
  502. //                                            children: <Widget>[
  503. //                                              Text((filter == "" || filter == null) ? "["+supplierList[index]["pkode_nama"]+"] " : "["+supplierListFilter[index]["pkode_nama"]+"] ",
  504. //                                                  style: TextStyle(color: Colors.red, /*fontWeight: FontWeight.bold*/)
  505. //                                              ),
  506. //                                              Text((filter == "" || filter == null) ? supplierList[index]["personal_nama"] : supplierListFilter[index]["personal_nama"])
  507. //                                            ],
  508.                                             ),
  509.                                         //Text((filter == "" || filter == null) ? supplierList[index]["personal_nama_dan_nama_perusahaan"] : supplierListFilter[index]["personal_nama_dan_nama_perusahaan"]),
  510.                                         Text((filter == "" || filter == null)
  511.                                             ? (jenisList[index]["jenis_nama"] ==
  512.                                                     null)
  513.                                                 ? "Jenis: -"
  514.                                                 : "Jenis : " +
  515.                                                     jenisList[index]
  516.                                                         ["jenis_nama"]
  517.                                             : (jenisList[index]["jenis_nama"] ==
  518.                                                     null)
  519.                                                 ? "Jenis: -"
  520.                                                 : "Jenis : " +
  521.                                                     jenisList[index]
  522.                                                         ["jenis_nama"]),
  523.                                       ],
  524.                                     )
  525.                                   : Text((filter == "" || filter == null)
  526.                                       ? jenisList[index]["jenis_nama"]
  527.                                       : jenisListFilter[index]["jenis_nama"]),
  528.                             ),
  529.                             onTap: () => {
  530.                               setState(() {
  531.                                 if (filter == null || filter == "") {
  532.                                   _currentJenisId =
  533.                                       "${jenisList[index]["jenis_id"]}";
  534.                                   _currentJenis =
  535.                                       "${jenisList[index]["jenis_nama"]}";
  536.                                   getEbmList(_currentJenisId);
  537.                                 } else {
  538.                                   _currentJenisId =
  539.                                       "${jenisListFilter[index]["jenis_id"]}";
  540.                                   _currentJenis =
  541.                                       "${jenisListFilter[index]["jenis_nama"]}";
  542.  
  543.                                   filter = "";
  544.                                   jenisListFilter.clear();
  545.                                   getEbmList(_currentJenisId);
  546.                                 }
  547.  
  548.                                 Navigator.pop(context);
  549.                               })
  550.                             },
  551.                           );
  552.                         }),
  553.                   ),
  554.                 )
  555.               ]))
  556.         ]));
  557.   }
  558. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement