From 4cf4901a2c6423d7673268751b4079bb170dcb5d Mon Sep 17 00:00:00 2001 From: jefry Date: Fri, 10 Dec 2021 16:54:37 +0700 Subject: [PATCH] sampek restore db method in db helper --- lib/Util/DBHelper.dart | 14 ++++++++++---- lib/Util/Util.dart | 3 --- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/Util/DBHelper.dart b/lib/Util/DBHelper.dart index 18cc6f3..4b0712a 100644 --- a/lib/Util/DBHelper.dart +++ b/lib/Util/DBHelper.dart @@ -14,19 +14,25 @@ class DBHelper { static Database _db; Future 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; } initDb() async { 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); + var theDb = await openDatabase(path, version: 1,onCreate: _onCreate); return theDb; } + restoreDb()async{ + // do something here + } + closeDb() async { final database = await db; await database.close(); diff --git a/lib/Util/Util.dart b/lib/Util/Util.dart index 39f642a..0489485 100644 --- a/lib/Util/Util.dart +++ b/lib/Util/Util.dart @@ -12,7 +12,6 @@ import 'package:location/location.dart'; import 'package:permission_handler/permission_handler.dart' as pHandler; import 'Prefs.dart'; import 'package:oauth2/oauth2.dart' as oauth2; -// import 'package:flutter_logs/flutter_logs.dart'; class Util{ bool tokenValidity = true; @@ -55,12 +54,10 @@ class Util{ await InAppUpdate.performImmediateUpdate(); } else throw {"message":"manual Update"}; -// util.showFlushbar(context, "${_updateInfo?.updateAvailable}"); } catch(e){ await Future.delayed(Duration(milliseconds: 500)); await launchURL('https://play.google.com/store/apps/details?id=com.thamringroup.unitstocks'); -// util.showFlushbar(context, "Failed checking updates. $e."); } }, ),