Skip to content

rajajawahar/FlutterDatabaseSQFLite

Repository files navigation

Sample application to save a data in SQFLite database.

Install dependencies

cupertino_icons: ^0.1.0
path_provider: '>=0.3.0'
sqflite : any

Create a database with name "test.db"

initDb() async {
    io.Directory documentsDirectory = await getApplicationDocumentsDirectory();
    String path = join(documentsDirectory.path, "test.db");
    var theDb = await openDatabase(path, version: 1, onCreate: _onCreate);
    return theDb;
}

Create a table named "Employee"

void _onCreate(Database db, int version) async {
    // When creating the db, create the table
    await db.execute(
        "CREATE TABLE Employee(id INTEGER PRIMARY KEY, firstname TEXT, lastname TEXT, mobileno TEXT,emailId TEXT )");
    print("Created tables");
}

Saving a employee data in Table

void saveEmployee(Employee employee) async {
    var dbClient = await db;
    await dbClient.transaction((txn) async {
      return await txn.rawInsert(
          'INSERT INTO Employee(firstname, lastname, mobileno, emailid ) VALUES(' +
              '\'' +
              employee.firstName +
              '\'' +
              ',' +
              '\'' +
              employee.lastName +
              '\'' +
              ',' +
              '\'' +
              employee.mobileNo +
              '\'' +
              ',' +
              '\'' +
              employee.emailId +
              '\'' +
              ')');
    });
  }

 

About

Sample flutter app using SQFlite database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published