flutter app untuk unitstock
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 
 

951 satır
53 KiB

  1. import 'dart:io';
  2. import 'dart:typed_data';
  3. import 'package:flutter/services.dart';
  4. import 'Util/UnitModel.dart';
  5. import 'Util/photo_viewer.dart';
  6. import 'package:flutter/cupertino.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:image_picker/image_picker.dart';
  9. import 'Util/DBHelper.dart';
  10. import 'Util/Util.dart';
  11. import 'main.dart';
  12. import 'package:intl/intl.dart';
  13. //import 'package:autocomplete_textfield/autocomplete_textfield.dart';
  14. class UnitDetails extends StatefulWidget {
  15. Unit unit;
  16. UnitDetails({this.unit});
  17. @override
  18. _UnitDetailsState createState() => _UnitDetailsState();
  19. }
  20. class _UnitDetailsState extends State<UnitDetails> {
  21. final tipeController = TextEditingController();
  22. final rangkaController = TextEditingController();
  23. final colorController = TextEditingController();
  24. final kodeController = TextEditingController();
  25. final mesinController = TextEditingController();
  26. final tahunController = TextEditingController();
  27. final stateController = TextEditingController();
  28. // insertUnit _unitDetails;
  29. bool isChanged = false;
  30. Util util = new Util();
  31. List<Uint8List> images = [];
  32. List<int> blobIds = [];
  33. List<int> deleteBlobIds = [];
  34. List<jenisDrop> dropMenu = [];
  35. List<String> jenisImages = [];
  36. int jenisLength=0;
  37. Unit _currentUnit;
  38. List<blobImage> blobList = [];
  39. // List<Unit> allUnits = [];
  40. loadUnitDetails(context)async{
  41. // if(widget.idInsert!=null){
  42. //// var result = await DBHelper.database.getInsertUnit(widget.idInsert);
  43. //// if(result!=null){
  44. //// _unitDetails = result;
  45. //// mesinController.text = _unitDetails.mesin;
  46. //// tipeController.text= _unitDetails.tipe;
  47. //// rangkaController.text = _unitDetails.rangka;
  48. //// colorController.text = _unitDetails.warna;
  49. //// tahunController.text = _unitDetails.tahun;
  50. //// kodeController.text = _unitDetails.kode;
  51. //// stateController.text = _unitDetails.state;
  52. ////
  53. //// result = await DBHelper.database.getAllBlobImage(_unitDetails.id);
  54. //// if(result!=null){
  55. //// for(int i =0; i<result.length;i++){
  56. //// images.add(result[i].blob_file);
  57. //// blobIds.add(result[i].blob_id);
  58. //// jenisImages.add(result[i].jenis);
  59. //// }
  60. //// }
  61. //// setState(() {
  62. //// });
  63. //// }
  64. //// else{
  65. //// util.showFlushbar(context, 'Unit can\'t be found');
  66. //// }
  67. // await DBHelper.database.closeDb();
  68. // }
  69. // else{
  70. // var result = await DBHelper.database.getUnitdetailMaster(widget.idRef);
  71. // if (result!=null){
  72. _currentUnit = widget.unit;
  73. tipeController.text= _currentUnit.tipe;
  74. rangkaController.text = _currentUnit.rangka;
  75. colorController.text = _currentUnit.warna;
  76. kodeController.text = _currentUnit.kode;
  77. mesinController.text = _currentUnit.mesin;
  78. tahunController.text = _currentUnit.tahun;
  79. stateController.text = _currentUnit.state;
  80. // }
  81. // }
  82. await loadBlob();
  83. }
  84. // loadTipe() async{
  85. // allUnits.clear();
  86. // allUnits = await DBHelper.database.getAllUnits();
  87. // }
  88. loadBlob()async{
  89. var result = await DBHelper.database.getBlobUnits(mesinController.text);
  90. if(result!=null){
  91. setState(() {
  92. blobList = result;
  93. });
  94. // for(int i =0; i<result.length;i++){
  95. // images.add(result[i].blob_file);
  96. // blobIds.add(result[i].blob_id);
  97. // jenisImages.add(result[i].jenis);
  98. // }
  99. // dropMenu = result;
  100. // jenisLength = result.length;
  101. // if(jenisImages.length!=0){
  102. // for (int i =0;i<jenisImages.length;i++){
  103. // dropMenu.removeWhere((element) => element.value==jenisImages[i]);
  104. // }
  105. // }
  106. }
  107. }
  108. @override
  109. void initState() {
  110. // TODO: implement initState
  111. super.initState();
  112. WidgetsBinding.instance.addPostFrameCallback((_) async {
  113. util.showLoading(context);
  114. await Future.sync(()async{await loadUnitDetails(context);});
  115. Navigator.pop(context);
  116. });
  117. }
  118. @override
  119. Widget build(BuildContext context) {
  120. // if(allUnits.length!=0){
  121. // print(allUnits[0].tipe);
  122. //// loadTipe();
  123. // }
  124. return Scaffold(
  125. resizeToAvoidBottomPadding: true,
  126. appBar: AppBar(
  127. backgroundColor: Colors.transparent,
  128. elevation: 0.0,
  129. iconTheme: IconThemeData(
  130. color: Colors.indigo,
  131. ),
  132. title: Text((widget.unit.flag=='FALSE')?'Inserting New Unit':'Editing Unit',style: TextStyle(color: Colors.indigo),),
  133. ),
  134. body: WillPopScope(
  135. onWillPop: ()async{
  136. if(widget.unit.flag=='TRUE'){
  137. if(isChanged){
  138. await showDialog(context: context,builder: (context)=>
  139. Material(
  140. color: Colors.white.withOpacity(0.9),
  141. child: Center(
  142. child: Container(
  143. decoration: BoxDecoration(
  144. color: Colors.white,
  145. boxShadow: [
  146. BoxShadow(
  147. color: Colors.grey.withOpacity(0.5),
  148. spreadRadius: 2,
  149. blurRadius: 2,
  150. offset: Offset(0, 0), // changes position of shadow
  151. ),
  152. ],
  153. borderRadius: BorderRadius.circular(5)
  154. ),
  155. height: MediaQuery.of(context).size.height/4.8,
  156. width: MediaQuery.of(context).size.width*0.75,
  157. child: Column(
  158. children: <Widget>[
  159. Flexible(
  160. flex:3,
  161. child: Container(
  162. padding: EdgeInsets.only(top:10,left: 10,right: 10),
  163. alignment: Alignment.center,
  164. decoration: BoxDecoration(
  165. // color: Colors.indigo,
  166. borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5))
  167. ),
  168. child: Column(
  169. mainAxisSize: MainAxisSize.min,
  170. crossAxisAlignment: CrossAxisAlignment.center,
  171. children: <Widget>[
  172. Icon(Icons.warning,size: 70,color: Colors.indigo,),
  173. ],
  174. ),
  175. ),
  176. ),
  177. Flexible(
  178. flex: 1,
  179. child: Container(
  180. padding: EdgeInsets.only(left: 20,right: 20),
  181. alignment: Alignment.centerLeft,
  182. child: Text('Data belum disimpan. Lanjutkan ?',style: TextStyle(fontWeight: FontWeight.w500,fontSize: 14,color: Colors.black.withOpacity(0.6)),)
  183. ),
  184. ),
  185. Flexible(
  186. flex: 1,
  187. child: Container(
  188. padding: EdgeInsets.only(bottom:10),
  189. child: Row(
  190. mainAxisAlignment: MainAxisAlignment.end,
  191. children: <Widget>[
  192. FlatButton(
  193. child: Text('Proceed'),
  194. // color: Colors.red,
  195. onPressed: (){
  196. Navigator.pop(context);
  197. Navigator.pop(context);
  198. },
  199. ),
  200. FlatButton(
  201. child: Text('Cancel'),
  202. // color: Colors.grey,
  203. onPressed: (){
  204. Navigator.pop(context);
  205. },
  206. ),
  207. ],
  208. ),
  209. ),
  210. )
  211. ],
  212. ),
  213. ),
  214. ),
  215. ),
  216. );
  217. }
  218. else Navigator.pop(context);
  219. }
  220. else{
  221. bool not_empty = (stateController.text!='-'&&mesinController.text!='-'&&tahunController.text!='-'&&kodeController.text!='-'&&colorController.text!='-'&&rangkaController.text!='-'&&tipeController.text!='-');
  222. if(blobList.where((element) => element.blob_file!=null).length!=0){
  223. await showDialog(context: context,builder: (context)=>
  224. Material(
  225. color: Colors.white.withOpacity(0.9),
  226. child: Center(
  227. child: Container(
  228. decoration: BoxDecoration(
  229. color: Colors.white,
  230. boxShadow: [
  231. BoxShadow(
  232. color: Colors.grey.withOpacity(0.5),
  233. spreadRadius: 2,
  234. blurRadius: 2,
  235. offset: Offset(0, 0), // changes position of shadow
  236. ),
  237. ],
  238. borderRadius: BorderRadius.circular(5)
  239. ),
  240. height: MediaQuery.of(context).size.height/4.8,
  241. width: MediaQuery.of(context).size.width*0.75,
  242. child: Column(
  243. children: <Widget>[
  244. Flexible(
  245. flex:3,
  246. child: Container(
  247. padding: EdgeInsets.only(top:10,left: 10,right: 10),
  248. alignment: Alignment.center,
  249. decoration: BoxDecoration(
  250. // color: Colors.indigo,
  251. borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5))
  252. ),
  253. child: Column(
  254. mainAxisSize: MainAxisSize.min,
  255. crossAxisAlignment: CrossAxisAlignment.center,
  256. children: <Widget>[
  257. Icon(Icons.warning,size: 70,color: Colors.indigo,),
  258. ],
  259. ),
  260. ),
  261. ),
  262. Flexible(
  263. flex: 1,
  264. child: Container(
  265. padding: EdgeInsets.only(left: 20,right: 20),
  266. alignment: Alignment.centerLeft,
  267. child: Text('Data belum disimpan. Lanjutkan ?',style: TextStyle(fontWeight: FontWeight.w500,fontSize: 14,color: Colors.black.withOpacity(0.6)),)
  268. ),
  269. ),
  270. Flexible(
  271. flex: 1,
  272. child: Container(
  273. padding: EdgeInsets.only(bottom:10),
  274. child: Row(
  275. mainAxisAlignment: MainAxisAlignment.end,
  276. children: <Widget>[
  277. FlatButton(
  278. child: Text('Back',style: TextStyle(color: Colors.indigo),),
  279. onPressed: (){
  280. Navigator.pop(context);
  281. Navigator.pop(context);
  282. },
  283. ),
  284. FlatButton(
  285. child: Text('Cancel',style: TextStyle(color: Colors.indigo)),
  286. onPressed: (){
  287. Navigator.pop(context);
  288. },
  289. ),
  290. ],
  291. ),
  292. ),
  293. )
  294. ],
  295. ),
  296. ),
  297. ),
  298. ),
  299. );
  300. }
  301. else Navigator.pop(context);
  302. }
  303. return false;
  304. },
  305. child: Container(
  306. padding: EdgeInsets.only(left:10,right: 10,bottom: 10),
  307. child: Column(
  308. children: <Widget>[
  309. // SizedBox(height: MediaQuery.of(context).size.height/25,),
  310. Expanded(
  311. child: Row(
  312. children: <Widget>[
  313. Flexible(
  314. flex: 4,
  315. child: Container(
  316. height: MediaQuery.of(context).size.height,
  317. child:
  318. ListView.builder(
  319. // itemCount: ((images.length+1)>jenisLength)?jenisLength:images.length+1,
  320. itemCount: blobList.length,
  321. itemBuilder: (context, index){
  322. // Uint8List image = ((images.length==0)||(images.length<(index+1)))?null:images[index];
  323. Uint8List image = blobList[index].blob_file;
  324. return Padding(
  325. padding: const EdgeInsets.only(top: 10,right: 10),
  326. child: Material(
  327. child: InkWell(
  328. onTap: ()async{
  329. if(image==null){
  330. // var selected = await showDialog(
  331. // context: context,
  332. // builder: (context){
  333. // var selected = dropMenu[0].value;
  334. // return WillPopScope(
  335. // onWillPop: ()async{
  336. // Navigator.pop(context,false);
  337. // return false;
  338. // },
  339. // child: AlertDialog(
  340. // content: StatefulBuilder(
  341. // builder: (context,setState){
  342. // return DropdownButtonFormField(
  343. // decoration: InputDecoration.collapsed(),
  344. // value: selected,
  345. // onChanged: (value){
  346. // setState(() {
  347. // selected = value;
  348. // });
  349. // },
  350. // items: dropMenu.map((item) {
  351. // return new DropdownMenuItem<String>(
  352. // value: item.value,
  353. // child: Row(
  354. // children: <Widget>[
  355. // Text(item.value),
  356. //// (item.optional=='TRUE')?Container():Text(' *',style: TextStyle(color: Colors.red),)
  357. // ],
  358. // ),
  359. // );
  360. // }).toList(),
  361. // );
  362. // },
  363. // ),
  364. // actions: <Widget>[
  365. // FlatButton(
  366. // child: Text('Done'),
  367. // onPressed: ()async{
  368. // jenisImages.add(selected);
  369. //
  370. // Navigator.pop(context,true);
  371. // },
  372. // ),
  373. // FlatButton(
  374. // child: Text('Cancel'),
  375. // onPressed: (){
  376. // Navigator.pop(context,false);
  377. // },
  378. // ),
  379. // ],
  380. // ),
  381. // );
  382. // }
  383. // );
  384. // if (selected){
  385. File temp = await ImagePicker.pickImage(source: ImageSource.camera,maxWidth: 800,imageQuality: 80);
  386. if(temp!=null){
  387. isChanged = true;
  388. blobList[index].blob_file = temp.readAsBytesSync();
  389. temp.deleteSync();
  390. // if(widget.idInsert!=null) {
  391. // blobIds.add(null);
  392. // isChanged = true;
  393. // }
  394. setState(() {
  395. });
  396. }
  397. // else {
  398. // jenisImages.removeLast();
  399. // }
  400. // await loadDropMenu();
  401. // }
  402. }
  403. else {
  404. // List<jenisDrop> dropNewMenu = new List<jenisDrop>.from(dropMenu);
  405. // dropNewMenu.add(new jenisDrop(value: jenisImages[index]));
  406. var result = await Navigator.push(context, MaterialPageRoute(builder: (context) => PhotoViewer(image,id: widget.unit.id.toString()+'.$index',jenis: blobList[index].jenis,)));
  407. if(result!=null){
  408. blobList[index] = result['byte'];
  409. isChanged = true;
  410. // images[index] = result['byte'];
  411. // jenisImages[index] = result['jenis'];
  412. // await loadDropMenu();
  413. // if(widget.idInsert!=null) {
  414. // isChanged = true;
  415. // }
  416. setState(() {
  417. });
  418. }
  419. }
  420. },
  421. splashColor: Colors.grey,
  422. child: Column(
  423. children: <Widget>[
  424. Container(padding: EdgeInsets.all(5),child: Text(blobList[index].jenis)),
  425. Stack(
  426. children: <Widget>[
  427. Container(
  428. decoration: BoxDecoration(
  429. color: Colors.grey.withOpacity(0.7),
  430. image: (image!=null)?DecorationImage(
  431. image: MemoryImage(image),
  432. fit: BoxFit.cover
  433. ):null,
  434. ),
  435. height: MediaQuery.of(context).size.width*0.35,
  436. width: MediaQuery.of(context).size.width*0.35,
  437. child: (image==null)?Icon(Icons.add):null,
  438. ),
  439. (image!=null)?Container(
  440. height: MediaQuery.of(context).size.width*0.35,
  441. width: MediaQuery.of(context).size.width*0.35,
  442. alignment: Alignment.topRight,
  443. child: InkWell(
  444. onTap: ()async{
  445. // if(widget.idInsert!=null){
  446. // isChanged = true;
  447. // deleteBlobIds.add(blobIds[index]);
  448. // blobIds.removeAt(index);
  449. // }
  450. setState(() {
  451. blobList[index].blob_file = null;
  452. // images.removeAt(index);
  453. // jenisImages.removeAt(index);
  454. });
  455. // await loadDropMenu();
  456. },
  457. child: Container(
  458. padding: EdgeInsets.all(5),
  459. child: Icon(Icons.cancel,color: Colors.red,)),
  460. ),
  461. ):Container(),
  462. ],
  463. ),
  464. ],
  465. ),
  466. ),
  467. ),
  468. );
  469. })
  470. ),
  471. ),
  472. Flexible(
  473. flex: 6,
  474. child: Container(
  475. alignment: Alignment.topLeft,
  476. padding: EdgeInsets.only(top: 10),
  477. child: SingleChildScrollView(
  478. scrollDirection: Axis.vertical,
  479. child: Column(
  480. mainAxisAlignment: MainAxisAlignment.start,
  481. children: <Widget>[
  482. // Divider(),
  483. // Row(
  484. // mainAxisAlignment: MainAxisAlignment.spaceBetween,
  485. // children: <Widget>[
  486. // Expanded(
  487. // child:
  488. // textfield??Container(),
  489. // ),
  490. // ],
  491. // ),
  492. Padding(
  493. padding: const EdgeInsets.all(5.0),
  494. child: Text('Units Details',style: TextStyle(fontSize: 18,fontWeight: FontWeight.bold),),
  495. ),
  496. Divider(),
  497. Row(
  498. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  499. children: <Widget>[
  500. Text('Tipe : '),
  501. Expanded(
  502. child:
  503. TextFormField(
  504. enabled: false,
  505. style: TextStyle(color: Colors.grey),
  506. controller: tipeController,
  507. decoration: InputDecoration.collapsed(hintText: null),
  508. ),
  509. ),
  510. ],
  511. ),
  512. Divider(),
  513. Row(
  514. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  515. children: <Widget>[
  516. Text('Mesin : '),
  517. Expanded(
  518. child: TextFormField(
  519. enabled: false,
  520. style: TextStyle(color: Colors.grey),
  521. controller: mesinController,
  522. decoration: InputDecoration.collapsed(hintText: null),
  523. ),
  524. ),
  525. ],
  526. ),
  527. Divider(),
  528. Row(
  529. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  530. children: <Widget>[
  531. Text('Rangka : '),
  532. Expanded(
  533. child: TextFormField(
  534. enabled: false,
  535. style: TextStyle(color: Colors.grey),
  536. controller: rangkaController,
  537. decoration: InputDecoration.collapsed(hintText: null),
  538. ),
  539. ),
  540. ],
  541. ),
  542. Divider(),
  543. Row(
  544. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  545. children: <Widget>[
  546. Text('Kode : '),
  547. Expanded(
  548. child: TextFormField(
  549. enabled: false,
  550. style: TextStyle(color: Colors.grey),
  551. controller: kodeController,
  552. decoration: InputDecoration.collapsed(hintText: null),
  553. ),
  554. ),
  555. ],
  556. ),
  557. Divider(),
  558. Row(
  559. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  560. children: <Widget>[
  561. Text('Tahun : '),
  562. Expanded(
  563. child: TextFormField(
  564. enabled: false,
  565. style: TextStyle(color: Colors.grey),
  566. controller: tahunController,
  567. decoration: InputDecoration.collapsed(hintText: null),
  568. ),
  569. ),
  570. ],
  571. ),
  572. Divider(),
  573. Row(
  574. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  575. children: <Widget>[
  576. Text('Warna : '),
  577. Expanded(
  578. child: TextFormField(
  579. enabled: false,
  580. style: TextStyle(color: Colors.grey),
  581. controller: colorController,
  582. decoration: InputDecoration.collapsed(hintText: null),
  583. ),
  584. ),
  585. ],
  586. ),
  587. Divider(),
  588. Row(
  589. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  590. children: <Widget>[
  591. Text('State : '),
  592. Expanded(
  593. child: TextFormField(
  594. enabled: false,
  595. style: TextStyle(color: Colors.grey),
  596. controller: stateController,
  597. decoration: InputDecoration.collapsed(hintText: null),
  598. ),
  599. ),
  600. ],
  601. ),
  602. Divider(),
  603. Row(
  604. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  605. children: <Widget>[
  606. FlatButton(
  607. child: Text((widget.unit.flag=='FALSE')?'Add':'Save'),
  608. onPressed: ()async{
  609. bool succeed = false;
  610. String errMsg = '';
  611. util.showLoading(context);
  612. await Future.sync(()async{
  613. if(currentPosisiton!=null) {
  614. if(blobList.where((element) => element.blob_file!=null).length==blobList.length){
  615. for(int i = 0 ; i<blobList.length;i++){
  616. blobList[i].lat = currentPosisiton.latitude.toString();
  617. blobList[i].long = currentPosisiton.longitude.toString();
  618. var result = await DBHelper.database.updateBlob(blobList[i]);
  619. succeed = (result!=null);
  620. if(!succeed) {
  621. i = blobList.length;
  622. }
  623. }
  624. if(succeed){
  625. _currentUnit.timestamp = DateFormat('dd-MM-yyyy HH:mm:ss').format(DateTime.now());
  626. _currentUnit.flag = 'TRUE';
  627. var result = await DBHelper.database.updateUnit(_currentUnit);
  628. succeed = (result!=null);
  629. }
  630. }
  631. else{
  632. succeed = false;
  633. errMsg ='Please take all the pictures';
  634. }
  635. }
  636. else{
  637. succeed = false;
  638. errMsg ='Failed getting current location. Please check gps.';
  639. }
  640. });
  641. Navigator.pop(context);
  642. // if(!ModalRoute.of(context).isCurrent)Navigator.popUntil(context,ModalRoute.withName('/unitdetails') );
  643. if(!ModalRoute.of(context).isCurrent)Navigator.pop(context);
  644. if(succeed) Navigator.pop(context,succeed);
  645. util.showFlushbar(context, (succeed)?'Data updated':errMsg,color: (succeed)?Colors.grey:Colors.red);
  646. // bool valid = false;
  647. // String errMsg= '';
  648. // if(widget.idInsert==null){
  649. // bool not_empty = (stateController.text!='-'&&mesinController.text!='-'&&tahunController.text!='-'&&kodeController.text!='-'&&colorController.text!='-'&&rangkaController.text!='-'&&tipeController.text!='-');
  650. // if(not_empty&&images.length==jenisLength){
  651. // valid = true;
  652. // }
  653. // else{
  654. // if(!not_empty) errMsg='Please fill all the Unit details';
  655. // else errMsg='You must atleast take required pictures of unit';
  656. // }
  657. // }
  658. // else{
  659. // checkChanges();
  660. // valid = true;
  661. // }
  662. // if(valid){
  663. // bool succeed = false;
  664. // util.showLoading(context);
  665. // await Future.sync(()async{
  666. // if(currentPosisiton!=null){
  667. // if(widget.idInsert==null){
  668. // var result = await DBHelper.database.checkUnitbyMesin(mesinController.text.replaceAll('-', ''));
  669. // if(result==0){
  670. // insertUnit input = new insertUnit(
  671. // mesin: mesinController.text,
  672. // timestamp:DateFormat('dd-MM-yyyy HH:mm:ss').format(DateTime.now()),
  673. // );
  674. // var insertID = await DBHelper.database.newInsertUnit(input);
  675. // if(insertID!=null){
  676. // for(int i=0;i<images.length;i++){
  677. // blobImage newBlob = new blobImage(
  678. // blob_file: images[i],
  679. // mesin_id: insertID,
  680. // lat: currentPosisiton.latitude.toString(),
  681. // long: currentPosisiton.longitude.toString(),
  682. // jenis: jenisImages[i],
  683. // );
  684. // var result = await DBHelper.database.newInsertBlob(newBlob);
  685. // succeed = (result!=null);
  686. // if(!succeed) {
  687. // i = images.length;
  688. // }
  689. // }
  690. // }
  691. // await DBHelper.database.closeDb();
  692. // }
  693. // else{
  694. // errMsg = "Data mesin ${mesinController.text} sudah diinput";
  695. // }
  696. // }
  697. // else{
  698. // if(isChanged){
  699. // if(images.length==jenisLength){
  700. // _unitDetails.mesin = mesinController.text;
  701. // _unitDetails.timestamp = DateFormat('dd-MM-yyyy HH:mm:ss').format(DateTime.now());
  702. // var updateresult = await DBHelper.database.updateInsertUnit(_unitDetails);
  703. // if(updateresult!=null){
  704. // print(deleteBlobIds);
  705. // for(int j=0;j<deleteBlobIds.length;j++){
  706. // var result = await DBHelper.database.deleteBlob(deleteBlobIds[j]);
  707. // succeed = (result!=null);
  708. // if(!succeed) {
  709. // j = deleteBlobIds.length;
  710. // }
  711. // }
  712. // for(int i=0;i<images.length;i++){
  713. // blobImage newBlob = new blobImage(
  714. // blob_id: blobIds[i],
  715. // blob_file: images[i],
  716. // mesin_id: _unitDetails.id,
  717. // lat : currentPosisiton.latitude.toString(),
  718. // long : currentPosisiton.longitude.toString(),
  719. // jenis: jenisImages[i],
  720. // );
  721. // var result = await DBHelper.database.insertUpdateBlob(newBlob);
  722. // succeed = (result!=null);
  723. // if(!succeed) {
  724. // i = images.length;
  725. // }
  726. // }
  727. // }
  728. // await DBHelper.database.closeDb();
  729. // }
  730. // else errMsg = 'You must atleast take required pictures of unit';
  731. // }
  732. // else succeed =true;
  733. // }
  734. // }
  735. // else{
  736. // errMsg = 'Failed fetching location. Please make sure gps enabled';
  737. // }
  738. // });
  739. // Navigator.pop(context);
  740. //// print('aaaaaaaaaaaaaa ${ModalRoute.of(context).isCurrent}');
  741. // if(!ModalRoute.of(context).isCurrent)Navigator.popUntil(context, ModalRoute.withName('/unitdetails'));
  742. // if(succeed){
  743. // Navigator.pop(context,succeed);
  744. // print(currentPosisiton);
  745. // util.showFlushbar(context, 'Row ${widget.idInsert==null?'Inserted':'Updated'}');
  746. // }
  747. // else{
  748. // util.showFlushbar(context, 'Failed to ${widget.idInsert==null?'insert':'update'} row. ${errMsg??''}',color: Colors.red);
  749. // }
  750. // }
  751. // else{
  752. // util.showFlushbar(context,errMsg);
  753. // }
  754. },
  755. color: Colors.green,
  756. ),
  757. FlatButton(
  758. child: Text('Cancel'),
  759. onPressed: ()async {
  760. if(widget.unit.flag=='TRUE'){
  761. if(isChanged){
  762. await showDialog(context: context,builder: (context)=>
  763. Material(
  764. color: Colors.white.withOpacity(0.9),
  765. child: Center(
  766. child: Container(
  767. decoration: BoxDecoration(
  768. color: Colors.white,
  769. boxShadow: [
  770. BoxShadow(
  771. color: Colors.grey.withOpacity(0.5),
  772. spreadRadius: 2,
  773. blurRadius: 2,
  774. offset: Offset(0, 0), // changes position of shadow
  775. ),
  776. ],
  777. borderRadius: BorderRadius.circular(5)
  778. ),
  779. height: MediaQuery.of(context).size.height/4.8,
  780. width: MediaQuery.of(context).size.width*0.75,
  781. child: Column(
  782. children: <Widget>[
  783. Flexible(
  784. flex:3,
  785. child: Container(
  786. padding: EdgeInsets.only(top:10,left: 10,right: 10),
  787. alignment: Alignment.center,
  788. decoration: BoxDecoration(
  789. // color: Colors.indigo,
  790. borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5))
  791. ),
  792. child: Column(
  793. mainAxisSize: MainAxisSize.min,
  794. crossAxisAlignment: CrossAxisAlignment.center,
  795. children: <Widget>[
  796. Icon(Icons.warning,size: 70,color: Colors.indigo,),
  797. ],
  798. ),
  799. ),
  800. ),
  801. Flexible(
  802. flex: 1,
  803. child: Container(
  804. padding: EdgeInsets.only(left: 20,right: 20),
  805. alignment: Alignment.centerLeft,
  806. child: Text('Data belum disimpan. Lanjutkan ?',style: TextStyle(fontWeight: FontWeight.w500,fontSize: 14,color: Colors.black.withOpacity(0.6)),)
  807. ),
  808. ),
  809. Flexible(
  810. flex: 1,
  811. child: Container(
  812. padding: EdgeInsets.only(bottom:10),
  813. child: Row(
  814. mainAxisAlignment: MainAxisAlignment.end,
  815. children: <Widget>[
  816. FlatButton(
  817. child: Text('Proceed'),
  818. onPressed: (){
  819. Navigator.pop(context);
  820. Navigator.popUntil(context,ModalRoute.withName('/stocking'));
  821. },
  822. ),
  823. FlatButton(
  824. child: Text('Cancel'),
  825. // color: Colors.grey,
  826. onPressed: (){
  827. Navigator.pop(context);
  828. },
  829. ),
  830. ],
  831. ),
  832. ),
  833. )
  834. ],
  835. ),
  836. ),
  837. ),
  838. ),
  839. );
  840. }
  841. else Navigator.pop(context);
  842. }
  843. else {
  844. // bool not_empty = (stateController.text!='-'&&mesinController.text!='-'&&tahunController.text!='-'&&kodeController.text!='-'&&colorController.text!='-'&&rangkaController.text!='-'&&tipeController.text!='-');
  845. if(blobList.where((element) => element.blob_file!=null).length!=0){
  846. await showDialog(context: context,builder: (context)=>
  847. Material(
  848. color: Colors.white.withOpacity(0.9),
  849. child: Center(
  850. child: Container(
  851. decoration: BoxDecoration(
  852. color: Colors.white,
  853. boxShadow: [
  854. BoxShadow(
  855. color: Colors.grey.withOpacity(0.5),
  856. spreadRadius: 2,
  857. blurRadius: 2,
  858. offset: Offset(0, 0), // changes position of shadow
  859. ),
  860. ],
  861. borderRadius: BorderRadius.circular(5)
  862. ),
  863. height: MediaQuery.of(context).size.height/4.8,
  864. width: MediaQuery.of(context).size.width*0.75,
  865. child: Column(
  866. children: <Widget>[
  867. Flexible(
  868. flex:3,
  869. child: Container(
  870. padding: EdgeInsets.only(top:10,left: 10,right: 10),
  871. alignment: Alignment.center,
  872. decoration: BoxDecoration(
  873. // color: Colors.indigo,
  874. borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5))
  875. ),
  876. child: Column(
  877. mainAxisSize: MainAxisSize.min,
  878. crossAxisAlignment: CrossAxisAlignment.center,
  879. children: <Widget>[
  880. Icon(Icons.warning,size: 70,color: Colors.indigo,),
  881. ],
  882. ),
  883. ),
  884. ),
  885. Flexible(
  886. flex: 1,
  887. child: Container(
  888. padding: EdgeInsets.only(left: 20,right: 20),
  889. alignment: Alignment.centerLeft,
  890. child: Text('Data belum disimpan. Lanjutkan ?',style: TextStyle(fontWeight: FontWeight.w500,fontSize: 14,color: Colors.black.withOpacity(0.6)),)
  891. ),
  892. ),
  893. Flexible(
  894. flex: 1,
  895. child: Container(
  896. padding: EdgeInsets.only(bottom:10),
  897. child: Row(
  898. mainAxisAlignment: MainAxisAlignment.end,
  899. children: <Widget>[
  900. FlatButton(
  901. child: Text('Back'),
  902. onPressed: (){
  903. Navigator.pop(context);
  904. Navigator.popUntil(context,ModalRoute.withName('/stocking'));
  905. },
  906. ),
  907. FlatButton(
  908. child: Text('Cancel'),
  909. onPressed: (){
  910. Navigator.pop(context);
  911. },
  912. ),
  913. ],
  914. ),
  915. ),
  916. )
  917. ],
  918. ),
  919. ),
  920. ),
  921. ),
  922. );
  923. }
  924. else Navigator.pop(context);
  925. }
  926. },
  927. color: Colors.redAccent,
  928. )
  929. ],
  930. )
  931. ],
  932. ),
  933. ),
  934. ),
  935. )
  936. ],
  937. ),
  938. ),
  939. ],
  940. ),
  941. ),
  942. ),
  943. );
  944. }
  945. }