Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I list the table names in a SQFlite Database in Flutter?

I have tried the following and only received information on the entire database.

listTables() async {
    sqflite.Database dbClient = await this.db;

    List<Map<String, dynamic>> tables = await dbClient
        .query('sqlite_master');

    print(tables);
  }

I am looking to get a list of the table names which exist in the database.

like image 726
S Galway Avatar asked Oct 31 '25 11:10

S Galway


1 Answers

As you see in the output, the schema is simple. sqlite_master table rows have type = 'table' and a name column.

Debug print:

(await db.query('sqlite_master', columns: ['type', 'name'])).forEach((row) {
  print(row.values);
});

to get something like:

(table, Product)
(table, Client)
(table, Request)
(index, Request_clientId)
(index, Request_productId)

You can get the table names with the following code:

var tableNames = (await db
        .query('sqlite_master', where: 'type = ?', whereArgs: ['table']))
    .map((row) => row['name'] as String)
    .toList(growable: false);
like image 76
alextk Avatar answered Nov 02 '25 15:11

alextk