@@ -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()}'); | |||
@@ -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; | |||
}) | |||
@@ -71,7 +71,7 @@ class _HomePageState extends State<HomePage> { | |||
// 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<HomePage> { | |||
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<HomePage> { | |||
//// 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<HomePage> { | |||
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()){ | |||
@@ -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()); | |||
@@ -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" | |||