Open BrainRayChristensen opened 3 months ago
I found a (not so great) solution. I had to add a dependency on path_provider and then I added the following code to my main method:
void main() async {
WidgetsFlutterBinding.ensureInitialized();
String appDirectory = (await getApplicationDocumentsDirectory()).path;
File oldLocalStorageFile = File(appDirectory + '/' + Constants.storage);
File newLocalStorageFile = File(appDirectory + '/' + 'storage-61f76cb0-842b-4318-a644-e245f50a0b5a.json');
if (oldLocalStorageFile.existsSync()){
if (newLocalStorageFile.existsSync()){
newLocalStorageFile.deleteSync();
}
oldLocalStorageFile.copySync(newLocalStorageFile.path);
oldLocalStorageFile.deleteSync();
};
await initLocalStorage();
runApp(MyApp());
}
I'd much prefer to have an option such as : await initLocalStorage(Constants.storage);
or await initLocalStorage(oldFileLocation: Constants.storage)
I will add migration functionality to the API
What if you used to have multiple different local storages? Would that mean that all those should be migrated into a single instance/file?
I will add migration functionality to the API
Are there any updates about the migration solution?
Up I use localstorage in that way
final storage = LocalStorage(LocalStorageKey.address);
or like that final ready = await storage.ready; if (ready) { await storage.setItem(kLocalKey['countries']!, countries); }
but there is not workaround. Thanks for help
I found a (not so great) solution. I had to add a dependency on path_provider and then I added the following code to my main method:
void main() async { WidgetsFlutterBinding.ensureInitialized(); String appDirectory = (await getApplicationDocumentsDirectory()).path; File oldLocalStorageFile = File(appDirectory + '/' + Constants.storage); File newLocalStorageFile = File(appDirectory + '/' + 'storage-61f76cb0-842b-4318-a644-e245f50a0b5a.json'); if (oldLocalStorageFile.existsSync()){ if (newLocalStorageFile.existsSync()){ newLocalStorageFile.deleteSync(); } oldLocalStorageFile.copySync(newLocalStorageFile.path); oldLocalStorageFile.deleteSync(); }; await initLocalStorage(); runApp(MyApp()); }
I'd much prefer to have an option such as :
await initLocalStorage(Constants.storage);
orawait initLocalStorage(oldFileLocation: Constants.storage)
Hi there, how does this work? It seems to me you are deleting the new local storage file but also copying and deleting it as the old local storage file?
I found a (not so great) solution. I had to add a dependency on path_provider and then I added the following code to my main method:
void main() async { WidgetsFlutterBinding.ensureInitialized(); String appDirectory = (await getApplicationDocumentsDirectory()).path; File oldLocalStorageFile = File(appDirectory + '/' + Constants.storage); File newLocalStorageFile = File(appDirectory + '/' + 'storage-61f76cb0-842b-4318-a644-e245f50a0b5a.json'); if (oldLocalStorageFile.existsSync()){ if (newLocalStorageFile.existsSync()){ newLocalStorageFile.deleteSync(); } oldLocalStorageFile.copySync(newLocalStorageFile.path); oldLocalStorageFile.deleteSync(); }; await initLocalStorage(); runApp(MyApp()); }
I'd much prefer to have an option such as :
await initLocalStorage(Constants.storage);
orawait initLocalStorage(oldFileLocation: Constants.storage)
sorry I read the copy function backwards, this makes sense and helps a lot until migration functionality is added. thank you :)
I used to access local storage like this:
LocalStorage(Constants.storage)
but with the updated api there's no way to access the data that used to be at that location. Is there a way to migrate the old data so users in my app don't lose their configs?