Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I display my UI only after my app is initialized?

I have a Dart + Web UI app that first needs to load data from the local IndexedDB store. The IndexedDB API is asynchronous, so I will get a callback when my data is loaded. I do not want to display any UI elements until my database is first opened and ready to go.

How can I wait for my database initialization before I display my UI?

like image 727
Seth Ladd Avatar asked Feb 12 '13 04:02

Seth Ladd


2 Answers

I am doing it in my project the Web UI way:

...
<body>
  <template if="showApplication">
    <span>The app is ready.</span>
  </template>
</body>
...
@observable bool showApplication = false;

main() {
  // Initialize...
  window.indexedDB.open(...).then((_) {
    showApplication = true;
  });
}

This has also an added bonus: separate code / web components can also check the app state before relying on db connectivity, etc.

like image 108
Kai Sellgren Avatar answered Oct 07 '22 05:10

Kai Sellgren


Hide the body tag with visibility:hidden:

<body style="visibility:hidden">
  <!-- content -->
</body>

And then show it in your future's then() callback

window.indexedDB.open(dbName, 
  version: version, 
  onUpgradeNeeded: createObjectStore).then(handleDBOpened);

handleDBOpened(..) {
  query('body').style.visibility = "visible"; // <-- show the body tag
}
like image 23
Chris Buckett Avatar answered Oct 07 '22 04:10

Chris Buckett