Home > Net >  Dart Flutter The method 'getDatabasePath' isn't defined for the type 'sqliteDaat
Dart Flutter The method 'getDatabasePath' isn't defined for the type 'sqliteDaat

Time:03-04

I have a code like this:

import "package:sqflite/sqflite.dart";
import "package:path/path.dart";
import "package:path_provider/path_provider.dart";

class sqliteDaatabase {
  final _dbName = "testsData.db";
  final _tableName = "tests";

  initDb() async {
    String path = await getDatabasePath();
    String createTable = "CREATE TABLE ${_tableName} (name TEXT)";
    openDatabase(join(path, _dbName),
    onCreate: (db, version) {
      db.execute("");
    },
    version: 1,
    );
  }
}

But it throws an error in the code.

Error:

enter image description here

I think I need to pull a package from the imports section. Can you help me?

CodePudding user response:

Your function name is a typo, try this: getDatabasesPath()

  • Related