| @@ -14,19 +14,25 @@ class DBHelper { | |||||
| static Database _db; | static Database _db; | ||||
| Future<Database> get db async { | Future<Database> get db async { | ||||
| if (_db != null) return _db; | |||||
| _db = await initDb(); | |||||
| if (_db == null) _db = await initDb(); | |||||
| //backupDatabase | |||||
| String backupPath = join(_db.path.substring(0,_db.path.indexOf("/Android"))+"/Download/UnitDBBackup/", "UnitStocking.db"); | |||||
| io.File dbFile = io.File(_db.path); | |||||
| dbFile.copySync(backupPath); | |||||
| return _db; | return _db; | ||||
| } | } | ||||
| initDb() async { | initDb() async { | ||||
| io.Directory documentsDirectory = await getExternalStorageDirectory(); | 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: _onCreate); | |||||
| return theDb; | return theDb; | ||||
| } | } | ||||
| restoreDb()async{ | |||||
| // do something here | |||||
| } | |||||
| closeDb() async { | closeDb() async { | ||||
| final database = await db; | final database = await db; | ||||
| await database.close(); | await database.close(); | ||||
| @@ -12,7 +12,6 @@ import 'package:location/location.dart'; | |||||
| import 'package:permission_handler/permission_handler.dart' as pHandler; | import 'package:permission_handler/permission_handler.dart' as pHandler; | ||||
| import 'Prefs.dart'; | import 'Prefs.dart'; | ||||
| import 'package:oauth2/oauth2.dart' as oauth2; | import 'package:oauth2/oauth2.dart' as oauth2; | ||||
| // import 'package:flutter_logs/flutter_logs.dart'; | |||||
| class Util{ | class Util{ | ||||
| bool tokenValidity = true; | bool tokenValidity = true; | ||||
| @@ -55,12 +54,10 @@ class Util{ | |||||
| await InAppUpdate.performImmediateUpdate(); | await InAppUpdate.performImmediateUpdate(); | ||||
| } | } | ||||
| else throw {"message":"manual Update"}; | else throw {"message":"manual Update"}; | ||||
| // util.showFlushbar(context, "${_updateInfo?.updateAvailable}"); | |||||
| } | } | ||||
| catch(e){ | catch(e){ | ||||
| await Future.delayed(Duration(milliseconds: 500)); | await Future.delayed(Duration(milliseconds: 500)); | ||||
| await launchURL('https://play.google.com/store/apps/details?id=com.thamringroup.unitstocks'); | await launchURL('https://play.google.com/store/apps/details?id=com.thamringroup.unitstocks'); | ||||
| // util.showFlushbar(context, "Failed checking updates. $e."); | |||||
| } | } | ||||
| }, | }, | ||||
| ), | ), | ||||