diff --git a/lib/Util/DBHelper.dart b/lib/Util/DBHelper.dart index 8a7315b..18cc6f3 100644 --- a/lib/Util/DBHelper.dart +++ b/lib/Util/DBHelper.dart @@ -20,8 +20,9 @@ class DBHelper { } initDb() async { - io.Directory documentsDirectory = await getApplicationDocumentsDirectory(); + io.Directory documentsDirectory = await getExternalStorageDirectory(); String path = join(documentsDirectory.path, "UnitStocking.db"); + print("save at $path"); var theDb = await openDatabase(path, version: 1,onCreate: await _onCreate); return theDb; } @@ -33,7 +34,7 @@ class DBHelper { } _onCreate(Database db, int version) async { - io.Directory documentsDirectory = await getApplicationDocumentsDirectory(); + io.Directory documentsDirectory = await getExternalStorageDirectory(); String path = join(documentsDirectory.path, "UnitStocking.db"); io.File file = io.File(path); print('Database created, ${file.lengthSync()}'); diff --git a/lib/Util/download_Upload_Handler.dart b/lib/Util/download_Upload_Handler.dart index 47183d1..2cdf28b 100644 --- a/lib/Util/download_Upload_Handler.dart +++ b/lib/Util/download_Upload_Handler.dart @@ -73,7 +73,7 @@ class file_Trans_Handler { _progress.add(0.0); print('Finish Download'); final file = File( - "${(await getApplicationDocumentsDirectory()).path}/$fileName"); + "${(await getExternalStorageDirectory()).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 getApplicationDocumentsDirectory()).path}/$fileName"); + "${(await getExternalStorageDirectory()).path}/$fileName"); String mimeType = 'application/vnd.sqlite3'; if(file.existsSync()){ Uint8List byte = file.readAsBytesSync(); @@ -219,11 +219,11 @@ class file_Trans_Handler { request.files.add( await MultipartFile.fromPath( 'picture', - "${(await getApplicationDocumentsDirectory()).path}/$fileName" + "${(await getExternalStorageDirectory()).path}/$fileName" ) ); _response = await httpClient.send(request); - _total = File("${(await getApplicationDocumentsDirectory()).path}/$fileName").lengthSync(); + _total = File("${(await getExternalStorageDirectory()).path}/$fileName").lengthSync(); dlulStream = _response.stream.listen((value) { _bytes.addAll(value); print('upload ${_bytes.length/_total}'); @@ -233,7 +233,7 @@ class file_Trans_Handler { _progress.add(0.0); print('Finish Download'); final file = File( - "${(await getApplicationDocumentsDirectory()).path}/$fileName"); + "${(await getExternalStorageDirectory()).path}/$fileName"); await file.writeAsBytes(_bytes); _path = file.path; }) diff --git a/lib/home_page.dart b/lib/home_page.dart index 09ba580..0227a23 100644 --- a/lib/home_page.dart +++ b/lib/home_page.dart @@ -71,7 +71,7 @@ class _HomePageState extends State { // await DBHelper.database.closeDb(); // if(result!=null){ try{ - Directory documentsDirectory = await getApplicationDocumentsDirectory(); + Directory documentsDirectory = await getExternalStorageDirectory(); String path = join(documentsDirectory.path, "UnitStocking.db"); File db = File(path); if(db.existsSync()){ @@ -292,7 +292,7 @@ class _HomePageState extends State { lastDownload = ''; timeString = ''; try{ - Directory documentsDirectory = await getApplicationDocumentsDirectory(); + Directory documentsDirectory = await getExternalStorageDirectory(); String path = join(documentsDirectory.path, "UnitStocking.db"); File db = File(path); if(db.existsSync()){ @@ -355,7 +355,7 @@ class _HomePageState extends State { //// await DBHelper.database.closeDb(); //// if(result!=null){ // try{ -// Directory documentsDirectory = await getApplicationDocumentsDirectory(); +// Directory documentsDirectory = await getExternalStorageDirectory(); // String path = join(documentsDirectory.path, "UnitStocking.db"); // File db = File(path); // if(db.existsSync()){ @@ -728,7 +728,7 @@ class _HomePageState extends State { a.start(); await Future.delayed(Duration(milliseconds: 200)); bool isclear; - Directory documentsDirectory = await getApplicationDocumentsDirectory(); + Directory documentsDirectory = await getExternalStorageDirectory(); String path = join(documentsDirectory.path, "UnitStocking.db"); File db = File(path); if(db.existsSync()){ diff --git a/lib/main.dart b/lib/main.dart index e068c69..fb42aa0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -29,26 +29,33 @@ registerCert()async{ } void main() async{ + // prefs = await SharedPreferences.getInstance(); WidgetsFlutterBinding.ensureInitialized(); - prefs = await SharedPreferences.getInstance(); + SharedPreferences.getInstance().then((pref) async{ + prefs = pref; + await prefs.setString(keyClass.hostAddress, "https://tbg.thamringroup.web.id/ords/tbs/unit/v1"); + await prefs.setString(keyClass.restTokenAddress, "https://tbg.thamringroup.web.id/ords/tbs/oauth/token"); + }, + onError: (error) { + print("SharedPreferences ERROR = $error"); + }); + // if( prefs.getString(keyClass.hostAddress) ==null) await registerCert(); - if( prefs.getString(keyClass.hostAddress) ==null)await prefs.setString(keyClass.hostAddress, "https://tbg.thamringroup.web.id/ords/tbs/unit/v1"); - await prefs.setString(keyClass.restTokenAddress, "https://tbg.thamringroup.web.id/ords/tbs/oauth/token"); - await FlutterLogs.initLogs( - logLevelsEnabled: [ - LogLevel.INFO, - LogLevel.WARNING, - LogLevel.ERROR, - LogLevel.SEVERE - ], - timeStampFormat: TimeStampFormat.TIME_FORMAT_READABLE, - directoryStructure: DirectoryStructure.FOR_DATE, - logTypesEnabled: ["device","network","errors"], - logFileExtension: LogFileExtension.LOG, - logsWriteDirectoryName: "MyLogs", - logsExportDirectoryName: "MyLogs/Exported", - debugFileOperations: true, - isDebuggable: true); + // await FlutterLogs.initLogs( + // logLevelsEnabled: [ + // LogLevel.INFO, + // LogLevel.WARNING, + // LogLevel.ERROR, + // LogLevel.SEVERE + // ], + // timeStampFormat: TimeStampFormat.TIME_FORMAT_READABLE, + // directoryStructure: DirectoryStructure.FOR_DATE, + // logTypesEnabled: ["device","network","errors"], + // logFileExtension: LogFileExtension.LOG, + // logsWriteDirectoryName: "MyLogs", + // logsExportDirectoryName: "MyLogs/Exported", + // debugFileOperations: true, + // isDebuggable: true); SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]) .then((_) { runApp(new MyApp()); diff --git a/pubspec.yaml b/pubspec.yaml index 7d235d7..0c732fe 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: unitstocks description: App to stock Thamrin Brothers Units # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.0.4+7 +version: 1.0.4+8 environment: sdk: ">=2.1.0 <3.0.0"