flutter app untuk unitstock
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 
 

1075 řádky
53 KiB

  1. import 'dart:async';
  2. import 'dart:io';
  3. import 'package:flutter/rendering.dart';
  4. import 'package:flutter/widgets.dart';
  5. import 'package:path/path.dart';
  6. import 'package:flutter/cupertino.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:path_provider/path_provider.dart';
  9. import 'Util/DBHelper.dart';
  10. import 'Util/Util.dart';
  11. import 'Util/download_Upload_Handler.dart';
  12. import 'package:intl/intl.dart';
  13. import 'main.dart';
  14. import 'Util/Prefs.dart';
  15. import 'Util/UnitModel.dart';
  16. class HomePage extends StatefulWidget {
  17. // HomePage({Key key}) : super(key: key);
  18. final String title;
  19. HomePage({this.title});
  20. @override
  21. _HomePageState createState() => _HomePageState();
  22. }
  23. class _HomePageState extends State<HomePage> {
  24. Util util = new Util();
  25. StreamSubscription progressDLStream,progressULStream;
  26. String lastDownload = '';
  27. String lastUpload = '';
  28. double progressDL,progressUL;
  29. String timeString = '';
  30. bool isLoading = false;
  31. String state = '';
  32. final hostAddress = new TextEditingController();
  33. clearData(context)async{
  34. setState(() {
  35. progressDL = null;
  36. isLoading = false;
  37. });
  38. String errMsg;
  39. bool result = await showDialog(context: context,builder: (context)=>WillPopScope(
  40. onWillPop: ()async{
  41. Navigator.pop(context,false);
  42. return false;
  43. },
  44. child: AlertDialog(
  45. title: Text('Clear Data ?'),
  46. content: Text('Proceed to clear any remaining units data on this device?'),
  47. actions: <Widget>[
  48. TextButton(
  49. child: Text('Proceed'),
  50. onPressed: ()async{
  51. util.showLoading(context);
  52. await Future.sync(()async{
  53. await prefs.remove(keyClass.lastDownload);
  54. await prefs.remove(keyClass.lastUpload);
  55. await prefs.remove(keyClass.targetProccess);
  56. await prefs.remove(keyClass.submitProccess);
  57. await prefs.remove(keyClass.stock_id);
  58. setState(() {
  59. lastUpload = '';
  60. lastDownload = '';
  61. timeString = '';
  62. });
  63. // var result = await DBHelper.database.deleteAll();
  64. // if(result!=null) {
  65. // await DBHelper.database.closeDb();
  66. // if(result!=null){
  67. try{
  68. Directory documentsDirectory = await getApplicationDocumentsDirectory();
  69. String path = join(documentsDirectory.path, "UnitStocking.db");
  70. File db = File(path);
  71. if(db.existsSync()){
  72. db.deleteSync();
  73. }
  74. }
  75. catch(e){
  76. print(e);
  77. util.showFlushbar(context, 'Failed to delete database file',color: Colors.red);
  78. }
  79. // }
  80. // else{
  81. // errMsg = 'Failed to clear unit data';
  82. // }
  83. // }
  84. // else{
  85. // errMsg = 'Failed to clear unit data';
  86. // }
  87. });
  88. Navigator.pop(context);
  89. Navigator.pop(context,true);
  90. util.showFlushbar(context,errMsg??'Data Cleared');
  91. },
  92. ),
  93. TextButton(
  94. child: Text('Cancel'),
  95. onPressed: (){Navigator.pop(context,false);},
  96. )
  97. ],
  98. ),
  99. ));
  100. return result;
  101. }
  102. loadState()async{
  103. String company = prefs.getString(keyClass.company);
  104. if(prefs.getString(keyClass.stock_id) == null)
  105. {
  106. valueTab value = await DBHelper.database.getValue(keyClass.stock_id);
  107. await prefs.setString(keyClass.stock_id, value.value);
  108. }
  109. String stock_taking_id = prefs.getString(keyClass.stock_id);
  110. if(company!=null&&stock_taking_id!=null){
  111. var result = await util.JsonDataPostRaw({"company":company,"stockTakingId":stock_taking_id}, '${prefs.getString(keyClass.hostAddress)}/stock_taking/state/');
  112. if(result['STATUS']==1){
  113. setState(() {
  114. state = result['DATA'];
  115. });
  116. }
  117. }
  118. }
  119. @override
  120. void initState() {
  121. // TODO: implement initState
  122. super.initState();
  123. loadState();
  124. lastDownload = prefs.getString(keyClass.lastDownload)??'';
  125. lastUpload = prefs.getString(keyClass.lastUpload)??'';
  126. }
  127. changeCabang(context)async{
  128. util.showLoading(context);
  129. var result = await util.JsonDataPostRaw({"company":prefs.getString(keyClass.company),"User":prefs.getString(keyClass.loginId)}, '${prefs.getString(keyClass.hostAddress)}/user/cabangs/');
  130. Navigator.pop(context);
  131. if(result['STATUS']==1){
  132. var selected = prefs.getString(keyClass.cabang_id)??result['DATA'][0]["RETURN_VALUE"];
  133. return await showDialog(context: context,builder: (context)=>StatefulBuilder(
  134. builder:(context,setState)=>
  135. Material(
  136. color: Colors.white.withOpacity(0.9),
  137. child: Center(
  138. child: Container(
  139. decoration: BoxDecoration(
  140. color: Colors.white,
  141. boxShadow: [
  142. BoxShadow(
  143. color: Colors.grey.withOpacity(0.5),
  144. spreadRadius: 2,
  145. blurRadius: 2,
  146. offset: Offset(0, 0), // changes position of shadow
  147. ),
  148. ],
  149. borderRadius: BorderRadius.circular(5)
  150. ),
  151. // height: MediaQuery.of(context).size.height/3.2,
  152. height:220,
  153. width: MediaQuery.of(context).size.width*0.75,
  154. child: Column(
  155. children: <Widget>[
  156. Flexible(
  157. flex:3,
  158. child: Container(
  159. padding: EdgeInsets.only(top:10,left: 10,right: 10),
  160. alignment: Alignment.center,
  161. decoration: BoxDecoration(
  162. // color: Colors.indigo,
  163. borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5))
  164. ),
  165. child: Column(
  166. mainAxisSize: MainAxisSize.min,
  167. crossAxisAlignment: CrossAxisAlignment.center,
  168. children: <Widget>[
  169. Icon(Icons.business,size: 70,color: Colors.indigo,),
  170. SizedBox(height: 5,),
  171. Text('Set Cabang',style: TextStyle(fontWeight: FontWeight.bold,fontSize: 16,color: Colors.indigo),)
  172. ],
  173. ),
  174. ),
  175. ),
  176. Flexible(
  177. flex: 1,
  178. child: Container(
  179. padding: EdgeInsets.only(left: 20,right: 20),
  180. alignment: Alignment.centerLeft,
  181. child: Theme(
  182. data: ThemeData(
  183. canvasColor: Colors.white,
  184. primaryColor: Colors.indigo,
  185. accentColor: Colors.indigo,
  186. hintColor: Colors.indigo
  187. ),
  188. child: DropdownButtonFormField(
  189. style: TextStyle(color: Colors.black.withOpacity(0.6),fontWeight: FontWeight.w500,fontSize: 14,),
  190. decoration: InputDecoration(
  191. contentPadding: EdgeInsets.all(8.0),
  192. ),
  193. value: selected,
  194. onChanged: (value){
  195. setState(() {
  196. selected = value;
  197. });
  198. },
  199. items: result['DATA'].map<DropdownMenuItem<dynamic>>((item){
  200. return DropdownMenuItem(
  201. value: item['RETURN_VALUE'],
  202. child: Text(item["DISPLAY_VALUE"]),
  203. );
  204. }).toList(),
  205. ),
  206. ),
  207. ),
  208. ),
  209. Flexible(
  210. flex: 1,
  211. child: Container(
  212. child: Row(
  213. mainAxisAlignment: MainAxisAlignment.end,
  214. children: <Widget>[
  215. TextButton(
  216. child: Text('OK',style: TextStyle(color: Colors.indigo),),
  217. onPressed: ()async{
  218. if(selected!=prefs.getString(keyClass.cabang_id)){
  219. prefs.setString(keyClass.cabang_id,selected);
  220. await Future.sync(()async{
  221. await prefs.remove(keyClass.lastDownload);
  222. await prefs.remove(keyClass.lastUpload);
  223. await prefs.remove(keyClass.targetProccess);
  224. await prefs.remove(keyClass.submitProccess);
  225. lastUpload = '';
  226. lastDownload = '';
  227. timeString = '';
  228. try{
  229. Directory documentsDirectory = await getApplicationDocumentsDirectory();
  230. String path = join(documentsDirectory.path, "UnitStocking.db");
  231. File db = File(path);
  232. if(db.existsSync()){
  233. db.deleteSync();
  234. }
  235. }
  236. catch(e){
  237. print(e);
  238. util.showFlushbar(context, 'Failed to delete database file',color: Colors.red);
  239. }
  240. });
  241. Navigator.pop(context,true);
  242. }
  243. else{
  244. Navigator.pop(context,false);
  245. }
  246. },
  247. ),
  248. ],
  249. ),
  250. ),
  251. )
  252. ],
  253. ),
  254. ),
  255. ),
  256. ),
  257. // AlertDialog(
  258. // title: Text('Set Cabang'),
  259. // content: DropdownButtonFormField(
  260. // value: selected,
  261. // onChanged: (value){
  262. // setState(() {
  263. // selected = value;
  264. // });
  265. // },
  266. // items: result['DATA'].map<DropdownMenuItem<dynamic>>((item){
  267. // return DropdownMenuItem(
  268. // value: item['RETURN_VALUE'],
  269. // child: Text(item["DISPLAY_VALUE"]),
  270. // );
  271. // }).toList(),
  272. // ),
  273. // actions: <Widget>[
  274. // TextButton(
  275. // child: Text('OK'),
  276. // onPressed: ()async{
  277. // if(selected!=prefs.getString(keyClass.cabang_id)){
  278. // prefs.setString(keyClass.cabang_id,selected);
  279. // await Future.sync(()async{
  280. // await prefs.remove(keyClass.lastDownload);
  281. // await prefs.remove(keyClass.lastUpload);
  282. // await prefs.remove(keyClass.targetProccess);
  283. // await prefs.remove(keyClass.submitProccess);
  284. // lastUpload = '';
  285. // lastDownload = '';
  286. // timeString = '';
  287. //// var result = await DBHelper.database.deleteAll();
  288. //// if(result!=null) {
  289. //// await DBHelper.database.closeDb();
  290. //// if(result!=null){
  291. // try{
  292. // Directory documentsDirectory = await getApplicationDocumentsDirectory();
  293. // String path = join(documentsDirectory.path, "UnitStocking.db");
  294. // File db = File(path);
  295. // if(db.existsSync()){
  296. // db.deleteSync();
  297. // }
  298. // }
  299. // catch(e){
  300. // print(e);
  301. // util.showFlushbar(context, 'Failed to delete database file',color: Colors.red);
  302. // }
  303. //// }
  304. //// else{
  305. //// errMsg = 'Failed to clear unit data';
  306. //// }
  307. //// }
  308. //// else{
  309. //// errMsg = 'Failed to clear unit data';
  310. //// }
  311. // });
  312. // Navigator.pop(context,true);
  313. // }
  314. // else{
  315. // Navigator.pop(context,false);
  316. // }
  317. //// util.showLoading(context);
  318. //
  319. //// Navigator.pop(context);
  320. // },
  321. // )
  322. // ],
  323. // ),
  324. ));
  325. }
  326. else{
  327. util.showFlushbar(context, result['DATA'],color: Colors.red);
  328. return false;
  329. }
  330. }
  331. @override
  332. Widget build(BuildContext context) {
  333. return WillPopScope(
  334. onWillPop: ()async{
  335. await showDialog(context: context,builder: (context)=>
  336. Material(
  337. color: Colors.white.withOpacity(0.9),
  338. child: Center(
  339. child: Container(
  340. decoration: BoxDecoration(
  341. color: Colors.white,
  342. boxShadow: [
  343. BoxShadow(
  344. color: Colors.grey.withOpacity(0.5),
  345. spreadRadius: 2,
  346. blurRadius: 2,
  347. offset: Offset(0, 0), // changes position of shadow
  348. ),
  349. ],
  350. borderRadius: BorderRadius.circular(5)
  351. ),
  352. // height: MediaQuery.of(context).size.height/4.8,
  353. height:220,
  354. width: MediaQuery.of(context).size.width*0.75,
  355. child: Column(
  356. children: <Widget>[
  357. Flexible(
  358. flex:3,
  359. child: Container(
  360. padding: EdgeInsets.only(top:10,left: 10,right: 10),
  361. alignment: Alignment.center,
  362. decoration: BoxDecoration(
  363. // color: Colors.indigo,
  364. borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5))
  365. ),
  366. child: Column(
  367. mainAxisSize: MainAxisSize.min,
  368. crossAxisAlignment: CrossAxisAlignment.center,
  369. children: <Widget>[
  370. Icon(Icons.exit_to_app,size: 70,color: Colors.indigo,),
  371. ],
  372. ),
  373. ),
  374. ),
  375. Flexible(
  376. flex: 1,
  377. child: Container(
  378. padding: EdgeInsets.only(left: 20,right: 20),
  379. alignment: Alignment.centerLeft,
  380. child: Text('Keluar dari aplikasi?',style: TextStyle(fontWeight: FontWeight.w500,fontSize: 14,color: Colors.black.withOpacity(0.6)),)
  381. ),
  382. ),
  383. Flexible(
  384. flex: 1,
  385. child: Container(
  386. padding: EdgeInsets.only(bottom:10),
  387. child: Row(
  388. mainAxisAlignment: MainAxisAlignment.end,
  389. children: <Widget>[
  390. TextButton(
  391. child: Text('Exit',style: TextStyle(color: Colors.indigo),),
  392. onPressed: ()async{
  393. Navigator.pop(context);
  394. await locationStream?.cancel();
  395. exit(0);
  396. },
  397. ),
  398. TextButton(
  399. child: Text('Cancel',style: TextStyle(color: Colors.indigo),),
  400. onPressed: (){
  401. Navigator.pop(context);
  402. },
  403. )
  404. ],
  405. ),
  406. ),
  407. )
  408. ],
  409. ),
  410. ),
  411. ),
  412. ),
  413. );
  414. return false;
  415. },
  416. child: Scaffold(
  417. body: Column(
  418. crossAxisAlignment: CrossAxisAlignment.end,
  419. children: <Widget>[
  420. Container(
  421. padding: EdgeInsets.only(bottom: 0,left: 15,right: 10,top: 10),
  422. height: MediaQuery.of(context).size.height/13,
  423. width: MediaQuery.of(context).size.width,
  424. alignment: Alignment.bottomLeft,
  425. child: Row(
  426. crossAxisAlignment: CrossAxisAlignment.end,
  427. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  428. children: <Widget>[
  429. Text('Home',style: TextStyle(color: Colors.indigo.withOpacity(0.8),fontSize: 18,fontWeight: FontWeight.bold),),
  430. PopupMenuButton(
  431. child: Padding(
  432. padding: const EdgeInsets.only(right:2.0),
  433. child: Icon(Icons.menu,color: Colors.indigo.withOpacity(0.8),),
  434. ),
  435. itemBuilder: (context){
  436. return [
  437. PopupMenuItem(
  438. value:'hostChange',
  439. child: Row(
  440. children: <Widget>[
  441. Icon(Icons.network_wifi,color: Colors.black,),
  442. SizedBox(width: 10,),
  443. Text('Change Ip Address')
  444. ],
  445. ),
  446. ),
  447. PopupMenuItem(
  448. value:'cabangChange',
  449. child: Row(
  450. children: <Widget>[
  451. Icon(Icons.business,color: Colors.black,),
  452. SizedBox(width: 10,),
  453. Text('Change Cabang')
  454. ],
  455. ),
  456. ),
  457. PopupMenuItem(
  458. value:'logout',
  459. child: Row(
  460. children: <Widget>[
  461. Icon(Icons.exit_to_app,color: Colors.black,),
  462. SizedBox(width: 10,),
  463. Text('Logout')
  464. ],
  465. ),
  466. ),
  467. ];
  468. },
  469. onSelected: (value)async{
  470. if(value == 'hostChange'){
  471. hostAddress.text = prefs.getString(keyClass.hostAddress);
  472. await showDialog(context: context,builder: (context)=>
  473. Material(
  474. color: Colors.white.withOpacity(0.9),
  475. child: Center(
  476. child: Container(
  477. decoration: BoxDecoration(
  478. color: Colors.white,
  479. boxShadow: [
  480. BoxShadow(
  481. color: Colors.grey.withOpacity(0.5),
  482. spreadRadius: 2,
  483. blurRadius: 2,
  484. offset: Offset(0, 0), // changes position of shadow
  485. ),
  486. ],
  487. borderRadius: BorderRadius.circular(5)
  488. ),
  489. height:220,
  490. // height: MediaQuery.of(context).size.height/3.2,
  491. width: MediaQuery.of(context).size.width*0.75,
  492. child: Column(
  493. children: <Widget>[
  494. Flexible(
  495. flex:3,
  496. child: Container(
  497. padding: EdgeInsets.only(top:10,left: 10,right: 10),
  498. alignment: Alignment.center,
  499. decoration: BoxDecoration(
  500. // color: Colors.indigo,
  501. borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5))
  502. ),
  503. child: Column(
  504. mainAxisSize: MainAxisSize.min,
  505. crossAxisAlignment: CrossAxisAlignment.center,
  506. children: <Widget>[
  507. Icon(Icons.network_wifi,size: 70,color: Colors.indigo,),
  508. SizedBox(height: 5,),
  509. Text('Set Ip Address',style: TextStyle(fontWeight: FontWeight.bold,fontSize: 16,color: Colors.indigo),)
  510. ],
  511. ),
  512. ),
  513. ),
  514. Flexible(
  515. flex: 1,
  516. child: Container(
  517. padding: EdgeInsets.only(left: 20,right: 20),
  518. alignment: Alignment.centerLeft,
  519. child: Theme(
  520. data: ThemeData(
  521. canvasColor: Colors.white,
  522. primaryColor: Colors.indigo,
  523. accentColor: Colors.indigo,
  524. hintColor: Colors.indigo
  525. ),
  526. child: TextField(
  527. controller: hostAddress,
  528. decoration: InputDecoration(
  529. contentPadding: EdgeInsets.all(8),
  530. ),
  531. onSubmitted: (value){
  532. prefs.setString(keyClass.hostAddress,(value=='')?'https://tbg.thamringroup.web.id/ords/tbs/unit/v1':value);
  533. Navigator.pop(context);
  534. },
  535. ),
  536. ),
  537. ),
  538. ),
  539. Flexible(
  540. flex: 1,
  541. child: Container(
  542. child: Row(
  543. mainAxisAlignment: MainAxisAlignment.end,
  544. children: <Widget>[
  545. TextButton(
  546. child: Text('OK',style: TextStyle(color: Colors.indigo),),
  547. onPressed: (){
  548. prefs.setString(keyClass.hostAddress,(hostAddress.text=='')?'https://tbg.thamringroup.web.id/ords/tbs/unit/v1':hostAddress.text);
  549. Navigator.pop(context);
  550. },
  551. )
  552. ],
  553. ),
  554. ),
  555. )
  556. ],
  557. ),
  558. ),
  559. ),
  560. )
  561. // AlertDialog(
  562. // title: Text('Set IP Address'),
  563. // content: TextField(
  564. // controller: hostAddress,
  565. // onSubmitted: (value){
  566. // prefs.setString(keyClass.hostAddress,(value=='')?'https://unitstocksbackend.thamringroup.web.id':value);
  567. // Navigator.pop(context);
  568. // },
  569. // ),
  570. // actions: <Widget>[
  571. // TextButton(
  572. // child: Text('OK'),
  573. // onPressed: (){
  574. // prefs.setString(keyClass.hostAddress,(hostAddress.text=='')?'https://unitstocksbackend.thamringroup.web.id':hostAddress.text);
  575. // Navigator.pop(context);
  576. // },
  577. // )
  578. // ],
  579. // )
  580. );
  581. }
  582. if(value=="cabangChange") {
  583. var res = await changeCabang(context);
  584. if(res??false){
  585. setState(() {
  586. });
  587. }
  588. }
  589. if(value == 'logout'){
  590. prefs.remove(keyClass.cabang_id);
  591. prefs.remove(keyClass.company);
  592. prefs.remove(keyClass.loginId);
  593. prefs.setBool(keyClass.logged_in, false);
  594. Navigator.pushNamed(context, '/login');
  595. }
  596. },
  597. ),
  598. ],
  599. ),
  600. ),
  601. (prefs.getString(keyClass.stock_id)==null)?Container():Padding(
  602. padding: const EdgeInsets.only(top: 8,right: 8),
  603. child: Container(
  604. decoration: BoxDecoration(
  605. color: Colors.indigo.withOpacity(0.9),
  606. borderRadius: BorderRadius.circular(8)
  607. // border: Border.all(),
  608. ),
  609. padding: EdgeInsets.all(8),
  610. child: Row(
  611. mainAxisSize: MainAxisSize.min,
  612. mainAxisAlignment: MainAxisAlignment.end,
  613. crossAxisAlignment: CrossAxisAlignment.center,
  614. children: <Widget>[
  615. Text('Status : ',style: TextStyle(color: Colors.white),),
  616. Text(state??'-',style: TextStyle(fontWeight: FontWeight.bold,color: Colors.white),),
  617. ],
  618. ),
  619. ),
  620. ),
  621. Expanded(
  622. child: Container(
  623. child:
  624. GridView.count(
  625. padding: EdgeInsets.all(10),
  626. crossAxisSpacing: 10,
  627. mainAxisSpacing: 10,
  628. crossAxisCount: 2,
  629. children: <Widget>[
  630. AbsorbPointer(
  631. absorbing: isLoading,
  632. child: InkWell(
  633. splashColor: Colors.black,
  634. onTap: ()async{
  635. bool getData = await showDialog(
  636. context: context,
  637. builder: (context)=>AlertDialog(
  638. title: Text("Get Data Units?"),
  639. content: Text('Fetch data unit for stocking'),
  640. actions: <Widget>[
  641. TextButton(
  642. child: Text('Proceed'),
  643. onPressed: (){
  644. Navigator.pop(context,true);
  645. },
  646. ),
  647. TextButton(
  648. child: Text('Cancel'),
  649. onPressed: (){
  650. Navigator.pop(context,false);
  651. },
  652. )
  653. ],
  654. )
  655. );
  656. if(getData??false){
  657. setState(() {
  658. isLoading = true;
  659. });
  660. var a = Stopwatch();
  661. a.start();
  662. await Future.delayed(Duration(milliseconds: 200));
  663. bool isclear;
  664. Directory documentsDirectory = await getApplicationDocumentsDirectory();
  665. String path = join(documentsDirectory.path, "UnitStocking.db");
  666. File db = File(path);
  667. if(db.existsSync()){
  668. isclear = await clearData(context);
  669. }
  670. else{
  671. isclear = true;
  672. }
  673. if(isclear??false){
  674. print('fetching');
  675. util.showLoading(context);
  676. file_Trans_Handler trans = new file_Trans_Handler();
  677. // trans.downloadFile('UnitStocking.db',"http://172.16.1.8:14002/getSqliteDbtest/TBS/02");
  678. trans.downloadFile('UnitStocking.db',"${prefs.getString(keyClass.hostAddress)}/stock_taking/get_units/${prefs.getString(keyClass.company)}/${prefs.getString(keyClass.cabang_id)}");
  679. progressDLStream = trans.progress.listen((value)async {
  680. if(progressDL==null) {
  681. // print(['test',value]);
  682. if(value!=null) Navigator.pop(context);
  683. }
  684. setState(() {
  685. progressDL = (value!=-1.0)?value:null;
  686. });
  687. if(value!=null&&value >= 1.0) {
  688. progressDLStream.cancel();
  689. progressDL = null;
  690. setState(() {
  691. lastDownload = DateTime.now().toIso8601String();
  692. });
  693. await prefs.setString(keyClass.lastDownload, lastDownload);
  694. await DBHelper.database.insertUpdateValue(new valueTab(name: 'TGL_START',value: DateFormat('dd-MM-yyyy HH:mm:ss').format(DateTime.parse(lastDownload))));
  695. await DBHelper.database.insertUpdateValue(new valueTab(name: 'TGL_STOCK_TAKING',value: DateFormat('dd-MM-yyyy').format(DateTime.parse(lastDownload))));
  696. await DBHelper.database.closeDb();
  697. util.showFlushbar(context,'Data downloaded');
  698. loadState();
  699. a.stop();
  700. if(a.elapsed.inSeconds<3){
  701. await Future.delayed(Duration(seconds: 3-a.elapsed.inSeconds));
  702. }
  703. setState(() {
  704. isLoading = false;
  705. });
  706. }
  707. if(value==-1.0){
  708. setState(() {
  709. isLoading = false;
  710. });
  711. util.showFlushbar(context,'Data download error',color: Colors.red);
  712. }
  713. });
  714. // Navigator.popUntil(context, ModalRoute.withName('/home'));
  715. }
  716. }
  717. },
  718. child: Container(
  719. padding: EdgeInsets.all(5),
  720. decoration: BoxDecoration(
  721. boxShadow: [
  722. BoxShadow(
  723. color: Colors.grey.withOpacity(0.5),
  724. spreadRadius: 2,
  725. blurRadius: 2,
  726. offset: Offset(0, 0), // changes position of shadow
  727. ),
  728. ],
  729. borderRadius: BorderRadius.all(Radius.circular(5.0)),
  730. color: Colors.green.withAlpha(220).withOpacity(0.7),
  731. ),
  732. child: Stack(
  733. children: <Widget>[
  734. Container(
  735. alignment: (progressDL!=null)?Alignment.bottomCenter:Alignment.bottomLeft,
  736. padding: EdgeInsets.only(left: 10,right: 10,top: 10,bottom: 15),
  737. child: (progressDL!=null)?Column(
  738. mainAxisSize: MainAxisSize.min,
  739. children: <Widget>[
  740. LinearProgressIndicator(
  741. value: progressDL,
  742. ),
  743. Text('${(progressDL*100).floor()}%',style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold),)
  744. ],
  745. ):(lastDownload=='')?null:Text('Last download : ${DateFormat('dd MMM yyyy HH:mm').format(DateTime.parse(lastDownload))}',style: TextStyle(color: Colors.white,fontSize: 11,fontWeight: FontWeight.bold)),
  746. ),
  747. Positioned.fill(
  748. child: Column(
  749. mainAxisAlignment: MainAxisAlignment.center,
  750. children: <Widget>[
  751. Icon(Icons.file_upload,size: MediaQuery.of(context).size.width/6,color: Colors.white,),
  752. SizedBox(height: 5,),
  753. Text('Get Data Master',style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold,fontSize: 16),),
  754. ],
  755. ),
  756. ),
  757. ],
  758. ),
  759. ),
  760. ),
  761. ),
  762. InkWell(
  763. splashColor: Colors.black,
  764. onTap: ()async{
  765. await Future.delayed(Duration(milliseconds: 200));
  766. if(lastDownload!=''){
  767. Navigator.pushNamed(context, '/stocking');
  768. }
  769. else{
  770. util.showFlushbar(context, 'Data Master tidak ditemukan. Get data master dulu.');
  771. }
  772. },
  773. child: Container(
  774. padding: EdgeInsets.all(5),
  775. decoration: BoxDecoration(
  776. boxShadow: [
  777. BoxShadow(
  778. color: Colors.grey.withOpacity(0.5),
  779. spreadRadius: 2,
  780. blurRadius: 2,
  781. offset: Offset(0, 0), // changes position of shadow
  782. ),
  783. ],
  784. borderRadius: BorderRadius.all(Radius.circular(5.0)),
  785. color: Colors.blueGrey.withAlpha(230).withOpacity(0.8),
  786. ),
  787. child: Column(
  788. mainAxisAlignment: MainAxisAlignment.center,
  789. children: <Widget>[
  790. Icon(Icons.receipt,size: MediaQuery.of(context).size.width/6,color: Colors.white,),
  791. SizedBox(height: 5,),
  792. Text('Stocking',style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold,fontSize: 16),)
  793. ],
  794. ),
  795. ),
  796. ),
  797. InkWell(
  798. splashColor: Colors.black,
  799. onTap: ()async{
  800. if(lastDownload!=''){
  801. await DBHelper.database.insertUpdateValue(new valueTab(name: 'TGL_SELESAI',value: DateFormat('dd-MM-yyyy HH:mm:ss').format(new DateTime.now())));
  802. await DBHelper.database.closeDb();
  803. file_Trans_Handler trans = new file_Trans_Handler();
  804. bool popped = false;
  805. util.showLoading(context,onwillpop:()async{
  806. await trans.cancel();
  807. popped = true;
  808. return true;
  809. });
  810. var upload = await trans.uploadFile('UnitStocking.db',"${prefs.getString(keyClass.hostAddress)}/stock_taking/upload/",prefs.getString(keyClass.company),prefs.getString(keyClass.cabang_id));
  811. if(!popped){
  812. Navigator.pop(context);
  813. util.showFlushbar(context, upload['DATA'],color:(upload['STATUS']!=1)?Colors.red:Colors.grey);
  814. if(upload['STATUS']==1){
  815. setState(() {
  816. lastUpload = new DateTime.now().toIso8601String();
  817. });
  818. prefs.setString(keyClass.lastUpload, lastUpload);
  819. prefs.setString(keyClass.targetProccess, upload[keyClass.targetProccess]);
  820. }
  821. }
  822. }
  823. else{
  824. util.showFlushbar(context, "Belum ada data yang disimpan.",color: Colors.red);
  825. }
  826. },
  827. child: Container(
  828. padding: EdgeInsets.all(5),
  829. decoration: BoxDecoration(
  830. boxShadow: [
  831. BoxShadow(
  832. color: Colors.grey.withOpacity(0.5),
  833. spreadRadius: 2,
  834. blurRadius: 2,
  835. offset: Offset(0, 0), // changes position of shadow
  836. ),
  837. ],
  838. borderRadius: BorderRadius.all(Radius.circular(5.0)),
  839. color: Colors.indigo.withAlpha(220).withOpacity(0.7),
  840. ),
  841. child: Stack(
  842. children: <Widget>[
  843. Container(
  844. alignment: (progressUL!=null)?Alignment.bottomCenter:Alignment.bottomLeft,
  845. padding: EdgeInsets.only(left: 10,right: 10,top: 10,bottom: 0),
  846. child: (progressUL!=null)?Column(
  847. mainAxisSize: MainAxisSize.min,
  848. children: <Widget>[
  849. LinearProgressIndicator(
  850. value: progressUL,
  851. ),
  852. Text('${(progressUL*100).floor()}%',style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold),)
  853. ],
  854. ):(lastUpload=='')?null:Text('Last upload : ${DateFormat('dd MMM yyyy HH:mm').format(DateTime.parse(lastUpload))}\n${(timeString!='')?'Duration: $timeString':''}',style: TextStyle(color: Colors.white,fontSize: 11,fontWeight: FontWeight.bold)),
  855. ),
  856. Positioned.fill(
  857. child: Column(
  858. mainAxisAlignment: MainAxisAlignment.center,
  859. children: <Widget>[
  860. Icon(Icons.file_upload,size: MediaQuery.of(context).size.width/6,color: Colors.white,),
  861. SizedBox(height: 5,),
  862. Text('Send Data Stokan',style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold,fontSize: 16),),
  863. ],
  864. ),
  865. ),
  866. ],
  867. ),
  868. ),
  869. ),
  870. (prefs.getString(keyClass.targetProccess)==null&&prefs.getBool(keyClass.submitProccess)==null)?InkWell(
  871. splashColor: Colors.black,
  872. onTap: ()async{
  873. await Future.delayed(Duration(milliseconds: 200));
  874. await clearData(context);
  875. },
  876. child: Container(
  877. padding: EdgeInsets.all(5),
  878. decoration: BoxDecoration(
  879. boxShadow: [
  880. BoxShadow(
  881. color: Colors.grey.withOpacity(0.5),
  882. spreadRadius: 2,
  883. blurRadius: 2,
  884. offset: Offset(0, 0), // changes position of shadow
  885. ),
  886. ],
  887. borderRadius: BorderRadius.all(Radius.circular(5.0)),
  888. color: Colors.red.withAlpha(200).withOpacity(0.7),
  889. ),
  890. child: Column(
  891. mainAxisAlignment: MainAxisAlignment.center,
  892. children: <Widget>[
  893. Icon(Icons.restore_from_trash,size: MediaQuery.of(context).size.width/6,color: Colors.white,),
  894. SizedBox(height: 5,),
  895. Text('Clear Data',style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold,fontSize: 16),)
  896. ],
  897. ),
  898. ),
  899. ):
  900. (prefs.getString(keyClass.targetProccess)!=null)?InkWell(
  901. onTap: ()async{
  902. bool result = await showDialog(context: context,builder: (context)=>WillPopScope(
  903. onWillPop: ()async{
  904. Navigator.pop(context,false);
  905. return false;
  906. },
  907. child: AlertDialog(
  908. title: Text('Process Data ?'),
  909. content: Text('Proceed to unpack the uploaded data.'),
  910. actions: <Widget>[
  911. TextButton(
  912. child: Text('Proceed'),
  913. onPressed: ()async{
  914. Navigator.pop(context,true);
  915. },
  916. ),
  917. TextButton(
  918. child: Text('Cancel'),
  919. onPressed: (){Navigator.pop(context,false);},
  920. )
  921. ],
  922. ),
  923. ));
  924. if(result){
  925. util.showLoading(context);
  926. var unpack = await util.JsonDataPutRaw({"cabangId":prefs.getString(keyClass.cabang_id),"company":prefs.getString(keyClass.company),"dbPath":prefs.getString(keyClass.targetProccess)}, '${prefs.getString(keyClass.hostAddress)}/stock_taking/add_collection/');
  927. Navigator.pop(context);
  928. util.showFlushbar(context, unpack['DATA'],color:(unpack['STATUS']!=1)?Colors.red:Colors.grey);
  929. if(unpack['STATUS']==1){
  930. prefs.remove(keyClass.targetProccess);
  931. prefs.setBool(keyClass.submitProccess,true);
  932. }
  933. setState(() {
  934. });
  935. }
  936. },
  937. child: Container(
  938. padding: EdgeInsets.all(5),
  939. decoration: BoxDecoration(
  940. boxShadow: [
  941. BoxShadow(
  942. color: Colors.grey.withOpacity(0.5),
  943. spreadRadius: 2,
  944. blurRadius: 2,
  945. offset: Offset(0, 0), // changes position of shadow
  946. ),
  947. ],
  948. borderRadius: BorderRadius.all(Radius.circular(5.0)),
  949. color: Colors.orangeAccent.withAlpha(230).withOpacity(0.7),
  950. ),
  951. child: Column(
  952. mainAxisAlignment: MainAxisAlignment.center,
  953. children: <Widget>[
  954. Icon(Icons.arrow_forward,size: MediaQuery.of(context).size.width/6,color: Colors.white,),
  955. SizedBox(height: 5,),
  956. Text('Process Units',style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold,fontSize: 16),)
  957. ],
  958. ),
  959. ),
  960. ):
  961. InkWell(
  962. onTap: ()async{
  963. bool result = await showDialog(context: context,builder: (context)=>WillPopScope(
  964. onWillPop: ()async{
  965. Navigator.pop(context,false);
  966. return false;
  967. },
  968. child: AlertDialog(
  969. title: Text('Submit Data ?'),
  970. content: Text('Submit the uploaded data.'),
  971. actions: <Widget>[
  972. TextButton(
  973. child: Text('Submit'),
  974. onPressed: ()async{
  975. Navigator.pop(context,true);
  976. },
  977. ),
  978. TextButton(
  979. child: Text('Cancel'),
  980. onPressed: (){Navigator.pop(context,false);},
  981. )
  982. ],
  983. ),
  984. ));
  985. if(result){
  986. util.showLoading(context);
  987. if(prefs.getString(keyClass.stock_id) == null)
  988. {
  989. valueTab value = await DBHelper.database.getValue(keyClass.stock_id);
  990. await prefs.setString(keyClass.stock_id, value.value);
  991. }
  992. var submits = await util.JsonDataPostRaw({"stockTakingId":prefs.getString(keyClass.stock_id),"company":prefs.getString(keyClass.company),"user_id":prefs.getString(keyClass.loginId)}, '${prefs.getString(keyClass.hostAddress)}/stock_taking/submit/');
  993. Navigator.pop(context);
  994. util.showFlushbar(context, submits['DATA'],color:(submits['STATUS']!=1)?Colors.red:Colors.grey);
  995. if(submits['STATUS']==1){
  996. loadState();
  997. prefs.remove(keyClass.submitProccess);
  998. }
  999. setState(() {
  1000. });
  1001. }
  1002. },
  1003. child: Container(
  1004. padding: EdgeInsets.all(5),
  1005. decoration: BoxDecoration(
  1006. boxShadow: [
  1007. BoxShadow(
  1008. color: Colors.grey.withOpacity(0.5),
  1009. spreadRadius: 2,
  1010. blurRadius: 2,
  1011. offset: Offset(0, 0), // changes position of shadow
  1012. ),
  1013. ],
  1014. borderRadius: BorderRadius.all(Radius.circular(5.0)),
  1015. color: Colors.lightGreen.withAlpha(230),
  1016. ),
  1017. child: Column(
  1018. mainAxisAlignment: MainAxisAlignment.center,
  1019. children: <Widget>[
  1020. Icon(Icons.arrow_forward,size: MediaQuery.of(context).size.width/6,color: Colors.white,),
  1021. SizedBox(height: 5,),
  1022. Text('Submit Process',style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold,fontSize: 16),)
  1023. ],
  1024. ),
  1025. ),
  1026. ),
  1027. (prefs.getString(keyClass.targetProccess)!=null||(prefs.getBool(keyClass.submitProccess)!=null&&prefs.getBool(keyClass.submitProccess)))?InkWell(
  1028. splashColor: Colors.black,
  1029. onTap: ()async{
  1030. await Future.delayed(Duration(milliseconds: 200));
  1031. await clearData(context);
  1032. },
  1033. child: Container(
  1034. padding: EdgeInsets.all(5),
  1035. decoration: BoxDecoration(
  1036. boxShadow: [
  1037. BoxShadow(
  1038. color: Colors.grey.withOpacity(0.5),
  1039. spreadRadius: 2,
  1040. blurRadius: 2,
  1041. offset: Offset(0, 0), // changes position of shadow
  1042. ),
  1043. ],
  1044. borderRadius: BorderRadius.all(Radius.circular(5.0)),
  1045. color: Colors.red.withAlpha(200),
  1046. ),
  1047. child: Column(
  1048. mainAxisAlignment: MainAxisAlignment.center,
  1049. children: <Widget>[
  1050. Icon(Icons.restore_from_trash,size: MediaQuery.of(context).size.width/6,color: Colors.white,),
  1051. SizedBox(height: 5,),
  1052. Text('Clear Data',style: TextStyle(color: Colors.white,fontWeight: FontWeight.bold,fontSize: 16),)
  1053. ],
  1054. ),
  1055. ),
  1056. ):Container(),
  1057. ],
  1058. )),
  1059. ),
  1060. ],
  1061. ),
  1062. bottomSheet: Container(height: 22,alignment: Alignment.bottomRight,child: Opacity(opacity: 0.5,child: Padding(padding: EdgeInsets.all(5),child: Text((lastDownload!='')?'Master Data Downloaded':'No Master Data Found',style: TextStyle(fontSize: 12),)))),
  1063. ),
  1064. );
  1065. }
  1066. }