maplibre / flutter-maplibre-gl

Customizable, performant and vendor-free vector and raster maps, flutter wrapper for maplibre-native and maplibre-gl-js (fork of flutter-mapbox-gl/maps)
https://pub.dev/packages/maplibre_gl
Other
186 stars 106 forks source link

Offline Regions Empty after Restart App, IOS only #381

Open GaelleJoubert opened 4 months ago

GaelleJoubert commented 4 months ago

Hello, I am facing a (new?) issue about offline regions, but only in IOS.

tldr : The function getListOfRegions() return a empty list at the start of the app, even if we previously downloaded some regions in another session. This bug is only in IOS !!

At the start of the application, I am calling : getListOfRegions() function, to get all the previously downloaded Regions.

In Android, the Downloaded regions are saved even when the app is killed. For exemple, if I do the following actions :

1- Download the Region (A) 2- Wait for the download to be over 3- Kill the App 4- Open the App and call the function getListOfRegions()

On the 4th action, the function getListOfRegions() return the Region (A) as expected.

Now, if I do the exact same thing on IOS : on the 4th action, the function getListOfRegions() return an empty list !

I am pretty sure it used to work fine on IOS, but it's not anymore.

I tried to run the exemple App bpth on Android and IOS, but starting downloading a region makes the app crash (both IOS and Android ...). But still I have noticed something similar :

Has anyone encouter the same issue ? I would be curious to know if someone mannage to use offline region in IOS in a way to still have them after killing the app.

GaelleJoubert commented 4 months ago

[FIX] I fixed my issue.

TLDR : I was calling getListOfRegions() too soon.

More detailed explaination :

I am using Provoider to save the list of downloaded Regions. My "SavedMapProvider" is instanciated at the very Root of my App, before Maplibre is ever called. The function getListOfRegions() is called at the init of the Provider. At that time, (only in IOS), it returns 0 at the start of the app.

I tried to call the function later : In the InitState of the page were the offline map are displayed. Even there, If I call the functiun straigh away, it still return an empty list, but if I add a delaly of 500ms, this time, it worked !!

The weird thing is that I do not face this issue with Android. I am also pretty sure that the behavior changed, and it use to work in IOS as well.

Knowing the fix, the issue was not that bad, but I guess maybe it is worth adding a little note in the Read Me, to avoid other a loooong time of debegging. (It took me a little bit more than a day to figure it out). What do you think @m0nac0 should I do a PR to edit the read me ?

m0nac0 commented 4 months ago

Maybe better add a note to the doc comment of getListOfRegions() in the dart code, to avoid the Readme getting to cluttered, and also since others with the same problem will/should probably look there, what do you think?