Closed imreallyliam closed 5 years ago
Its flutter. You can easily use if(data != null)
to check if there exsists any data. In case you dont want the first time a null return, i would just add
Map<String, dynamic> data = storage.getItem('key');
if(data == null) {
data = defaultData(); // Replace with own default data
}
...
Or did i misunderstand your issue?
The issue was that it'd return null when there was data. If the data is null, the system overwrites it with default data, causing a reset.
If you got a null, it means you got nothing. I don't think anything is going wrong here. Also, It's your choice whether to overwrite or not. @xeu100
@xeu100 make sure that you call getItem
after await storage.ready
(https://pub.dev/documentation/localstorage/latest/localstorage/LocalStorage/ready.html)
there's also a chance something went wrong during data write, there's an error listener for this (https://pub.dev/documentation/localstorage/latest/localstorage/LocalStorage/onError.html)
A null returns the first time I use Get-Item on a certain page, this (due to the way code is written) causes data to be written as null.
What can be done to prevent nulls on the first call?