James O Claire
08/30/2023, 1:53 PMprivate val Context.datastore by dataStore(fileKey, WeatherInfoSerializer)
(replaceing the default FILENAME parameter with fileKey, but as it was not yet initialized, it does not work. I'm a bit lost as to how this should be done, though the comments in WeatherApp allude to it being close. Could someone share some help?
I also asked my question here in Stack Overflow:
https://stackoverflow.com/questions/77008645/how-to-make-unique-datastore-for-each-glance-widgetselcukbulca
08/30/2023, 1:57 PMDataStoreFactory
to create a new DataStore for each `fileKey`:
override suspend fun getDataStore(context: Context, fileKey: String) = DataStoreFactory.create(
serializer = serializer,
produceFile = { getLocation(context, fileKey) }
)
override fun getLocation(context: Context, fileKey: String) =
context.dataStoreFile(DATA_STORE_FILENAME_PREFIX + fileKey.lowercase())
James O Claire
08/30/2023, 2:30 PMprivate val Context.datastore by dataStore(DATA_STORE_FILENAME, WeatherInfoSerializer)
is no longer needed to create the datastore, and instead getDataStore creates the unique files.
I implemented the above as you shared it, and by one small change to get the random weather info to be made for each GlanceId, I was able to see different numbers for each widget, as well as confirm that inside /datastore/ there were two files! Thank you so much!James O Claire
08/30/2023, 2:39 PMJames O Claire
08/30/2023, 3:25 PMSummers Pittman
08/31/2023, 2:41 PMSummers Pittman
08/31/2023, 2:47 PMJames O'Claire
09/13/2023, 6:00 AM