Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:loading/loading.dart';
- import 'package:pull_to_refresh/pull_to_refresh.dart';
- import 'package:loading/indicator/ball_pulse_indicator.dart';
- import 'package:shared_preferences/shared_preferences.dart';
- import 'package:http/http.dart' as http;
- import 'dart:async';
- import 'dart:convert';
- class EbmListPage extends StatefulWidget {
- @override
- _EbmListPageState createState() => _EbmListPageState();
- }
- class _EbmListPageState extends State<EbmListPage> {
- //Untuk List Data
- Map data;
- List ebmListData;
- bool kedatangan;
- Map dataJenis;
- List jenisList;
- List<dynamic> jenisListFilter = [];
- String filter;
- String messageInfo = "Tekan tombol filter diatas untuk menampilkan data";
- //Variables
- String baseUrl, serverCode;
- bool loading = true;
- String tanggal;
- String _currentJenisId, _currentJenis;
- String _isButtonEnabled = "N";
- String fromDetail;
- RefreshController _refreshController =
- RefreshController(initialRefresh: false);
- //void _onChangedKedatangan(bool value) => setState(() => kedatangan = value);
- @override
- void initState() {
- super.initState();
- getServerUrl();
- }
- @override
- Widget build(BuildContext context) {
- final containerLoading = Center(
- child: Column(mainAxisSize: MainAxisSize.max, children: <Widget>[
- Padding(
- padding: EdgeInsets.only(top: MediaQuery.of(context).size.height / 2.2),
- ),
- Loading(
- indicator: BallPulseIndicator(),
- size: 50.0,
- color: Colors.lightBlue,
- ),
- Text("Memuat Data")
- ]));
- final containerNoData = Center(
- child: Text(messageInfo,
- style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)));
- final containerListData = SmartRefresher(
- enablePullDown: true,
- enablePullUp: false,
- header: WaterDropHeader(waterDropColor: Colors.lightBlue),
- footer: CustomFooter(
- builder: (BuildContext context, LoadStatus mode) {
- Widget body;
- if (mode == LoadStatus.noMore) {
- body = Text("No more Data");
- } else if (mode == LoadStatus.loading) {
- body = Loading(
- indicator: BallPulseIndicator(),
- size: 50.0,
- color: Colors.lightBlue,
- );
- } else if (mode == LoadStatus.failed) {
- body = Text("Load Failed!Click retry!");
- } else if (mode == LoadStatus.canLoading) {
- body = Text("release to load more");
- } else {
- body = Text("pull up load");
- }
- return Container(
- height: 55.0,
- child: Center(child: body),
- );
- },
- ),
- controller: _refreshController,
- onRefresh: _onRefresh,
- onLoading: _onLoading,
- child: ListView.builder(
- itemCount: (ebmListData == null) ? 0 : ebmListData.length,
- itemBuilder: (BuildContext context, int index) {
- return InkWell(
- highlightColor: Colors.white.withAlpha(30),
- splashColor: Colors.white.withAlpha(20),
- child: Card(
- color: (ebmListData[index]["ebm_kedatangan"] == 'Y')
- ? Colors.lightBlue
- : (ebmListData[index]["ebm_kedatangan"] == 'N')
- ? Colors.orange
- : Colors.red,
- margin: EdgeInsets.fromLTRB(10.0, 5.0, 10.0, 5.0),
- elevation: 3,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(7.0)),
- child: Container(
- decoration: BoxDecoration(
- color: Colors.white,
- borderRadius: BorderRadius.only(
- topRight: Radius.circular(7.0),
- bottomRight: Radius.circular(7.0),
- )),
- margin: EdgeInsets.only(left: 10),
- child: Padding(
- padding: EdgeInsets.all(10.0),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Row(
- mainAxisAlignment:
- MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Text(
- "${ebmListData[index]["personal_nama"]}",
- style: TextStyle(
- fontWeight: FontWeight.bold)),
- Row(
- children: <Widget>[
- Image.asset(
- (ebmListData[index]
- ["ebm_kedatangan"] ==
- 'Y')
- ? 'assets/images/tick.png'
- : (ebmListData[index][
- "ebm_kedatangan"] ==
- 'N')
- ? 'assets/images/hourglass.png'
- : 'assets/images/cancel.png',
- height: 15,
- width: 15,
- color: (ebmListData[index]
- ["ebm_kedatangan"] ==
- 'Y')
- ? Colors.lightBlue
- : (ebmListData[index][
- "ebm_kedatangan"] ==
- 'N')
- ? Colors.orange
- : Colors.red,
- ),
- Text(
- (ebmListData[index]
- ["ebm_kedatangan"] ==
- 'Y')
- ? "OK"
- : (ebmListData[index][
- "ebm_kedatangan"] ==
- 'N')
- ? "Belum"
- : "Batal",
- style: TextStyle(
- color: (ebmListData[index][
- "ebm_kedatangan"] ==
- 'Y')
- ? Colors.lightBlue
- : (ebmListData[index][
- "ebm_kedatangan"] ==
- 'N')
- ? Colors.orange
- : Colors.red,
- ))
- ],
- )
- ],
- ),
- Text("${ebmListData[index]["ebm_tanggal"]}"),
- SizedBox(height: 10),
- Text(
- "Jenis: ${ebmListData[index]["jenis_nama"]}"),
- Text(
- "Estimasi: ${ebmListData[index]["ebm_est_jml_box"]} Box / ${ebmListData[index]["ebm_est_jml_kg"]} Kg")
- ],
- )))),
- onTap: () => Navigator.of(context)
- .pushNamed('/EbmDetailPage', arguments: {
- 'post2db': "UPDATE",
- 'ebmId': ebmListData[index]["ebm_id"],
- 'ebmTanggal': ebmListData[index]["ebm_tanggal"],
- 'ebmPersonalId': ebmListData[index]["pkode_id"],
- 'ebmPersonalNama': ebmListData[index]["personal_nama"],
- 'ebmJenisId': ebmListData[index]["jenis_id"],
- 'ebmJenisNama': ebmListData[index]["jenis_nama"],
- 'ebmKedatangan': ebmListData[index]["ebm_kedatangan"],
- 'ebmJmlKg': ebmListData[index]["ebm_est_jml_kg"],
- 'ebmKetLapangan': ebmListData[index]
- ["ebm_keterangan_lapangan"],
- 'ebmKetAdmin': ebmListData[index]["ebm_keterangan"],
- 'ebmjmlBox': ebmListData[index]["ebm_est_jml_box"],
- 'ebmRevised': ebmListData[index]["ebm_revised"],
- }));
- }));
- final body = Container(
- padding: EdgeInsets.only(top: 10, bottom: 10),
- color: Colors.grey[100],
- child: (loading)
- ? containerLoading
- : (ebmListData == null) ? containerNoData : containerListData);
- return Scaffold(
- appBar: new AppBar(
- actions: <Widget>[
- new IconButton(
- icon: new Icon(Icons.tune, color: Colors.white),
- onPressed: () => {
- print(_isButtonEnabled),
- if (_isButtonEnabled == "Y") {
- showDialogListJenis(context, "Jenis")
- } else {
- // null,
- // print(_isButtonDisabled)
- // showDialogListJenis(context, "Jenis")
- }
- }),
- ],
- title: Container(
- width: double.infinity,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Text(
- 'Daftar Estimasi Barang Masuk',
- textAlign: TextAlign.left,
- ),
- Text(
- 'Tanggal $tanggal',
- textAlign: TextAlign.left,
- style: TextStyle(fontSize: 13),
- ),
- ],
- ),
- ),
- elevation: 3,
- ),
- body: body);
- }
- //All Function
- 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/index.php?c=c_estimasi_barang_masuk&m=get_action";
- } else if (prefs.getString("login_cabang") == 'MJWSBY') {
- serverCode =
- "koffie_mjw_sby/index.php?c=c_estimasi_barang_masuk&m=get_action";
- } else {
- serverCode =
- "koffie_mjw_testing/index.php?c=c_estimasi_barang_masuk&m=get_action";
- }
- // getEbmList("");
- getJenisList();
- final Map arguments = ModalRoute.of(context).settings.arguments as Map;
- setState(() {
- tanggal = arguments["tanggal"];
- fromDetail = arguments["fromDetail"];
- print("kunam $fromDetail");
- if (fromDetail != null) {
- getEbmList("0");
- }
- });
- });
- }
- Future getEbmList(String id) async {
- loading = true;
- http.Response response = await http.post("$baseUrl$serverCode", body: {
- "task": "LIST",
- "jenis_id": id,
- "ebm_start_date": tanggal,
- "ebm_end_date": tanggal,
- "ebm_tahun": "",
- "ebm_bulan": "",
- "start": "0",
- "end": "100",
- });
- if (response.statusCode == 200) {
- data = json.decode(response.body);
- setState(() {
- ebmListData = (data["total"] == "0") ? null : data["results"];
- messageInfo = "Tidak ada barang masuk untuk jenis ini";
- loading = false;
- });
- print('Url : $baseUrl$serverCode');
- print('ResponseData : $ebmListData');
- } else {
- return null;
- }
- }
- Future getJenisList() async {
- http.Response response = await http.post(
- "$baseUrl${serverCode}index.php?c=c_estimasi_barang_masuk&m=get_ebm_jenis",
- body: {});
- if (response.statusCode == 200) {
- dataJenis = json.decode(response.body);
- setState(() {
- jenisList = (dataJenis["total"] == "0") ? null : dataJenis["results"];
- loading = false;
- _isButtonEnabled = "Y";
- });
- } else {
- return null;
- }
- }
- void _onRefresh() async {
- await Future.delayed(Duration(milliseconds: 1000));
- _refreshController.refreshCompleted();
- getEbmList("");
- }
- void _onLoading() async {
- await Future.delayed(Duration(milliseconds: 1000));
- setState(() {});
- _refreshController.loadComplete();
- }
- void onSearchTextChanged(String text, String dataList) async {
- jenisListFilter.clear();
- setState(() {
- filter = text.toUpperCase();
- });
- if (text.isEmpty) {
- setState(() {});
- return;
- }
- for (var i = 0; i < jenisList.length; i++) {
- if (jenisList[i]["jenis_nama"].contains(filter)) {
- jenisListFilter.add(jenisList[i]);
- }
- }
- print('new list: ' + jenisListFilter.toString());
- print('new length: ' + jenisListFilter.length.toString());
- print(filter);
- setState(() {});
- }
- void showDialogListJenis(BuildContext context, dataList) {
- AlertDialog dialog = new AlertDialog(
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(10.0),
- ),
- elevation: 0.0,
- backgroundColor: Colors.transparent,
- content: dialogContent(context, dataList));
- showDialog(context: context, child: dialog);
- }
- dialogContent(context, dataList) {
- return Container(
- height: 390,
- width: MediaQuery.of(context).size.width,
- 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("Daftar $dataList",
- 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))),
- padding: EdgeInsets.only(bottom: 10),
- child: Column(children: <Widget>[
- Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: <Widget>[
- Container(
- height: 30,
- width: MediaQuery.of(context).size.width / 1.8,
- margin: EdgeInsets.all(5),
- child: TextFormField(
- // controller: filterSupplier,
- onChanged: (text) {
- onSearchTextChanged(text, dataList);
- },
- autofocus: false,
- decoration: InputDecoration(
- contentPadding:
- EdgeInsets.fromLTRB(10.0, 5.0, 5.0, 10.0),
- hintText: "Cari $dataList"),
- )),
- InkWell(
- onTap: () {
- Navigator.of(context).pop();
- showDialogListJenis(context, dataList);
- },
- child: Container(
- padding: EdgeInsets.only(right: 20),
- height: 30,
- width: 35,
- //color: Colors.red,
- child: Icon(Icons.search, color: Colors.black),
- ))
- ],
- ),
- Container(
- width: MediaQuery.of(context).size.width,
- height: 298,
- child: SmartRefresher(
- enablePullDown: true,
- enablePullUp: false,
- header: WaterDropHeader(waterDropColor: Colors.lightBlue),
- footer: CustomFooter(
- builder: (BuildContext context, LoadStatus mode) {
- Widget body;
- if (mode == LoadStatus.noMore) {
- body = Text("No more Data");
- } else if (mode == LoadStatus.loading) {
- body = Loading(
- indicator: BallPulseIndicator(),
- size: 50.0,
- color: Colors.lightBlue,
- );
- } else if (mode == LoadStatus.failed) {
- body = Text("Load Failed!Click retry!");
- } else if (mode == LoadStatus.canLoading) {
- body = Text("release to load more");
- } else {
- body = Text("pull up load");
- }
- return Container(
- height: 55.0,
- child: Center(child: body),
- );
- },
- ),
- controller: _refreshController,
- onRefresh: () => _onRefresh(),
- onLoading: _onLoading,
- child: ListView.builder(
- shrinkWrap: true,
- // itemCount: (dataList == 'Supplier') ?
- // (filter == null || filter == "") ? (supplierList == null) ? 0 : supplierList.length : supplierListFilter.length :
- // (filter == null || filter == "") ? (jenisList == null) ? 0 : jenisList.length : jenisListFilter.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: (dataList == 'Supplier')
- ? Column(
- crossAxisAlignment:
- CrossAxisAlignment.start,
- children: <Widget>[
- Row(
- // children: <Widget>[
- // Text((filter == "" || filter == null) ? "["+supplierList[index]["pkode_nama"]+"] " : "["+supplierListFilter[index]["pkode_nama"]+"] ",
- // style: TextStyle(color: Colors.red, /*fontWeight: FontWeight.bold*/)
- // ),
- // Text((filter == "" || filter == null) ? supplierList[index]["personal_nama"] : supplierListFilter[index]["personal_nama"])
- // ],
- ),
- //Text((filter == "" || filter == null) ? supplierList[index]["personal_nama_dan_nama_perusahaan"] : supplierListFilter[index]["personal_nama_dan_nama_perusahaan"]),
- Text((filter == "" || filter == null)
- ? (jenisList[index]["jenis_nama"] ==
- null)
- ? "Jenis: -"
- : "Jenis : " +
- jenisList[index]
- ["jenis_nama"]
- : (jenisList[index]["jenis_nama"] ==
- null)
- ? "Jenis: -"
- : "Jenis : " +
- jenisList[index]
- ["jenis_nama"]),
- ],
- )
- : Text((filter == "" || filter == null)
- ? jenisList[index]["jenis_nama"]
- : jenisListFilter[index]["jenis_nama"]),
- ),
- onTap: () => {
- setState(() {
- if (filter == null || filter == "") {
- _currentJenisId =
- "${jenisList[index]["jenis_id"]}";
- _currentJenis =
- "${jenisList[index]["jenis_nama"]}";
- getEbmList(_currentJenisId);
- } else {
- _currentJenisId =
- "${jenisListFilter[index]["jenis_id"]}";
- _currentJenis =
- "${jenisListFilter[index]["jenis_nama"]}";
- filter = "";
- jenisListFilter.clear();
- getEbmList(_currentJenisId);
- }
- Navigator.pop(context);
- })
- },
- );
- }),
- ),
- )
- ]))
- ]));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement