@@ -20,8 +20,9 @@ class DBHelper { | |||||
} | } | ||||
initDb() async { | initDb() async { | ||||
io.Directory documentsDirectory = await getApplicationDocumentsDirectory(); | |||||
io.Directory documentsDirectory = await getExternalStorageDirectory(); | |||||
String path = join(documentsDirectory.path, "UnitStocking.db"); | String path = join(documentsDirectory.path, "UnitStocking.db"); | ||||
print("save at $path"); | |||||
var theDb = await openDatabase(path, version: 1,onCreate: await _onCreate); | var theDb = await openDatabase(path, version: 1,onCreate: await _onCreate); | ||||
return theDb; | return theDb; | ||||
} | } | ||||
@@ -33,7 +34,7 @@ class DBHelper { | |||||
} | } | ||||
_onCreate(Database db, int version) async { | _onCreate(Database db, int version) async { | ||||
io.Directory documentsDirectory = await getApplicationDocumentsDirectory(); | |||||
io.Directory documentsDirectory = await getExternalStorageDirectory(); | |||||
String path = join(documentsDirectory.path, "UnitStocking.db"); | String path = join(documentsDirectory.path, "UnitStocking.db"); | ||||
io.File file = io.File(path); | io.File file = io.File(path); | ||||
print('Database created, ${file.lengthSync()}'); | print('Database created, ${file.lengthSync()}'); | ||||
@@ -73,7 +73,7 @@ class file_Trans_Handler { | |||||
_progress.add(0.0); | _progress.add(0.0); | ||||
print('Finish Download'); | print('Finish Download'); | ||||
final file = File( | final file = File( | ||||
"${(await getApplicationDocumentsDirectory()).path}/$fileName"); | |||||
"${(await getExternalStorageDirectory()).path}/$fileName"); | |||||
await file.writeAsBytes(_bytes); | await file.writeAsBytes(_bytes); | ||||
_path = file.path; | _path = file.path; | ||||
} | } | ||||
@@ -114,7 +114,7 @@ class file_Trans_Handler { | |||||
httpClient = await util.getOauth2Client(); | httpClient = await util.getOauth2Client(); | ||||
oauth2.Credentials tokenRestData = oauth2.Credentials.fromJson(prefs.getString(keyClass.rest_data)); | oauth2.Credentials tokenRestData = oauth2.Credentials.fromJson(prefs.getString(keyClass.rest_data)); | ||||
final file = File( | final file = File( | ||||
"${(await getApplicationDocumentsDirectory()).path}/$fileName"); | |||||
"${(await getExternalStorageDirectory()).path}/$fileName"); | |||||
String mimeType = 'application/vnd.sqlite3'; | String mimeType = 'application/vnd.sqlite3'; | ||||
if(file.existsSync()){ | if(file.existsSync()){ | ||||
Uint8List byte = file.readAsBytesSync(); | Uint8List byte = file.readAsBytesSync(); | ||||
@@ -219,11 +219,11 @@ class file_Trans_Handler { | |||||
request.files.add( | request.files.add( | ||||
await MultipartFile.fromPath( | await MultipartFile.fromPath( | ||||
'picture', | 'picture', | ||||
"${(await getApplicationDocumentsDirectory()).path}/$fileName" | |||||
"${(await getExternalStorageDirectory()).path}/$fileName" | |||||
) | ) | ||||
); | ); | ||||
_response = await httpClient.send(request); | _response = await httpClient.send(request); | ||||
_total = File("${(await getApplicationDocumentsDirectory()).path}/$fileName").lengthSync(); | |||||
_total = File("${(await getExternalStorageDirectory()).path}/$fileName").lengthSync(); | |||||
dlulStream = _response.stream.listen((value) { | dlulStream = _response.stream.listen((value) { | ||||
_bytes.addAll(value); | _bytes.addAll(value); | ||||
print('upload ${_bytes.length/_total}'); | print('upload ${_bytes.length/_total}'); | ||||
@@ -233,7 +233,7 @@ class file_Trans_Handler { | |||||
_progress.add(0.0); | _progress.add(0.0); | ||||
print('Finish Download'); | print('Finish Download'); | ||||
final file = File( | final file = File( | ||||
"${(await getApplicationDocumentsDirectory()).path}/$fileName"); | |||||
"${(await getExternalStorageDirectory()).path}/$fileName"); | |||||
await file.writeAsBytes(_bytes); | await file.writeAsBytes(_bytes); | ||||
_path = file.path; | _path = file.path; | ||||
}) | }) | ||||
@@ -71,7 +71,7 @@ class _HomePageState extends State<HomePage> { | |||||
// await DBHelper.database.closeDb(); | // await DBHelper.database.closeDb(); | ||||
// if(result!=null){ | // if(result!=null){ | ||||
try{ | try{ | ||||
Directory documentsDirectory = await getApplicationDocumentsDirectory(); | |||||
Directory documentsDirectory = await getExternalStorageDirectory(); | |||||
String path = join(documentsDirectory.path, "UnitStocking.db"); | String path = join(documentsDirectory.path, "UnitStocking.db"); | ||||
File db = File(path); | File db = File(path); | ||||
if(db.existsSync()){ | if(db.existsSync()){ | ||||
@@ -292,7 +292,7 @@ class _HomePageState extends State<HomePage> { | |||||
lastDownload = ''; | lastDownload = ''; | ||||
timeString = ''; | timeString = ''; | ||||
try{ | try{ | ||||
Directory documentsDirectory = await getApplicationDocumentsDirectory(); | |||||
Directory documentsDirectory = await getExternalStorageDirectory(); | |||||
String path = join(documentsDirectory.path, "UnitStocking.db"); | String path = join(documentsDirectory.path, "UnitStocking.db"); | ||||
File db = File(path); | File db = File(path); | ||||
if(db.existsSync()){ | if(db.existsSync()){ | ||||
@@ -355,7 +355,7 @@ class _HomePageState extends State<HomePage> { | |||||
//// await DBHelper.database.closeDb(); | //// await DBHelper.database.closeDb(); | ||||
//// if(result!=null){ | //// if(result!=null){ | ||||
// try{ | // try{ | ||||
// Directory documentsDirectory = await getApplicationDocumentsDirectory(); | |||||
// Directory documentsDirectory = await getExternalStorageDirectory(); | |||||
// String path = join(documentsDirectory.path, "UnitStocking.db"); | // String path = join(documentsDirectory.path, "UnitStocking.db"); | ||||
// File db = File(path); | // File db = File(path); | ||||
// if(db.existsSync()){ | // if(db.existsSync()){ | ||||
@@ -728,7 +728,7 @@ class _HomePageState extends State<HomePage> { | |||||
a.start(); | a.start(); | ||||
await Future.delayed(Duration(milliseconds: 200)); | await Future.delayed(Duration(milliseconds: 200)); | ||||
bool isclear; | bool isclear; | ||||
Directory documentsDirectory = await getApplicationDocumentsDirectory(); | |||||
Directory documentsDirectory = await getExternalStorageDirectory(); | |||||
String path = join(documentsDirectory.path, "UnitStocking.db"); | String path = join(documentsDirectory.path, "UnitStocking.db"); | ||||
File db = File(path); | File db = File(path); | ||||
if(db.existsSync()){ | if(db.existsSync()){ | ||||
@@ -29,26 +29,33 @@ registerCert()async{ | |||||
} | } | ||||
void main() async{ | void main() async{ | ||||
// prefs = await SharedPreferences.getInstance(); | |||||
WidgetsFlutterBinding.ensureInitialized(); | 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(); | 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]) | SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]) | ||||
.then((_) { | .then((_) { | ||||
runApp(new MyApp()); | runApp(new MyApp()); | ||||
@@ -1,7 +1,7 @@ | |||||
name: unitstocks | name: unitstocks | ||||
description: App to stock Thamrin Brothers Units | description: App to stock Thamrin Brothers Units | ||||
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html | # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html | ||||
version: 1.0.4+7 | |||||
version: 1.0.4+8 | |||||
environment: | environment: | ||||
sdk: ">=2.1.0 <3.0.0" | sdk: ">=2.1.0 <3.0.0" | ||||