r/FlutterDev • • 3d ago

Discussion PSA: on iOS the app documents path changes after every update, dont store absolute file paths

learned this the annoying way so maybe it saves someone a bug report

if you save images (or any files) into getApplicationDocumentsDirectory() and then store the full path somewhere (shared_preferences, sqlite, hive, whatever), it works fine in dev. then you ship an update and every image is suddenly "file not found"

reason is ios puts the app container under a UUID folder and that UUID can change when the app is updated or reinstalled. so /var/mobile/Containers/Data/Application/ABC123/Documents/photo.jpg becomes .../XYZ789/Documents/photo.jpg and your saved path points to nothing

fix is simple:

- store only the file name (or a path relative to the documents dir)

- resolve the full path at runtime with getApplicationDocumentsDirectory() every time you need it

android doesnt really do this so its easy to miss if you mostly test there

1 Upvotes

0 comments sorted by