Skip to content
This repository has been archived by the owner on Mar 6, 2023. It is now read-only.

Insert locale-dependent document into db #10

Closed
stemuk opened this issue Oct 15, 2018 · 2 comments
Closed

Insert locale-dependent document into db #10

stemuk opened this issue Oct 15, 2018 · 2 comments

Comments

@stemuk
Copy link

stemuk commented Oct 15, 2018

I am currently trying to insert a different document into objectDb depending on the users locale.
In short, my code currently goes like:

void main() async {
  // get document directory using path_provider plugin
  Directory appDocDir = await getApplicationDocumentsDirectory();

  String dbFilePath = [appDocDir.path, 'user.db'].join('/');

  // initialize and open database
  db = ObjectDB(dbFilePath);

  // delete old database file if exists
  File dbFile = File(dbFilePath);

  // check if database already exists
  var isNew = !await dbFile.exists();

  db.open();
  if (isNew) {
    //insert first document
    final document =
        r'[{"insert":"Welcome"}];
   db.insert({
      'document': document,
      'key': randomKey,
    });
  }
}

Now I am wondering: Is it possible to insert a different document into the db depending on the user devices locale? My first try was using Localizations.localeOf(context); which however didn't work because the main() function does not have a context. Is there any other way of achieving this?

PS: Sorry for asking a simple question as an issue, I just didn't find any other place to ask. Thanks a lot for the awesome database! 👍

@marioreggiori
Copy link
Owner

Check out the objectdb_flutter example. You can insert data before returning the root component.

You could ask the question on StackOverflow ;)
& feel free to send me a pm via Twitter @marioreggiori if i don't respond soon.

@marioreggiori
Copy link
Owner

Feel free to reopen if there are more questions related to this topic.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants