1

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.

Mahi
  • 1,297
  • 1
  • 14
  • 28

2 Answers2

1

This works.

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

Mahi
  • 1,297
  • 1
  • 14
  • 28
0
  await database.rawQuery(
        'SELECT * FROM docs WHERE title="$keyword" AND content="$keyword"');
Sandeep Singh
  • 241
  • 1
  • 9