diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 51831ae..d7482b9 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -9,6 +9,8 @@ + + + \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index 3100ad2..2536f19 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -6,7 +6,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:4.1.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } diff --git a/android/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties index 296b146..90f271d 100644 --- a/android/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip diff --git a/lib/home.dart b/lib/home.dart index 8abd739..a06fa1e 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -216,62 +216,103 @@ class _HomeState extends State { children: [ InkWell( onTap: ()async{ -// await Future.delayed(Duration(milliseconds: 300)); String Address = prefs.getString(keyClass.hostAddress); +// await Future.delayed(Duration(milliseconds: 300)); util.showLoading(context,dissmissable: false); - var result = await util.JsonDataPostRaw({}, "${Address??"https://asset.thamringroup.web.id"}/admin/getDbList"); + var bUnits = await util.JsonDataPostRaw({}, "${Address??"https://asset.thamringroup.web.id"}/admin/getBisnisList"); Navigator.pop(context); - if(result['STATUS']==1){ - bool isClear = await clearData(context); - if(isClear??false){ - String selected = result['DATA'][0]; - bool res =await showDialog(context: context,builder: (context)=>StatefulBuilder( - builder: (context,setState)=>AlertDialog( - title: Text('Pick Database'), - content: DropdownButtonFormField( - onChanged: (value){ - setState(() { - selected = value; - }); + if(bUnits["STATUS"]==1){ + var selectedBisnis= bUnits["DATA"][0]["id"]; + var bisnisPicked = await showDialog(context: context,builder: (context)=>StatefulBuilder( + builder: (context,setState)=>AlertDialog( + title: Text('Pick Bisnis Unit'), + content: DropdownButtonFormField( + onChanged: (value)async{ + setState(() { + selectedBisnis = value; + }); + }, + value: selectedBisnis, + items: new List>.from(bUnits['DATA'].map((value){ + String showText = value["name"]; + if(showText.length>30) showText = showText.substring(0,30); + return DropdownMenuItem( + child: Text(showText), + value: value["id"], + ); + })), + ), + actions: [ + FlatButton( + onPressed: ()async{ + Navigator.pop(context,true); }, - value: selected, - items: new List>.from(result['DATA'].map((value){ - String showText = value; - if(showText.length>30) showText = showText.substring(0,30); - return DropdownMenuItem( - child: Text(showText), - value: value, - ); - })), + child: Text('Next'), ), - actions: [ - FlatButton( - onPressed: ()async{ - Navigator.pop(context,true); - }, - child: Text('Get'), + FlatButton( + onPressed: ()async{ + Navigator.pop(context,false); + }, + child: Text('Cancel'), + ) + ], + ), + )); + if(bisnisPicked??false){ + util.showLoading(context,dissmissable: false); + var result = await util.JsonDataPostRaw({"bUnit":selectedBisnis}, "${Address??"https://asset.thamringroup.web.id"}/admin/getDbList"); + Navigator.pop(context); + if(result['STATUS']==1){ + bool isClear = await clearData(context); + if(isClear??false){ + String selected = result['DATA'][0]["fullName"]; + bool res =await showDialog(context: context,builder: (context)=>StatefulBuilder( + builder: (context,setState)=>AlertDialog( + title: Text('Pick Database'), + content: DropdownButtonFormField( + onChanged: (value){ + setState(() { + selected = value; + }); + }, + value: selected, + items: new List>.from(result['DATA'].map((value){ + String showText = value["name"]; + if(showText.length>30) showText = showText.substring(0,30); + return DropdownMenuItem( + child: Text(showText), + value: value["fullName"], + ); + })), + ), + actions: [ + FlatButton( + onPressed: ()async{ + Navigator.pop(context,true); + }, + child: Text('Get'), + ), + FlatButton( + onPressed: ()async{ + Navigator.pop(context,false); + }, + child: Text('Cancel'), + ) + ], ), - FlatButton( - onPressed: ()async{ - Navigator.pop(context,false); - }, - child: Text('Cancel'), - ) - ], - ), - )); - if(res??false){ + )); + if(res??false){ // util.showLoading(context,dissmissable: false); - await prefs.setString(keyClass.dbName,selected); - file_Trans_Handler trans = new file_Trans_Handler(); - await trans.downloadFile("assets.db", "${Address??"https://asset.thamringroup.web.id"}/admin/downloadDb/$selected"); - _dlulStream = trans.progress.listen((value)async { - setState(() { - progressDL = (value!=-1.0)?value:null; - }); - if(value!=null&&value >= 1.0) { - _dlulStream.cancel(); - progressDL = null; + await prefs.setString(keyClass.dbName,selected); + file_Trans_Handler trans = new file_Trans_Handler(); + await trans.downloadFile("assets.db", "${Address??"https://asset.thamringroup.web.id"}/admin/downloadDb/$selectedBisnis/$selected"); + _dlulStream = trans.progress.listen((value)async { + setState(() { + progressDL = (value!=-1.0)?value:null; + }); + if(value!=null&&value >= 1.0) { + _dlulStream.cancel(); + progressDL = null; // setState(() { // lastDownload = DateTime.now().toIso8601String(); // }); @@ -281,21 +322,26 @@ class _HomeState extends State { // await DBHelper.database.closeDb(); // var allUnits = await DBHelper.database.getAllAsset(); // print('${allUnits.length} Units'); - util.showToast('ALERT','Data Downloaded'); - } - if(value==-1.0){ - util.showToast('ALERT','Data Error ${trans.error}'); - } - }); + util.showToast('ALERT','Data Downloaded'); + } + if(value==-1.0){ + util.showToast('ALERT','Data Error ${trans.error}'); + } + }); // Navigator.pop(context); - setState(() { + setState(() { - }); + }); + } + } + } + else{ + await util.showToast("ERROR",result['ERROR']??"Database tidak ditemukan"); } } } else{ - await util.showToast("ERROR",result['ERROR']); + await util.showToast("ERROR",bUnits['DATA']); } }, child: Padding(