Last active
April 11, 2019 11:29
-
-
Save ashishrawat2911/a59ab9ece9649d1de3dc9527b870c99b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<Database> get database async { | |
if (_database != null) return _database; | |
_database = await getDatabaseInstance(); | |
return _database; | |
} | |
Future<Database> getDatabaseInstance() async { | |
Directory directory = await getApplicationDocumentsDirectory(); | |
String path = join(directory.path, "person.db"); | |
return await openDatabase(path, version: 1, | |
onCreate: (Database db, int version) async { | |
await db.execute("CREATE TABLE Person (" | |
"id integer primary key AUTOINCREMENT," | |
"name TEXT," | |
"city TEXT" | |
")"); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment