NestifyCode
 · Flutterflow expert

To create a SqLite file must i have toggled enable Sqlite

Actions & Logic

I have created a custom action to create sqlite file also to query etc
must I toggle this button on my settings or my action will function just fine Serge Middendorf
Fongang Rodrique


// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/schema/structs/index.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:sqflite/sqflite.dart';

Future creeateLocalFile(
  String? transactionId,
  double? amount,
  DateTime? date,
) async {

  Future<void> createLocalFile(
      String? transactionId, double? amount, DateTime? date) async {
    
    Directory documentsDirectory = await getApplicationDocumentsDirectory();
    String path = documentsDirectory.path + '/transactions.db';

    
    Database database = await openDatabase(path, version: 1,
        onCreate: (Database db, int version) async {
     
      await db.execute(
          'CREATE TABLE transactions (id INTEGER PRIMARY KEY, transactionId TEXT, amount REAL, date TEXT)');
    });

    
    await database.transaction((txn) async {
      await txn.rawInsert(
          'INSERT INTO transactions(transactionId, amount, date) VALUES("$transactionId", $amount, "${date.toString()}")');
    });

    // Close the database
    await database.close();
  }
}


What have you tried so far?

Nothing yet

Did you check FlutterFlow's Documentation for this topic?
No
1
6 replies