Search code examples
fluttersqflite

multiple arguments in sqflite flutter


I want to search database based on the keyword. if it title or content contains the keyword then return the data. but it send backs nothing.


  static Future<List<Note>> searchDocuments(String? keyword) async {
    final database = await DatabaseHelper.database();
 
    List<Map<String, dynamic>> allDocuments = await database.rawQuery(
        'SELECT * FROM docs WHERE title=? and content=?',
        ['$keyword%', '$keyword%']);


checked - doesn't work.


Solution

  • This works.

    await database.rawQuery(
            'SELECT * FROM docs WHERE title LIKE ? OR content LIKE ?',
            ['%$keyword%', '%$keyword%']);