Hi ,
I am developing an application using FlutterFlow, and I am having trouble using SQLite when creating custom functions or custom actions. I have noticed that I need values like opendatabase
and dbpath
every time. I would like to understand the issues I am facing in this process and the best approach to take.
import 'package:sqflite/sqflite.dart';
Future<Database> openDatabaseConnection() async {
String dbPath = await getDatabasesPath();
String path = join(dbPath, 'my_database.db');
Database database = await openDatabase(
path,
version: 1,
onCreate: (Database db, int version) async {
await db.execute('''
CREATE TABLE my_table (
id INTEGER PRIMARY KEY,
name TEXT
)
''');
},
);
return database;
}
Future<void> insertData(String name) async {
Database db = await openDatabaseConnection();
await db.insert('my_table', {'name': name});
}
Future<List<Map<String, dynamic>>> fetchData() async {
Database db = await openDatabaseConnection();
return await db.query('my_table');
}
In this code, the openDatabaseConnection
function opens the database, the insertData
function adds a new record, and the fetchData
function retrieves existing data. However, how can I effectively implement these processes in FlutterFlow?
What best practices should I consider in this process? I would greatly appreciate your help!
Thank you!