import 'dart:async'; import 'package:flutter/widgets.dart'; import 'package:path/path.dart'; import 'package:sqflite/sqflite.dart'; Future deleteDb() async { final path = join(await getDatabasesPath(), 'envelope.db'); deleteDatabase(path); } Future getDatabaseConnection() async { WidgetsFlutterBinding.ensureInitialized(); final path = join(await getDatabasesPath(), 'envelope.db'); final database = openDatabase( path, onCreate: (db, version) async { await db.execute( ''' CREATE TABLE IF NOT EXISTS friends( id TEXT PRIMARY KEY, user_id TEXT, username TEXT, friend_id TEXT, symmetric_key TEXT, accepted_at TEXT ); '''); // TODO: Change users to use its own table, as it is a json blob await db.execute( ''' CREATE TABLE IF NOT EXISTS conversations( id TEXT PRIMARY KEY, user_id TEXT, conversation_detail_id TEXT, message_thread_key TEXT, symmetric_key TEXT, admin INTEGER, name TEXT, users TEXT ); '''); await db.execute( ''' CREATE TABLE IF NOT EXISTS messages( id TEXT PRIMARY KEY, message_thread_key TEXT, symmetric_key TEXT, data TEXT, sender_id TEXT, sender_username TEXT, created_at TEXT ); '''); }, // Set the version. This executes the onCreate function and provides a // path to perform database upgrades and downgrades. version: 1, ); return database; }