Skip to content

Instantly share code, notes, and snippets.

@tomalabaster
Created March 1, 2020 01:06
Show Gist options
  • Save tomalabaster/fde073ac0490c685e143e1cfb4ea060e to your computer and use it in GitHub Desktop.
Save tomalabaster/fde073ac0490c685e143e1cfb4ea060e to your computer and use it in GitHub Desktop.
GOOD: Async init done in main method
void main() async {
WidgetsFlutterBinding.ensureInitialized();
var databasesPath = await getDatabasesPath();
var path = join(databasesPath, 'example.db');
var database = await openDatabase(path, version: 1, onCreate: (db, version) async {
await db.execute('''CREATE TABLE MyTable (
id INTEGER PRIMARY KEY,
name TEXT)''');
});
runApp(MyApp(database: database));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment