|
@@ -609,6 +609,7 @@ class _UnitDetailsState extends State<UnitDetails> { |
|
|
succeed = (result!=null); |
|
|
succeed = (result!=null); |
|
|
if(!succeed) { |
|
|
if(!succeed) { |
|
|
i = blobList.length; |
|
|
i = blobList.length; |
|
|
|
|
|
errMsg = "Gagal menyimpan foto unit!"; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
if(succeed){ |
|
|
if(succeed){ |
|
@@ -616,132 +617,25 @@ class _UnitDetailsState extends State<UnitDetails> { |
|
|
_currentUnit.flag = 'TRUE'; |
|
|
_currentUnit.flag = 'TRUE'; |
|
|
var result = await DBHelper.database.updateUnit(_currentUnit); |
|
|
var result = await DBHelper.database.updateUnit(_currentUnit); |
|
|
succeed = (result!=null); |
|
|
succeed = (result!=null); |
|
|
|
|
|
if(!succeed) { |
|
|
|
|
|
errMsg = "Gagal menyimpan data unit!"; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else{ |
|
|
else{ |
|
|
succeed = false; |
|
|
succeed = false; |
|
|
errMsg ='Please take all the pictures'; |
|
|
|
|
|
|
|
|
errMsg ='Tolong lengkapi data foto'; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else{ |
|
|
else{ |
|
|
succeed = false; |
|
|
succeed = false; |
|
|
errMsg ='Failed getting current location. Please check gps.'; |
|
|
|
|
|
|
|
|
errMsg ='Gagal mengamil koordinat lokasi. Tolong cek gps.'; |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
Navigator.pop(context); |
|
|
Navigator.pop(context); |
|
|
// if(!ModalRoute.of(context).isCurrent)Navigator.popUntil(context,ModalRoute.withName('/unitdetails') ); |
|
|
|
|
|
if(!ModalRoute.of(context).isCurrent)Navigator.pop(context); |
|
|
if(!ModalRoute.of(context).isCurrent)Navigator.pop(context); |
|
|
if(succeed) Navigator.pop(context,succeed); |
|
|
if(succeed) Navigator.pop(context,succeed); |
|
|
util.showFlushbar(context, (succeed)?'Data updated':errMsg,color: (succeed)?Colors.grey:Colors.red); |
|
|
|
|
|
|
|
|
|
|
|
// bool valid = false; |
|
|
|
|
|
// String errMsg= ''; |
|
|
|
|
|
// if(widget.idInsert==null){ |
|
|
|
|
|
// bool not_empty = (stateController.text!='-'&&mesinController.text!='-'&&tahunController.text!='-'&&kodeController.text!='-'&&colorController.text!='-'&&rangkaController.text!='-'&&tipeController.text!='-'); |
|
|
|
|
|
// if(not_empty&&images.length==jenisLength){ |
|
|
|
|
|
// valid = true; |
|
|
|
|
|
// } |
|
|
|
|
|
// else{ |
|
|
|
|
|
// if(!not_empty) errMsg='Please fill all the Unit details'; |
|
|
|
|
|
// else errMsg='You must atleast take required pictures of unit'; |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// else{ |
|
|
|
|
|
// checkChanges(); |
|
|
|
|
|
// valid = true; |
|
|
|
|
|
// } |
|
|
|
|
|
// if(valid){ |
|
|
|
|
|
// bool succeed = false; |
|
|
|
|
|
// util.showLoading(context); |
|
|
|
|
|
// await Future.sync(()async{ |
|
|
|
|
|
// if(currentPosisiton!=null){ |
|
|
|
|
|
// if(widget.idInsert==null){ |
|
|
|
|
|
// var result = await DBHelper.database.checkUnitbyMesin(mesinController.text.replaceAll('-', '')); |
|
|
|
|
|
// if(result==0){ |
|
|
|
|
|
// insertUnit input = new insertUnit( |
|
|
|
|
|
// mesin: mesinController.text, |
|
|
|
|
|
// timestamp:DateFormat('dd-MM-yyyy HH:mm:ss').format(DateTime.now()), |
|
|
|
|
|
// ); |
|
|
|
|
|
// var insertID = await DBHelper.database.newInsertUnit(input); |
|
|
|
|
|
// if(insertID!=null){ |
|
|
|
|
|
// for(int i=0;i<images.length;i++){ |
|
|
|
|
|
// blobImage newBlob = new blobImage( |
|
|
|
|
|
// blob_file: images[i], |
|
|
|
|
|
// mesin_id: insertID, |
|
|
|
|
|
// lat: currentPosisiton.latitude.toString(), |
|
|
|
|
|
// long: currentPosisiton.longitude.toString(), |
|
|
|
|
|
// jenis: jenisImages[i], |
|
|
|
|
|
// ); |
|
|
|
|
|
// var result = await DBHelper.database.newInsertBlob(newBlob); |
|
|
|
|
|
// succeed = (result!=null); |
|
|
|
|
|
// if(!succeed) { |
|
|
|
|
|
// i = images.length; |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// await DBHelper.database.closeDb(); |
|
|
|
|
|
// } |
|
|
|
|
|
// else{ |
|
|
|
|
|
// errMsg = "Data mesin ${mesinController.text} sudah diinput"; |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// else{ |
|
|
|
|
|
// if(isChanged){ |
|
|
|
|
|
// if(images.length==jenisLength){ |
|
|
|
|
|
// _unitDetails.mesin = mesinController.text; |
|
|
|
|
|
// _unitDetails.timestamp = DateFormat('dd-MM-yyyy HH:mm:ss').format(DateTime.now()); |
|
|
|
|
|
// var updateresult = await DBHelper.database.updateInsertUnit(_unitDetails); |
|
|
|
|
|
// if(updateresult!=null){ |
|
|
|
|
|
// print(deleteBlobIds); |
|
|
|
|
|
// for(int j=0;j<deleteBlobIds.length;j++){ |
|
|
|
|
|
// var result = await DBHelper.database.deleteBlob(deleteBlobIds[j]); |
|
|
|
|
|
// succeed = (result!=null); |
|
|
|
|
|
// if(!succeed) { |
|
|
|
|
|
// j = deleteBlobIds.length; |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// for(int i=0;i<images.length;i++){ |
|
|
|
|
|
// blobImage newBlob = new blobImage( |
|
|
|
|
|
// blob_id: blobIds[i], |
|
|
|
|
|
// blob_file: images[i], |
|
|
|
|
|
// mesin_id: _unitDetails.id, |
|
|
|
|
|
// lat : currentPosisiton.latitude.toString(), |
|
|
|
|
|
// long : currentPosisiton.longitude.toString(), |
|
|
|
|
|
// jenis: jenisImages[i], |
|
|
|
|
|
// ); |
|
|
|
|
|
// var result = await DBHelper.database.insertUpdateBlob(newBlob); |
|
|
|
|
|
// succeed = (result!=null); |
|
|
|
|
|
// if(!succeed) { |
|
|
|
|
|
// i = images.length; |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// await DBHelper.database.closeDb(); |
|
|
|
|
|
// } |
|
|
|
|
|
// else errMsg = 'You must atleast take required pictures of unit'; |
|
|
|
|
|
// } |
|
|
|
|
|
// else succeed =true; |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// else{ |
|
|
|
|
|
// errMsg = 'Failed fetching location. Please make sure gps enabled'; |
|
|
|
|
|
// } |
|
|
|
|
|
// }); |
|
|
|
|
|
// Navigator.pop(context); |
|
|
|
|
|
//// print('aaaaaaaaaaaaaa ${ModalRoute.of(context).isCurrent}'); |
|
|
|
|
|
// if(!ModalRoute.of(context).isCurrent)Navigator.popUntil(context, ModalRoute.withName('/unitdetails')); |
|
|
|
|
|
// if(succeed){ |
|
|
|
|
|
// Navigator.pop(context,succeed); |
|
|
|
|
|
// print(currentPosisiton); |
|
|
|
|
|
// util.showFlushbar(context, 'Row ${widget.idInsert==null?'Inserted':'Updated'}'); |
|
|
|
|
|
// } |
|
|
|
|
|
// else{ |
|
|
|
|
|
// util.showFlushbar(context, 'Failed to ${widget.idInsert==null?'insert':'update'} row. ${errMsg??''}',color: Colors.red); |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// else{ |
|
|
|
|
|
// util.showFlushbar(context,errMsg); |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
util.showFlushbar(context, (succeed)?'Data terupdate':errMsg,color: (succeed)?Colors.grey:Colors.red); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
), |
|
|
), |
|
|