Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating to latest api #104

Open
BrainRayChristensen opened this issue Jun 24, 2024 · 5 comments
Open

Migrating to latest api #104

BrainRayChristensen opened this issue Jun 24, 2024 · 5 comments

Comments

@BrainRayChristensen
Copy link

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?

@BrainRayChristensen
Copy link
Author

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)

@lesnitsky
Copy link
Owner

lesnitsky commented Jun 24, 2024

I will add migration functionality to the API

@RodideBoer
Copy link

What if you used to have multiple different local storages?
Would that mean that all those should be migrated into a single instance/file?

@ChristianMaidhof
Copy link

I will add migration functionality to the API

Are there any updates about the migration solution?

@im-web
Copy link

im-web commented Sep 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants