1

I developed my app for Windows and it works perfectly fine. So after some time I tried to build it to Android, it come with an error

E/Box     (30248): Storage error "Read-only file system" (code 30)

I have read the doc from Objectbox and I know that it is because I tried to access a read only directory. Pretty self explanatory. My question is then how do I fix it ? How do I access the not read-only ?

Here is my code to initialize my Store

Directory paths = Directory("");    
getApplicationDocumentsDirectory().then((dir) => paths = dir);
    _store = Store(getObjectBoxModel(),directory: p.join(paths.path, 'objectBoxMyDirectory'));

Thanks y'all

Trisk Khan
  • 25
  • 7

1 Answers1

3

getApplicationDocumentsDirectory returns a Future, meaning there is an delay, .then() is not called immediately.

You can use

final dir = await getApplicationDocumentsDirectory();
    _store = Store(getObjectBoxModel(), directory: p.join(paths.path, 'objectBoxMyDirectory'));

or if you cannot make your function async

() async {
    final dir = await getApplicationDocumentsDirectory();
    _store = Store(getObjectBoxModel(), directory: p.join(paths.path, 'objectBoxMyDirectory'));
  }();
  • Yes sir. Apparently I have false logic there. Would you explain it a bit more about `then()` ?. I thought `then()` supposed to called after the Future is finished running, that way my code kind of waiting the future to finished first. – Trisk Khan May 04 '23 at 13:48
  • 2
    `then()` is called after future completed, but the main process continues without waiting for the future to complete unless you use the `await` – PurplePolyhedron May 04 '23 at 14:51