@@ -11,7 +11,7 @@ | |||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" | |||
android:maxSdkVersion="28" /> | |||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> | |||
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/> | |||
<!-- <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>--> | |||
<application | |||
android:name="${applicationName}" | |||
@@ -25,19 +25,22 @@ class DBHelper { | |||
if(stock_id != ''){ | |||
await util.permissionCheck(context,pHandler.Permission.storage,()async{ | |||
try{ | |||
// if(dbPath == null || dbPath == ''){ | |||
final database = await db; | |||
var dbPath = database.path; | |||
await DBHelper.database.closeDb(); | |||
// } | |||
await prefs.remove(keyClass.backup_stock_id); | |||
if(stock_id !='' && stock_id != null ) await prefs.setString(keyClass.backup_stock_id,stock_id); | |||
//backupDatabase | |||
String backupPath = join(dbPath.substring(0,dbPath.indexOf("/Android"))+"/Download", "${prefs.getString(keyClass.backup_stock_id)}_UnitStocking.db"); | |||
io.Directory documentsDirectory = await getApplicationDocumentsDirectory(); | |||
String backupPath = join(documentsDirectory.path, "${prefs.getString(keyClass.backup_stock_id)}_UnitStocking.db"); | |||
// dak jadi pakek external storage karena full access dak dibolehke playstore | |||
// String backupPath = join(dbPath.substring(0,dbPath.indexOf("/Android"))+"/Download", "${prefs.getString(keyClass.backup_stock_id)}_UnitStocking.db"); | |||
io.File backupFile = new io.File(backupPath); | |||
io.File dbFile = io.File(dbPath); | |||
if(dbFile.existsSync()){ | |||
// dbFile.copySync(backupPath); | |||
Uint8List byte = dbFile.readAsBytesSync(); | |||
backupFile.writeAsBytesSync(byte); | |||
result = {"STATUS":1,"MSG":"Backup Berhasil!"}; | |||
@@ -60,7 +63,7 @@ class DBHelper { | |||
return result; | |||
} | |||
initDb() async { | |||
io.Directory documentsDirectory = await getExternalStorageDirectory(); | |||
io.Directory documentsDirectory = await getApplicationDocumentsDirectory(); | |||
String path = join(documentsDirectory.path, "UnitStocking.db"); | |||
var theDb = await openDatabase(path, version: 1,onCreate: _onCreate); | |||
return theDb; | |||
@@ -70,8 +73,13 @@ class DBHelper { | |||
var result = {"STATUS":0,"MSG":"File Backup tidak ditemukan!"}; | |||
if(prefs.getString(keyClass.backup_stock_id)!=null){ | |||
await util.permissionCheck(context,pHandler.Permission.storage,()async{ | |||
io.Directory documentsDirectory = await getExternalStorageDirectory(); | |||
String backupPath = join(documentsDirectory.path.substring(0,documentsDirectory.path.indexOf("/Android"))+"/Download", "${prefs.getString(keyClass.backup_stock_id)}_UnitStocking.db"); | |||
io.Directory documentsDirectory = await getApplicationDocumentsDirectory(); | |||
String backupPath = join(documentsDirectory.path, "${prefs.getString(keyClass.backup_stock_id)}_UnitStocking.db"); | |||
// dak jadi karena ribet ngurusnyo | |||
// String backupPath = join(documentsDirectory.path.substring(0,documentsDirectory.path.indexOf("/Android"))+"/Download", "${prefs.getString(keyClass.backup_stock_id)}_UnitStocking.db"); | |||
io.File backupdbFile = io.File(backupPath); | |||
if(backupdbFile.existsSync()){ | |||
io.File dbFile = new io.File(join(documentsDirectory.path, "UnitStocking.db")); | |||
@@ -98,7 +106,7 @@ class DBHelper { | |||
} | |||
_onCreate(Database db, int version) async { | |||
io.Directory documentsDirectory = await getExternalStorageDirectory(); | |||
io.Directory documentsDirectory = await getApplicationDocumentsDirectory(); | |||
String path = join(documentsDirectory.path, "UnitStocking.db"); | |||
io.File file = io.File(path); | |||
print('Database created, ${file.lengthSync()}'); | |||
@@ -39,7 +39,6 @@ class file_Trans_Handler { | |||
else _error = e.message??e; | |||
// print("mainthrow $_error"); | |||
} | |||
Request req = new Request('GET', Uri.parse(link)); | |||
// req.headers = ''; | |||
_response = await httpClient.send(req).timeout( | |||
@@ -61,6 +60,7 @@ class file_Trans_Handler { | |||
// this.cancel(); | |||
// cancel(); //stop stream | |||
String resString = utf8.decode(value); | |||
print(resString); | |||
// if(util.htmlErrorTitle(resString)!=""){ | |||
// _error = util.htmlErrorTitle(resString); | |||
// } | |||
@@ -73,7 +73,7 @@ class file_Trans_Handler { | |||
_progress.add(0.0); | |||
print('Finish Download'); | |||
final file = File( | |||
"${(await getExternalStorageDirectory()).path}/$fileName"); | |||
"${(await getApplicationDocumentsDirectory()).path}/$fileName"); | |||
await file.writeAsBytes(_bytes); | |||
_path = file.path; | |||
} | |||
@@ -114,7 +114,7 @@ class file_Trans_Handler { | |||
httpClient = await util.getOauth2Client(); | |||
oauth2.Credentials tokenRestData = oauth2.Credentials.fromJson(prefs.getString(keyClass.rest_data)); | |||
final file = File( | |||
"${(await getExternalStorageDirectory()).path}/$fileName"); | |||
"${(await getApplicationDocumentsDirectory()).path}/$fileName"); | |||
String mimeType = 'application/vnd.sqlite3'; | |||
if(file.existsSync()){ | |||
Uint8List byte = file.readAsBytesSync(); | |||
@@ -227,11 +227,11 @@ class file_Trans_Handler { | |||
request.files.add( | |||
await MultipartFile.fromPath( | |||
'picture', | |||
"${(await getExternalStorageDirectory()).path}/$fileName" | |||
"${(await getApplicationDocumentsDirectory()).path}/$fileName" | |||
) | |||
); | |||
_response = await httpClient.send(request); | |||
_total = File("${(await getExternalStorageDirectory()).path}/$fileName").lengthSync(); | |||
_total = File("${(await getApplicationDocumentsDirectory()).path}/$fileName").lengthSync(); | |||
dlulStream = _response.stream.listen((value) { | |||
_bytes.addAll(value); | |||
print('upload ${_bytes.length/_total}'); | |||
@@ -241,7 +241,7 @@ class file_Trans_Handler { | |||
_progress.add(0.0); | |||
print('Finish Download'); | |||
final file = File( | |||
"${(await getExternalStorageDirectory()).path}/$fileName"); | |||
"${(await getApplicationDocumentsDirectory()).path}/$fileName"); | |||
await file.writeAsBytes(_bytes); | |||
_path = file.path; | |||
}) | |||
@@ -59,7 +59,7 @@ class _HomePageState extends State<HomePage> { | |||
util.showLoading(context); | |||
await Future.sync(()async{ | |||
try{ | |||
Directory documentsDirectory = await getExternalStorageDirectory(); | |||
Directory documentsDirectory = await getApplicationDocumentsDirectory(); | |||
String path = join(documentsDirectory.path, "UnitStocking.db"); | |||
File db = File(path); | |||
if(db.existsSync()){ | |||
@@ -105,7 +105,7 @@ class _HomePageState extends State<HomePage> { | |||
if(value != null)await prefs.setString(keyClass.stock_id, value.value); | |||
} | |||
String stock_taking_id = prefs.getString(keyClass.stock_id); | |||
if(prefs.getString(keyClass.backup_stock_id) == null) prefs.setString(keyClass.backup_stock_id,stock_taking_id); | |||
if(prefs.getString(keyClass.backup_stock_id) == null && stock_taking_id!= null) prefs.setString(keyClass.backup_stock_id,stock_taking_id); | |||
if(company!=null&&stock_taking_id!=null){ | |||
var result = await util.JsonDataPostRaw({"company":company,"stockTakingId":stock_taking_id}, '${prefs.getString(keyClass.hostAddress)}/stock_taking/state/'); | |||
if(result['STATUS']==1){ | |||
@@ -125,12 +125,15 @@ class _HomePageState extends State<HomePage> { | |||
lastUpload = prefs.getString(keyClass.lastUpload)??''; | |||
WidgetsBinding.instance.addPostFrameCallback((_) async { | |||
await _check_Update(); | |||
final androidVersion = await DeviceInfoPlugin().androidInfo; | |||
if ((androidVersion.version.sdkInt ?? 0) >= 30) { | |||
await util.permissionCheck(this.context,pHandler.Permission.manageExternalStorage,()async{print("storage permit granted!");},customMessage: " untuk menyimpan data backup"); | |||
} else { | |||
// dak jadi pakek external karena butuh Full acces File yang ribet ngorosnyo di appstore dan playstore | |||
// final androidVersion = await DeviceInfoPlugin().androidInfo; | |||
// if ((androidVersion.version.sdkInt ?? 0) >= 30) { | |||
// print(1); | |||
// await util.permissionCheck(this.context,pHandler.Permission.manageExternalStorage,()async{print("storage permit granted!");},customMessage: " untuk menyimpan data backup ke external storage!!"); | |||
// } else { | |||
// print(3); | |||
await util.permissionCheck(this.context,pHandler.Permission.storage,()async{print("storage permit granted!");},customMessage: " untuk menyimpan data backup"); | |||
} | |||
// } | |||
}); | |||
} | |||
@@ -263,7 +266,7 @@ class _HomePageState extends State<HomePage> { | |||
items: result['DATA'].map<DropdownMenuItem<dynamic>>((item){ | |||
return DropdownMenuItem( | |||
value: item['RETURN_VALUE'], | |||
child: Text(item["DISPLAY_VALUE"]), | |||
child: Container(width: MediaQuery.of(context).size.width*0.55,child: Text(item["DISPLAY_VALUE"])), | |||
); | |||
}).toList(), | |||
), | |||
@@ -291,7 +294,7 @@ class _HomePageState extends State<HomePage> { | |||
lastDownload = ''; | |||
timeString = ''; | |||
try{ | |||
Directory documentsDirectory = await getExternalStorageDirectory(); | |||
Directory documentsDirectory = await getApplicationDocumentsDirectory(); | |||
String path = join(documentsDirectory.path, "UnitStocking.db"); | |||
File db = File(path); | |||
if(db.existsSync()){ | |||
@@ -319,73 +322,6 @@ class _HomePageState extends State<HomePage> { | |||
), | |||
), | |||
), | |||
// AlertDialog( | |||
// title: Text('Set Cabang'), | |||
// content: DropdownButtonFormField( | |||
// value: selected, | |||
// onChanged: (value){ | |||
// setState(() { | |||
// selected = value; | |||
// }); | |||
// }, | |||
// items: result['DATA'].map<DropdownMenuItem<dynamic>>((item){ | |||
// return DropdownMenuItem( | |||
// value: item['RETURN_VALUE'], | |||
// child: Text(item["DISPLAY_VALUE"]), | |||
// ); | |||
// }).toList(), | |||
// ), | |||
// actions: <Widget>[ | |||
// TextButton( | |||
// child: Text('OK'), | |||
// onPressed: ()async{ | |||
// if(selected!=prefs.getString(keyClass.cabang_id)){ | |||
// prefs.setString(keyClass.cabang_id,selected); | |||
// await Future.sync(()async{ | |||
// await prefs.remove(keyClass.lastDownload); | |||
// await prefs.remove(keyClass.lastUpload); | |||
// await prefs.remove(keyClass.targetProccess); | |||
// await prefs.remove(keyClass.submitProccess); | |||
// lastUpload = ''; | |||
// lastDownload = ''; | |||
// timeString = ''; | |||
//// var result = await DBHelper.database.deleteAll(); | |||
//// if(result!=null) { | |||
//// await DBHelper.database.closeDb(); | |||
//// if(result!=null){ | |||
// try{ | |||
// Directory documentsDirectory = await getExternalStorageDirectory(); | |||
// String path = join(documentsDirectory.path, "UnitStocking.db"); | |||
// File db = File(path); | |||
// if(db.existsSync()){ | |||
// db.deleteSync(); | |||
// } | |||
// } | |||
// catch(e){ | |||
// print(e); | |||
// util.showFlushbar(context, 'Failed to delete database file',color: Colors.red); | |||
// } | |||
//// } | |||
//// else{ | |||
//// errMsg = 'Failed to clear unit data'; | |||
//// } | |||
//// } | |||
//// else{ | |||
//// errMsg = 'Failed to clear unit data'; | |||
//// } | |||
// }); | |||
// Navigator.pop(context,true); | |||
// } | |||
// else{ | |||
// Navigator.pop(context,false); | |||
// } | |||
//// util.showLoading(context); | |||
// | |||
//// Navigator.pop(context); | |||
// }, | |||
// ) | |||
// ], | |||
// ), | |||
)); | |||
} | |||
else{ | |||
@@ -741,7 +677,7 @@ class _HomePageState extends State<HomePage> { | |||
if(isRestore??false){ | |||
var response; | |||
bool isclear; | |||
Directory documentsDirectory = await getExternalStorageDirectory(); | |||
Directory documentsDirectory = await getApplicationDocumentsDirectory(); | |||
String path = join(documentsDirectory.path, "UnitStocking.db"); | |||
File db = File(path); | |||
if(db.existsSync()){ | |||
@@ -859,7 +795,7 @@ class _HomePageState extends State<HomePage> { | |||
a.start(); | |||
await Future.delayed(Duration(milliseconds: 200)); | |||
bool isclear; | |||
Directory documentsDirectory = await getExternalStorageDirectory(); | |||
Directory documentsDirectory = await getApplicationDocumentsDirectory(); | |||
String path = join(documentsDirectory.path, "UnitStocking.db"); | |||
File db = File(path); | |||
if(db.existsSync()){ | |||
@@ -101,6 +101,7 @@ class _LoginPageState extends State<LoginPage> { | |||
return false; | |||
}, | |||
child: Container( | |||
padding: EdgeInsets.only(bottom: MediaQuery.of(context).size.width*0.1), | |||
decoration: BoxDecoration( | |||
color: Colors.white | |||
), | |||
@@ -200,19 +201,8 @@ class _LoginPageState extends State<LoginPage> { | |||
), | |||
), | |||
), | |||
SizedBox(height: 30,), | |||
TextButton( | |||
onPressed: Login, | |||
style: TextButton.styleFrom( | |||
backgroundColor: Colors.indigo, | |||
padding: EdgeInsets.all(15), | |||
shape: RoundedRectangleBorder( | |||
borderRadius: BorderRadius.circular(100.0), | |||
side: BorderSide(color: Colors.indigo) | |||
), | |||
), | |||
child: Container(width: MediaQuery.of(context).size.width*0.7,child: Text('Login',textAlign: TextAlign.center,style: TextStyle(color: Colors.white,fontSize: 21),)), | |||
) | |||
// SizedBox(height: 30,), | |||
], | |||
), | |||
), | |||
@@ -291,7 +281,7 @@ class _LoginPageState extends State<LoginPage> { | |||
}, | |||
items: cabangDrop.map<DropdownMenuItem<dynamic>>((item)=>DropdownMenuItem( | |||
value: item['RETURN_VALUE'], | |||
child: Text(item["DISPLAY_VALUE"]), | |||
child: Container(width: MediaQuery.of(context).size.width*0.55,child: Text(item["DISPLAY_VALUE"])), | |||
)).toList(), | |||
), | |||
), | |||
@@ -338,121 +328,22 @@ class _LoginPageState extends State<LoginPage> { | |||
), | |||
), | |||
), | |||
bottomSheet: | |||
Padding( | |||
padding: EdgeInsets.only(bottom: MediaQuery.of(context).size.width*0.06,left: MediaQuery.of(context).size.width*0.1,right: MediaQuery.of(context).size.width*0.1), | |||
child: TextButton( | |||
onPressed: Login, | |||
style: TextButton.styleFrom( | |||
backgroundColor: Colors.indigo, | |||
padding: EdgeInsets.all(15), | |||
shape: RoundedRectangleBorder( | |||
borderRadius: BorderRadius.circular(100.0), | |||
side: BorderSide(color: Colors.indigo) | |||
), | |||
), | |||
child: Container(width: MediaQuery.of(context).size.width,child: Text('Login',textAlign: TextAlign.center,style: TextStyle(color: Colors.white,fontSize: 21),)), | |||
), | |||
), | |||
); | |||
// } | |||
// else{ | |||
// return WillPopScope( | |||
// onWillPop: ()async{ | |||
// setState(() { | |||
// prefs.setBool(keyClass.logged_in, false); | |||
// prefs.remove(keyClass.cabang_id); | |||
// prefs.remove(keyClass.company); | |||
// prefs.remove(keyClass.loginId); | |||
// }); | |||
// return false; | |||
// }, | |||
// child: Material( | |||
// child: Container( | |||
// color: Colors.grey.withOpacity(0.7), | |||
// child: Center( | |||
// child: Container( | |||
// decoration: BoxDecoration( | |||
// color: Colors.white, | |||
// borderRadius: BorderRadius.circular(5) | |||
// ), | |||
// height: MediaQuery.of(context).size.height/3.2, | |||
// width: MediaQuery.of(context).size.width*0.75, | |||
// child: Column( | |||
// children: <Widget>[ | |||
// Flexible( | |||
// flex:3, | |||
// child: Container( | |||
// padding: EdgeInsets.only(top:10,left: 10,right: 10), | |||
// alignment: Alignment.center, | |||
// decoration: BoxDecoration( | |||
//// color: Colors.indigo, | |||
// borderRadius: BorderRadius.only(topLeft: Radius.circular(5),topRight: Radius.circular(5)) | |||
// ), | |||
// child: Column( | |||
// mainAxisSize: MainAxisSize.min, | |||
// crossAxisAlignment: CrossAxisAlignment.center, | |||
// children: <Widget>[ | |||
// Icon(Icons.business,size: 70,color: Colors.indigo,), | |||
// SizedBox(height: 5,), | |||
// Text('Pilih Cabang',style: TextStyle(fontWeight: FontWeight.bold,fontSize: 16,color: Colors.indigo),) | |||
// ], | |||
// ), | |||
// ), | |||
// ), | |||
// Flexible( | |||
// flex: 1, | |||
// child: Container( | |||
// padding: EdgeInsets.only(left: 20,right: 20), | |||
// alignment: Alignment.centerLeft, | |||
// child: Theme( | |||
// data: ThemeData( | |||
// canvasColor: Colors.white, | |||
// primaryColor: Colors.indigo, | |||
// accentColor: Colors.indigo, | |||
// hintColor: Colors.indigo | |||
// ), | |||
// child: DropdownButtonFormField( | |||
// style: TextStyle(color: Colors.black.withOpacity(0.6),fontWeight: FontWeight.w500,fontSize: 14,), | |||
// decoration: InputDecoration( | |||
// contentPadding: EdgeInsets.all(8.0), | |||
// ), | |||
// value: selected, | |||
// onChanged: (value){ | |||
// setState(() { | |||
// selected = value; | |||
// }); | |||
// }, | |||
// items: cabangDrop.map<DropdownMenuItem<dynamic>>((item)=>DropdownMenuItem( | |||
// value: item['RETURN_VALUE'], | |||
// child: Text(item["DISPLAY_VALUE"]), | |||
// )).toList(), | |||
// ), | |||
// ), | |||
// ), | |||
// ), | |||
// Flexible( | |||
// flex: 1, | |||
// child: Container( | |||
// child: Row( | |||
// mainAxisAlignment: MainAxisAlignment.end, | |||
// children: <Widget>[ | |||
// ButtonTheme( | |||
// minWidth: 10, | |||
// child: TextButton( | |||
// onPressed: (){ | |||
// prefs.setString(keyClass.cabang_id, selected); | |||
// Navigator.pushNamed(context, '/home'); | |||
// }, | |||
// child: Text('Set',style: TextStyle(color: Colors.indigo),), | |||
// ), | |||
// ), | |||
// TextButton( | |||
// onPressed: (){ | |||
// setState(() { | |||
// prefs.setBool(keyClass.logged_in, false); | |||
// prefs.remove(keyClass.cabang_id); | |||
// prefs.remove(keyClass.company); | |||
// prefs.remove(keyClass.loginId); | |||
// }); | |||
// }, | |||
// child: Text('Cancel',style: TextStyle(color: Colors.indigo)), | |||
// ) | |||
// ], | |||
// ), | |||
// ), | |||
// ) | |||
// ], | |||
// ), | |||
// ), | |||
// ), | |||
// ), | |||
// ), | |||
// ); | |||
// } | |||
} | |||
} |
@@ -21,7 +21,7 @@ packages: | |||
name: async | |||
url: "https://pub.dartlang.org" | |||
source: hosted | |||
version: "2.8.2" | |||
version: "2.9.0" | |||
barcode_scan2: | |||
dependency: "direct main" | |||
description: | |||
@@ -42,7 +42,7 @@ packages: | |||
name: characters | |||
url: "https://pub.dartlang.org" | |||
source: hosted | |||
version: "1.2.0" | |||
version: "1.2.1" | |||
charcode: | |||
dependency: transitive | |||
description: | |||
@@ -56,7 +56,7 @@ packages: | |||
name: clock | |||
url: "https://pub.dartlang.org" | |||
source: hosted | |||
version: "1.1.0" | |||
version: "1.1.1" | |||
collection: | |||
dependency: transitive | |||
description: | |||
@@ -133,7 +133,7 @@ packages: | |||
name: fake_async | |||
url: "https://pub.dartlang.org" | |||
source: hosted | |||
version: "1.3.0" | |||
version: "1.3.1" | |||
ffi: | |||
dependency: transitive | |||
description: | |||
@@ -281,21 +281,21 @@ packages: | |||
name: matcher | |||
url: "https://pub.dartlang.org" | |||
source: hosted | |||
version: "0.12.11" | |||
version: "0.12.12" | |||
material_color_utilities: | |||
dependency: transitive | |||
description: | |||
name: material_color_utilities | |||
url: "https://pub.dartlang.org" | |||
source: hosted | |||
version: "0.1.4" | |||
version: "0.1.5" | |||
meta: | |||
dependency: transitive | |||
description: | |||
name: meta | |||
url: "https://pub.dartlang.org" | |||
source: hosted | |||
version: "1.7.0" | |||
version: "1.8.0" | |||
oauth2: | |||
dependency: "direct main" | |||
description: | |||
@@ -316,7 +316,7 @@ packages: | |||
name: path | |||
url: "https://pub.dartlang.org" | |||
source: hosted | |||
version: "1.8.1" | |||
version: "1.8.2" | |||
path_provider: | |||
dependency: "direct main" | |||
description: | |||
@@ -510,7 +510,7 @@ packages: | |||
name: source_span | |||
url: "https://pub.dartlang.org" | |||
source: hosted | |||
version: "1.8.2" | |||
version: "1.9.0" | |||
sqflite: | |||
dependency: "direct main" | |||
description: | |||
@@ -545,7 +545,7 @@ packages: | |||
name: string_scanner | |||
url: "https://pub.dartlang.org" | |||
source: hosted | |||
version: "1.1.0" | |||
version: "1.1.1" | |||
synchronized: | |||
dependency: transitive | |||
description: | |||
@@ -559,14 +559,14 @@ packages: | |||
name: term_glyph | |||
url: "https://pub.dartlang.org" | |||
source: hosted | |||
version: "1.2.0" | |||
version: "1.2.1" | |||
test_api: | |||
dependency: transitive | |||
description: | |||
name: test_api | |||
url: "https://pub.dartlang.org" | |||
source: hosted | |||
version: "0.4.9" | |||
version: "0.4.12" | |||
typed_data: | |||
dependency: transitive | |||
description: | |||