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ů.
 
 
 
 
 

956 řádky
54 KiB

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