lesnitsky / flutter_localstorage

📦 LocalStorage for Flutter
MIT License
298 stars 65 forks source link

Localstorage doesn't persist when app is closed or restarted #49

Closed gorebang closed 4 years ago

gorebang commented 4 years ago

Unlike Shared_Prefs, when an app using localstorage is hot restarted or the app is closed on the device and restarted, data isn't persisted.

This can be seen by running the example solution, adding some todo items then performing a hot restart (SHIFT R)... the items won't be persisted.

Perhaps I misunderstood the purpose of the package; I was hoping to use it to persist JSON blobs on the device to be retrieved over a longer period of time.

lesnitsky commented 4 years ago

@gorebang hot restart works for me on all platforms

pablofridman commented 4 years ago

Same problem here, solved adding a setState() before retrieving the first time an element from the database (xxx.getItem('')). Happens when you call getItem before finish rendering the app the first time in my case.....

lesnitsky commented 4 years ago

could you please make sure you wait for the localstorage to be initialized

storage.getItem('item'); // null if not yet initialized

await storage.ready;
storage.getItem('item'); // should return data
lesnitsky commented 4 years ago

Seems like https://github.com/lesnitsky/flutter_localstorage/issues/49#issuecomment-676146168 is the reason