flutter app untuk unitstock
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

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