0

I keep getting this syntax error : E/SQLiteLog( 4514): (1) near "null": syntax error in "CREATE TABLE expenses_table(id INTEGER PRIMARY KEY AUTOINCREMENT, null TEXT ,null TEXT)"

I am quite new to this, and have been using examples online to put this code together, but I can't seem to find what is causing this issue.

Any help would be very much appreciated!

'''

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

class ExpensesDatabase {
  static ExpensesDatabase _expensesDatabase;
  static Database _database;

  String expensesTable = 'expenses_table';

  String id = 'id';
  String name;
  String amount;

  ExpensesDatabase._createInstance();

  factory ExpensesDatabase() {
    if (_expensesDatabase == null) {
      _expensesDatabase = ExpensesDatabase._createInstance();
    }
    return _expensesDatabase;
  }

  Future<Database> get database async {
    if (_database == null) {
      _database = await initializeDatabase();
    }
    return _database;
  }

  Future<Database> initializeDatabase() async {
    Directory directory = await getApplicationDocumentsDirectory();
    String path = directory.path + 'expenses.db';

    var expensesDatabase =
        await openDatabase(path, version: 1, onCreate: _createDb);
    return expensesDatabase;
  }

  void _createDb(Database db, int newVersion) async {
    await db.execute(
        'CREATE TABLE $expensesTable($id INTEGER PRIMARY KEY AUTOINCREMENT,'
        '$name TEXT,'
        '$amount TEXT)');
  }

'''

1 Answer 1

1

Intialize your name and amount variables, its getting null because string name and amount are not initialised yet.

String name = 'name';
String amount = 'amount';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.