Advertisement
andresual

CekFotoPage

Mar 18th, 2020
526
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 16.37 KB | None | 0 0
  1. import 'dart:convert';
  2.  
  3. import 'package:flutter/material.dart';
  4. import 'package:loading/loading.dart';
  5. import 'package:loading/indicator/ball_pulse_indicator.dart';
  6. import 'package:shared_preferences/shared_preferences.dart';
  7. import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
  8. import 'package:intl/intl.dart' show DateFormat;
  9.  
  10. import 'package:http/http.dart' as http;
  11. import 'dart:async';
  12.  
  13. class CekFotoPage extends StatefulWidget {
  14.   @override
  15.   _CekFotoPageState createState() => _CekFotoPageState();
  16. }
  17.  
  18. class _CekFotoPageState extends State<CekFotoPage> with WidgetsBindingObserver {
  19.   String baseUrl, serverCode, ebmTanggal, post2db = "CREATE";
  20.   List persetujuandata, jenisDokumenList, statusDokumenList;
  21.   bool loading = true;
  22.   String groupId, _currentDocType1, _currentDocType2, _currentDocStat;
  23.   String selectedDate, selectedDateEnd;
  24.   Map data;
  25.   final flutterWebViewPlugin = new FlutterWebviewPlugin();
  26.   Map dataJenis;
  27.   List jenisList;
  28.  
  29.   String _currentCabang;
  30.   int _persetujuanJktCount, _persetujuanSbyCount, _persetujuanTestingCount;
  31.   bool isFromSheet = true;
  32.  
  33.   @override
  34.   void initState() {
  35.     // TODO: implement initState
  36.     super.initState();
  37.     getCredential();
  38.     getServerUrl();
  39.   }
  40.  
  41.   DateTime _currentDate = DateTime.now();
  42.   DateTime _currentDateEnd = DateTime.now();
  43.   var myFormat = DateFormat('yyyy-MM-dd');
  44.   Future<Null> _selectDateStart(BuildContext context) async {
  45.     final DateTime picked = await showDatePicker(
  46.         context: context,
  47.         initialDate: _currentDate,
  48.         firstDate: DateTime(2015, 8),
  49.         lastDate: DateTime(2101));
  50.     if (picked != null && picked != _currentDate)
  51.       setState(() {
  52.         _currentDate = picked;
  53.         selectedDate = "${myFormat.format(_currentDate)}";
  54.         rebuildDate(selectedDate);
  55.       });
  56.   }
  57.  
  58.   Future<Null> _selectDateEnd(BuildContext context) async {
  59.     final DateTime picked = await showDatePicker(
  60.         context: context,
  61.         initialDate: _currentDateEnd,
  62.         firstDate: DateTime(2015, 8),
  63.         lastDate: DateTime(2101));
  64.     if (picked != null && picked != _currentDateEnd)
  65.       setState(() {
  66.         _currentDateEnd = picked;
  67.         selectedDateEnd = "${myFormat.format(_currentDateEnd)}";
  68.         rebuildDateEnd(selectedDateEnd);
  69.       });
  70.   }
  71.  
  72.   @override
  73.   Widget build(BuildContext context) {
  74.     return WebviewScaffold(
  75.         appBar: new AppBar(
  76.           actions: <Widget>[
  77.             new IconButton(
  78.               icon: new Icon(Icons.tune, color: Colors.white),
  79.               onPressed: () => _bottomSheetFilterSearch(context),
  80.             ),
  81.           ],
  82.           title: const Text('Cek Foto'),
  83.           elevation: 3,
  84.         ),
  85.         url: "$baseUrl${serverCode}print/p_cek_foto.html",
  86.         withZoom: true,
  87.         clearCache: true,
  88.         clearCookies: true,
  89.         withLocalStorage: true,
  90.         hidden: isFromSheet ? false : true,
  91.         primary: false,
  92.         initialChild: Container(
  93.           //  height: 350,
  94.             child: Center(
  95.                 child:
  96.                 Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
  97.                   Text(isFromSheet ? "" : "Memuat data..."),
  98.                   Loading(
  99.                     indicator: BallPulseIndicator(),
  100.                     size: 50.0,
  101.                     color: isFromSheet ? Colors.white : Colors.lightBlue,
  102.                   )
  103.                 ]))));
  104.   }
  105.  
  106.   Future getServerUrl() async {
  107.     SharedPreferences prefs = await SharedPreferences.getInstance();
  108.     setState(() {
  109.       if (prefs.getString("login_jaringan") == "Lokal") {
  110.         baseUrl = "http://192.168.1.200/";
  111.       } else {
  112.         baseUrl = "http://koffiesoftmjw.ngrok.io/";
  113.       }
  114.  
  115.       if (prefs.getString("login_cabang") == 'MJWJKT') {
  116.         serverCode = "koffie_mjw/";
  117.       } else if (prefs.getString("login_cabang") == 'MJWSBY') {
  118.         serverCode = "koffie_mjw_sby/";
  119.       } else {
  120.         serverCode = "koffie_mjw_testing/";
  121.       }
  122.  
  123.       getJenisList();
  124.     });
  125.   }
  126.  
  127.   void _bottomSheetFilterSearch(context) {
  128.     flutterWebViewPlugin.hide();
  129.  
  130.     setState(() {
  131.       isFromSheet = true;
  132.     });
  133.  
  134.     showModalBottomSheet(
  135.         context: context,
  136.         backgroundColor: Colors.transparent,
  137.         builder: (BuildContext bc) {
  138.           return Container(
  139.               decoration: BoxDecoration(
  140.                   color: Colors.white,
  141.                   borderRadius: new BorderRadius.only(
  142.                       topLeft: const Radius.circular(20.0),
  143.                       topRight: const Radius.circular(20.0))),
  144.               child: new Wrap(children: <Widget>[
  145.                 new Column(
  146.                   children: <Widget>[
  147.                     new Divider(height: 20),
  148.                     new InkWell(
  149.                         onTap: () =>
  150.                             showDialogListData(context, "Jenis Dokumen"),
  151.                         child: Container(
  152.                             height: 40,
  153.                             width: double.infinity,
  154.                             margin: EdgeInsets.fromLTRB(10, 5, 10, 5),
  155.                             decoration: BoxDecoration(
  156.                                 color: Colors.grey[100],
  157.                                 borderRadius: new BorderRadius.all(
  158.                                     const Radius.circular(20.0)),
  159.                                 border: Border.all(color: Colors.grey)),
  160.                             child: Padding(
  161.                                 padding: EdgeInsets.all(10),
  162.                                 child: Text((_currentDocType2 == null)
  163.                                     ? "Pilih Jenis Dokumen"
  164.                                     : _currentDocType2)))),
  165.                     new InkWell(
  166.                         highlightColor: Colors.blue.withAlpha(30),
  167.                         splashColor: Colors.blue.withAlpha(20),
  168.                         child: Row(children: <Widget>[
  169.                           SizedBox(width: 100, child: Text("Tanggal Awal")),
  170.                           Container(
  171.                             width: 120,
  172.                             padding: EdgeInsets.all(8),
  173.                             decoration: BoxDecoration(
  174.                                 color: Colors.grey[200],
  175.                                 border: Border.all(color: Colors.grey),
  176.                                 borderRadius:
  177.                                 BorderRadius.all(Radius.circular(8.0))),
  178.                             child: Text((selectedDate == null)
  179.                                 ? "${myFormat.format(_currentDate)}"
  180.                                 : "$selectedDate"),
  181.                           )
  182.                         ]),
  183.                         onTap: () => _selectDateStart(context)),
  184.                     new InkWell(
  185.                         highlightColor: Colors.blue.withAlpha(30),
  186.                         splashColor: Colors.blue.withAlpha(20),
  187.                         child: Row(children: <Widget>[
  188.                           SizedBox(width: 100, child: Text("Tanggal Akhir")),
  189.                           Container(
  190.                             width: 120,
  191.                             padding: EdgeInsets.all(8),
  192.                             decoration: BoxDecoration(
  193.                                 color: Colors.grey[200],
  194.                                 border: Border.all(color: Colors.grey),
  195.                                 borderRadius:
  196.                                 BorderRadius.all(Radius.circular(8.0))),
  197.                             child: Text((post2db == "CREATE")
  198.                                 ? (selectedDateEnd == null)
  199.                                 ? "${myFormat.format(_currentDateEnd)}"
  200.                                 : "$selectedDateEnd"
  201.                                 : (selectedDateEnd == null)
  202.                                 ? "$ebmTanggal"
  203.                                 : "$selectedDateEnd"),
  204.                           )
  205.                         ]),
  206.                         onTap: () => _selectDateEnd(context)),
  207.                     InkWell(
  208.                       onTap: () => {
  209.                         setState(() {
  210.                           loading = true;
  211.                           isFromSheet = false;
  212.                         }),
  213.                         Navigator.pop(context),
  214.                         getData(selectedDate, selectedDateEnd, _currentDocType2,
  215.                             "0", "100"),
  216.                         print(selectedDate + " " + selectedDateEnd)
  217.                       },
  218.                       child: Container(
  219.                         margin: EdgeInsets.all(10.0),
  220.                         padding: EdgeInsets.all(10.0),
  221.                         decoration: BoxDecoration(
  222.                           color: Colors.lightBlue,
  223.                           borderRadius:
  224.                           new BorderRadius.all(const Radius.circular(20.0)),
  225.                         ),
  226.                         width: double.infinity,
  227.                         child: Text("CARI",
  228.                             style: TextStyle(color: Colors.white),
  229.                             textAlign: TextAlign.center),
  230.                       ),
  231.                     )
  232.                   ],
  233.                 ),
  234.               ]));
  235.         });
  236.   }
  237.  
  238.   void showDialogListData(BuildContext context, String listData) {
  239.     AlertDialog dialog = new AlertDialog(
  240.         shape: RoundedRectangleBorder(
  241.           borderRadius: BorderRadius.circular(10.0),
  242.         ),
  243.         elevation: 0.0,
  244.         backgroundColor: Colors.transparent,
  245.         content: listDataContent(context, listData));
  246.  
  247.     showDialog(context: context, child: dialog);
  248.   }
  249.  
  250.   listDataContent(context, listData) {
  251.     return Container(
  252.         height: 350,
  253.         width: 300,
  254.         decoration: new BoxDecoration(
  255.           color: Colors.blue,
  256.           shape: BoxShape.rectangle,
  257.           borderRadius: BorderRadius.circular(20.0),
  258.           boxShadow: [
  259.             BoxShadow(
  260.               color: Colors.black26,
  261.               blurRadius: 10.0,
  262.               offset: const Offset(0.0, 10.0),
  263.             ),
  264.           ],
  265.         ),
  266.         child: Column(
  267.           children: <Widget>[
  268.             Container(
  269.               padding: EdgeInsets.only(top: 10, bottom: 10),
  270.               child: Text("$listData",
  271.                   style: TextStyle(
  272.                       color: Colors.white, fontWeight: FontWeight.bold)),
  273.             ),
  274.             Container(
  275.                 decoration: new BoxDecoration(
  276.                     color: Colors.white,
  277.                     shape: BoxShape.rectangle,
  278.                     borderRadius: BorderRadius.only(
  279.                         bottomLeft: const Radius.circular(20.0),
  280.                         bottomRight: const Radius.circular(20.0))),
  281.                 height: 308,
  282.                 width: 300,
  283.                 padding: EdgeInsets.only(bottom: 10),
  284.                 child: ListView.builder(
  285.                     shrinkWrap: true,
  286.                     itemCount: (listData == 'Jenis Dokumen')
  287.                         ? (jenisDokumenList == null)
  288.                         ? 0
  289.                         : jenisDokumenList.length
  290.                         : (statusDokumenList == null)
  291.                         ? 0
  292.                         : statusDokumenList.length,
  293.                     itemBuilder: (BuildContext context, int index) {
  294.                       return InkWell(
  295.                         highlightColor: Colors.white.withAlpha(30),
  296.                         splashColor: Colors.white.withAlpha(20),
  297.                         child: Padding(
  298.                           padding: EdgeInsets.all(5),
  299.                           child: Text((listData == 'Jenis Dokumen')
  300.                               ? jenisDokumenList[index]["title"]
  301.                               : statusDokumenList[index]),
  302.                         ),
  303.                         onTap: () => {
  304.                           Navigator.pop(context),
  305.                           rebuildView(index, listData)
  306.                         },
  307.                       );
  308.                     }))
  309.           ],
  310.         ));
  311.   }
  312.  
  313.   void rebuildView(int index, String listData) {
  314. //    (listData == 'Jenis Dokumen') ? setState(() {
  315.     _currentDocType1 = jenisDokumenList[index]["title"];
  316.     _currentDocType2 = jenisDokumenList[index]["title"];
  317. //          }) : setState(() {
  318. //            _currentDocStat = statusDokumenList[index];
  319. //          });
  320.  
  321.     Navigator.pop(context);
  322.     _bottomSheetFilterSearch(context);
  323.   }
  324.  
  325.   void rebuildDate(String dateAwal) {
  326.     setState(() {
  327.       selectedDate = dateAwal;
  328.     });
  329.  
  330.     Navigator.pop(context);
  331.     _bottomSheetFilterSearch(context);
  332.   }
  333.  
  334.   void rebuildDateEnd(String dateAakhir) {
  335.     setState(() {
  336.       selectedDateEnd = dateAakhir;
  337.     });
  338.  
  339.     Navigator.pop(context);
  340.     _bottomSheetFilterSearch(context);
  341.   }
  342.  
  343.   Future getJenisList() async {
  344.     http.Response response = await http.post(
  345.         "$baseUrl${serverCode}index.php?c=c_cek_foto&m=get_action",
  346.         body: {
  347.           "task": "LIST",
  348.           "query": "",
  349.           "tgl_start": "",
  350.           "tgl_end": "",
  351.           "jenis_dokumen": "",
  352.           "start": "0",
  353.           "limit": "100"
  354.         });
  355.  
  356.     print("$baseUrl${serverCode}index.php?c=c_cek_foto&m=get_action");
  357.  
  358.     if (response.statusCode == 200) {
  359.       dataJenis = json.decode(response.body);
  360.       setState(() {
  361.         jenisDokumenList = (dataJenis["total"] == "0") ? null : dataJenis["results"];
  362.         loading = false;
  363.       });
  364.     } else {
  365.       return null;
  366.     }
  367.   }
  368.  
  369.   void getCredential() async {
  370.     SharedPreferences prefs = await SharedPreferences.getInstance();
  371.     setState(() {
  372.       _currentCabang = prefs.getString("login_cabang");
  373.       groupId = prefs.getString("group_id");
  374.     });
  375.  
  376. //    if (groupId == "5") {
  377. //      //HRD
  378. //      jenisDokumenList = [
  379. //        {'jenis': 'terima_beli', 'keterangan': 'Terima Beli'},
  380. //        {'jenis': 'kirim_barang', 'keterangan': 'Kirim Barang'},
  381. //        {'jenis': 'izin_karyawan', 'keterangan': 'Izin Karyawan'}
  382. //      ];
  383. //    } else if (groupId == "15") {
  384. //      //kepala gudang
  385. //      jenisDokumenList = [
  386. //        {'jenis': 'vonis_loyo', 'keterangan': 'Vonis Loyo'},
  387. //        {'jenis': 'mati_kolam', 'keterangan': 'Mati Kolam'},
  388. //        {'jenis': 'izin_karyawan', 'keterangan': 'Izin Karyawan'}
  389. //      ];
  390. //    } else {
  391. //      //direksi atau administrator
  392. //      jenisDokumenList = [
  393. //        {'jenis': 'harga_beli', 'keterangan': 'Harga Beli'},
  394. //        {'jenis': 'order_beli', 'keterangan': 'Order Beli'},
  395. //        {'jenis': 'nota_beli', 'keterangan': 'Nota Beli'},
  396. //        {'jenis': 'subsidi_beli', 'keterangan': 'Subsidi Beli'},
  397. //        {'jenis': 'personal', 'keterangan': 'Supplier / Customer'},
  398. //        {'jenis': 'register_pkk', 'keterangan': 'Register PKK'},
  399. //        {
  400. //          'jenis': 'mutasi_tabung_oksigen',
  401. //          'keterangan': 'Mutasi Tabung Oksigen'
  402. //        },
  403. //        {'jenis': 'harga_packing', 'keterangan': 'Harga Packing'},
  404. //        {'jenis': 'sp_material', 'keterangan': 'Surat Pesanan Material'},
  405. //        {'jenis': 'laba_rugi_harian', 'keterangan': 'Laba Rugi Harian'},
  406. //        {'jenis': 'register_cargo_export', 'keterangan': 'Ubahan Upi'},
  407. //        {'jenis': 'izin_karyawan', 'keterangan': 'Izin Karyawan'}
  408. //      ];
  409. //    }
  410.  
  411.     statusDokumenList = ["Tunggu", "Tertutup", "Batal"];
  412.   }
  413.  
  414.   Future getData(String tglStart, String tglEnd, String jenisDokumen,
  415.       String start, String limit) async {
  416. //    SharedPreferences prefs = await SharedPreferences.getInstance();
  417.     http.Response response = await http.post(
  418.         "$baseUrl$serverCode" + "index.php?c=c_cek_foto&m=get_print_data",
  419.         body: {
  420.           "query": "",
  421.           "tgl_start": tglStart,
  422.           "tgl_end": tglEnd,
  423.           "jenis_dokumen": jenisDokumen,
  424.           "start": start,
  425.           "limit": limit
  426.         });
  427.  
  428.     print("$baseUrl$serverCode" + "index.php?c=c_cek_foto&m=get_print_data");
  429.     print(response.body);
  430.  
  431.     if (response.statusCode == 200) {
  432.       print(response.toString());
  433.  
  434.       setState(() {
  435. //        isFromSheet = true;
  436.         flutterWebViewPlugin.show();
  437.         flutterWebViewPlugin.reload();
  438. //        flutterWebViewPlugin.launch("$baseUrl${serverCode}print/p_cek_foto.html");
  439. //      loading = false;
  440.         print(response.body);
  441.         loading = false;
  442.       });
  443.     } else {
  444.       return null;
  445.     }
  446.   }
  447. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement