Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'dart:convert';
- import 'package:flutter/material.dart';
- import 'package:loading/loading.dart';
- import 'package:loading/indicator/ball_pulse_indicator.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- import 'package:flutter_webview_plugin/flutter_webview_plugin.dart';
- import 'package:intl/intl.dart' show DateFormat;
- import 'package:http/http.dart' as http;
- import 'dart:async';
- class CekFotoPage extends StatefulWidget {
- @override
- _CekFotoPageState createState() => _CekFotoPageState();
- }
- class _CekFotoPageState extends State<CekFotoPage> with WidgetsBindingObserver {
- String baseUrl, serverCode, ebmTanggal, post2db = "CREATE";
- List persetujuandata, jenisDokumenList, statusDokumenList;
- bool loading = true;
- String groupId, _currentDocType1, _currentDocType2, _currentDocStat;
- String selectedDate, selectedDateEnd;
- Map data;
- final flutterWebViewPlugin = new FlutterWebviewPlugin();
- Map dataJenis;
- List jenisList;
- String _currentCabang;
- int _persetujuanJktCount, _persetujuanSbyCount, _persetujuanTestingCount;
- bool isFromSheet = true;
- @override
- void initState() {
- // TODO: implement initState
- super.initState();
- getCredential();
- getServerUrl();
- }
- DateTime _currentDate = DateTime.now();
- DateTime _currentDateEnd = DateTime.now();
- var myFormat = DateFormat('yyyy-MM-dd');
- Future<Null> _selectDateStart(BuildContext context) async {
- final DateTime picked = await showDatePicker(
- context: context,
- initialDate: _currentDate,
- firstDate: DateTime(2015, 8),
- lastDate: DateTime(2101));
- if (picked != null && picked != _currentDate)
- setState(() {
- _currentDate = picked;
- selectedDate = "${myFormat.format(_currentDate)}";
- rebuildDate(selectedDate);
- });
- }
- Future<Null> _selectDateEnd(BuildContext context) async {
- final DateTime picked = await showDatePicker(
- context: context,
- initialDate: _currentDateEnd,
- firstDate: DateTime(2015, 8),
- lastDate: DateTime(2101));
- if (picked != null && picked != _currentDateEnd)
- setState(() {
- _currentDateEnd = picked;
- selectedDateEnd = "${myFormat.format(_currentDateEnd)}";
- rebuildDateEnd(selectedDateEnd);
- });
- }
- @override
- Widget build(BuildContext context) {
- return WebviewScaffold(
- appBar: new AppBar(
- actions: <Widget>[
- new IconButton(
- icon: new Icon(Icons.tune, color: Colors.white),
- onPressed: () => _bottomSheetFilterSearch(context),
- ),
- ],
- title: const Text('Cek Foto'),
- elevation: 3,
- ),
- url: "$baseUrl${serverCode}print/p_cek_foto.html",
- withZoom: true,
- clearCache: true,
- clearCookies: true,
- withLocalStorage: true,
- hidden: isFromSheet ? false : true,
- primary: false,
- initialChild: Container(
- // height: 350,
- child: Center(
- child:
- Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
- Text(isFromSheet ? "" : "Memuat data..."),
- Loading(
- indicator: BallPulseIndicator(),
- size: 50.0,
- color: isFromSheet ? Colors.white : Colors.lightBlue,
- )
- ]))));
- }
- Future getServerUrl() async {
- SharedPreferences prefs = await SharedPreferences.getInstance();
- setState(() {
- if (prefs.getString("login_jaringan") == "Lokal") {
- baseUrl = "http://192.168.1.200/";
- } else {
- baseUrl = "http://koffiesoftmjw.ngrok.io/";
- }
- if (prefs.getString("login_cabang") == 'MJWJKT') {
- serverCode = "koffie_mjw/";
- } else if (prefs.getString("login_cabang") == 'MJWSBY') {
- serverCode = "koffie_mjw_sby/";
- } else {
- serverCode = "koffie_mjw_testing/";
- }
- getJenisList();
- });
- }
- void _bottomSheetFilterSearch(context) {
- flutterWebViewPlugin.hide();
- setState(() {
- isFromSheet = true;
- });
- showModalBottomSheet(
- context: context,
- backgroundColor: Colors.transparent,
- builder: (BuildContext bc) {
- return Container(
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: new BorderRadius.only(
- topLeft: const Radius.circular(20.0),
- topRight: const Radius.circular(20.0))),
- child: new Wrap(children: <Widget>[
- new Column(
- children: <Widget>[
- new Divider(height: 20),
- new InkWell(
- onTap: () =>
- showDialogListData(context, "Jenis Dokumen"),
- child: Container(
- height: 40,
- width: double.infinity,
- margin: EdgeInsets.fromLTRB(10, 5, 10, 5),
- decoration: BoxDecoration(
- color: Colors.grey[100],
- borderRadius: new BorderRadius.all(
- const Radius.circular(20.0)),
- border: Border.all(color: Colors.grey)),
- child: Padding(
- padding: EdgeInsets.all(10),
- child: Text((_currentDocType2 == null)
- ? "Pilih Jenis Dokumen"
- : _currentDocType2)))),
- new InkWell(
- highlightColor: Colors.blue.withAlpha(30),
- splashColor: Colors.blue.withAlpha(20),
- child: Row(children: <Widget>[
- SizedBox(width: 100, child: Text("Tanggal Awal")),
- Container(
- width: 120,
- padding: EdgeInsets.all(8),
- decoration: BoxDecoration(
- color: Colors.grey[200],
- border: Border.all(color: Colors.grey),
- borderRadius:
- BorderRadius.all(Radius.circular(8.0))),
- child: Text((selectedDate == null)
- ? "${myFormat.format(_currentDate)}"
- : "$selectedDate"),
- )
- ]),
- onTap: () => _selectDateStart(context)),
- new InkWell(
- highlightColor: Colors.blue.withAlpha(30),
- splashColor: Colors.blue.withAlpha(20),
- child: Row(children: <Widget>[
- SizedBox(width: 100, child: Text("Tanggal Akhir")),
- Container(
- width: 120,
- padding: EdgeInsets.all(8),
- decoration: BoxDecoration(
- color: Colors.grey[200],
- border: Border.all(color: Colors.grey),
- borderRadius:
- BorderRadius.all(Radius.circular(8.0))),
- child: Text((post2db == "CREATE")
- ? (selectedDateEnd == null)
- ? "${myFormat.format(_currentDateEnd)}"
- : "$selectedDateEnd"
- : (selectedDateEnd == null)
- ? "$ebmTanggal"
- : "$selectedDateEnd"),
- )
- ]),
- onTap: () => _selectDateEnd(context)),
- InkWell(
- onTap: () => {
- setState(() {
- loading = true;
- isFromSheet = false;
- }),
- Navigator.pop(context),
- getData(selectedDate, selectedDateEnd, _currentDocType2,
- "0", "100"),
- print(selectedDate + " " + selectedDateEnd)
- },
- child: Container(
- margin: EdgeInsets.all(10.0),
- padding: EdgeInsets.all(10.0),
- decoration: BoxDecoration(
- color: Colors.lightBlue,
- borderRadius:
- new BorderRadius.all(const Radius.circular(20.0)),
- ),
- width: double.infinity,
- child: Text("CARI",
- style: TextStyle(color: Colors.white),
- textAlign: TextAlign.center),
- ),
- )
- ],
- ),
- ]));
- });
- }
- void showDialogListData(BuildContext context, String listData) {
- AlertDialog dialog = new AlertDialog(
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(10.0),
- ),
- elevation: 0.0,
- backgroundColor: Colors.transparent,
- content: listDataContent(context, listData));
- showDialog(context: context, child: dialog);
- }
- listDataContent(context, listData) {
- return Container(
- height: 350,
- width: 300,
- decoration: new BoxDecoration(
- color: Colors.blue,
- shape: BoxShape.rectangle,
- borderRadius: BorderRadius.circular(20.0),
- boxShadow: [
- BoxShadow(
- color: Colors.black26,
- blurRadius: 10.0,
- offset: const Offset(0.0, 10.0),
- ),
- ],
- ),
- child: Column(
- children: <Widget>[
- Container(
- padding: EdgeInsets.only(top: 10, bottom: 10),
- child: Text("$listData",
- style: TextStyle(
- color: Colors.white, fontWeight: FontWeight.bold)),
- ),
- Container(
- decoration: new BoxDecoration(
- color: Colors.white,
- shape: BoxShape.rectangle,
- borderRadius: BorderRadius.only(
- bottomLeft: const Radius.circular(20.0),
- bottomRight: const Radius.circular(20.0))),
- height: 308,
- width: 300,
- padding: EdgeInsets.only(bottom: 10),
- child: ListView.builder(
- shrinkWrap: true,
- itemCount: (listData == 'Jenis Dokumen')
- ? (jenisDokumenList == null)
- ? 0
- : jenisDokumenList.length
- : (statusDokumenList == null)
- ? 0
- : statusDokumenList.length,
- itemBuilder: (BuildContext context, int index) {
- return InkWell(
- highlightColor: Colors.white.withAlpha(30),
- splashColor: Colors.white.withAlpha(20),
- child: Padding(
- padding: EdgeInsets.all(5),
- child: Text((listData == 'Jenis Dokumen')
- ? jenisDokumenList[index]["title"]
- : statusDokumenList[index]),
- ),
- onTap: () => {
- Navigator.pop(context),
- rebuildView(index, listData)
- },
- );
- }))
- ],
- ));
- }
- void rebuildView(int index, String listData) {
- // (listData == 'Jenis Dokumen') ? setState(() {
- _currentDocType1 = jenisDokumenList[index]["title"];
- _currentDocType2 = jenisDokumenList[index]["title"];
- // }) : setState(() {
- // _currentDocStat = statusDokumenList[index];
- // });
- Navigator.pop(context);
- _bottomSheetFilterSearch(context);
- }
- void rebuildDate(String dateAwal) {
- setState(() {
- selectedDate = dateAwal;
- });
- Navigator.pop(context);
- _bottomSheetFilterSearch(context);
- }
- void rebuildDateEnd(String dateAakhir) {
- setState(() {
- selectedDateEnd = dateAakhir;
- });
- Navigator.pop(context);
- _bottomSheetFilterSearch(context);
- }
- Future getJenisList() async {
- http.Response response = await http.post(
- "$baseUrl${serverCode}index.php?c=c_cek_foto&m=get_action",
- body: {
- "task": "LIST",
- "query": "",
- "tgl_start": "",
- "tgl_end": "",
- "jenis_dokumen": "",
- "start": "0",
- "limit": "100"
- });
- print("$baseUrl${serverCode}index.php?c=c_cek_foto&m=get_action");
- if (response.statusCode == 200) {
- dataJenis = json.decode(response.body);
- setState(() {
- jenisDokumenList = (dataJenis["total"] == "0") ? null : dataJenis["results"];
- loading = false;
- });
- } else {
- return null;
- }
- }
- void getCredential() async {
- SharedPreferences prefs = await SharedPreferences.getInstance();
- setState(() {
- _currentCabang = prefs.getString("login_cabang");
- groupId = prefs.getString("group_id");
- });
- // if (groupId == "5") {
- // //HRD
- // jenisDokumenList = [
- // {'jenis': 'terima_beli', 'keterangan': 'Terima Beli'},
- // {'jenis': 'kirim_barang', 'keterangan': 'Kirim Barang'},
- // {'jenis': 'izin_karyawan', 'keterangan': 'Izin Karyawan'}
- // ];
- // } else if (groupId == "15") {
- // //kepala gudang
- // jenisDokumenList = [
- // {'jenis': 'vonis_loyo', 'keterangan': 'Vonis Loyo'},
- // {'jenis': 'mati_kolam', 'keterangan': 'Mati Kolam'},
- // {'jenis': 'izin_karyawan', 'keterangan': 'Izin Karyawan'}
- // ];
- // } else {
- // //direksi atau administrator
- // jenisDokumenList = [
- // {'jenis': 'harga_beli', 'keterangan': 'Harga Beli'},
- // {'jenis': 'order_beli', 'keterangan': 'Order Beli'},
- // {'jenis': 'nota_beli', 'keterangan': 'Nota Beli'},
- // {'jenis': 'subsidi_beli', 'keterangan': 'Subsidi Beli'},
- // {'jenis': 'personal', 'keterangan': 'Supplier / Customer'},
- // {'jenis': 'register_pkk', 'keterangan': 'Register PKK'},
- // {
- // 'jenis': 'mutasi_tabung_oksigen',
- // 'keterangan': 'Mutasi Tabung Oksigen'
- // },
- // {'jenis': 'harga_packing', 'keterangan': 'Harga Packing'},
- // {'jenis': 'sp_material', 'keterangan': 'Surat Pesanan Material'},
- // {'jenis': 'laba_rugi_harian', 'keterangan': 'Laba Rugi Harian'},
- // {'jenis': 'register_cargo_export', 'keterangan': 'Ubahan Upi'},
- // {'jenis': 'izin_karyawan', 'keterangan': 'Izin Karyawan'}
- // ];
- // }
- statusDokumenList = ["Tunggu", "Tertutup", "Batal"];
- }
- Future getData(String tglStart, String tglEnd, String jenisDokumen,
- String start, String limit) async {
- // SharedPreferences prefs = await SharedPreferences.getInstance();
- http.Response response = await http.post(
- "$baseUrl$serverCode" + "index.php?c=c_cek_foto&m=get_print_data",
- body: {
- "query": "",
- "tgl_start": tglStart,
- "tgl_end": tglEnd,
- "jenis_dokumen": jenisDokumen,
- "start": start,
- "limit": limit
- });
- print("$baseUrl$serverCode" + "index.php?c=c_cek_foto&m=get_print_data");
- print(response.body);
- if (response.statusCode == 200) {
- print(response.toString());
- setState(() {
- // isFromSheet = true;
- flutterWebViewPlugin.show();
- flutterWebViewPlugin.reload();
- // flutterWebViewPlugin.launch("$baseUrl${serverCode}print/p_cek_foto.html");
- // loading = false;
- print(response.body);
- loading = false;
- });
- } else {
- return null;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement