Make sure you always use the transaction object for database operations during a transaction

I am adding data records to the sqflite database and then fetching them to schedule notifications using the flutter_local_notifications package. Although I have a transaction object for the insert and query functions of the DB, I see a message that the database is locked after all the notifications are scheduled.

  • Expected Results: All the notifications should be scheduled based on the data fetched from the DB without locking the DB. So that I can see the output.
  • Actual Results: I see a warning message that DB is locked after all the notifications are scheduled and then I am unable to see the output or be able to debug after the warning pops up.
  • Error Messages: Make sure you always use the transaction object for database operations during a transaction

I tried adding the transaction object to all the database transactions I have in my project. Also, I tried using the raw queries(rawQuery, rawInsert) instead of the predefined methods (query, insert). Here’s
The minimum code needed to reproduce the problem -

static Future<List<Map<String, dynamic>>> queryDB(string table) async{
      var results;
      await _db.transaction((txn) async {
      results = await txn.query(table);
    }); 
}
// Function to insert data into DB
static void insertMedicationRoutine(String table, Item item) async{
      await _db.transaction((txn) async {
      return await txn.insert(table, item.toMap());
     });
}

// Fetching the data from DB as a list and then iterating over each item to the prepare notifications.

void SetReminders() async{
    var items = await queryDB('mytable');
    items.forEach((item) {
        prepareNotification(item);
    });

//Code I used to schedule notifications using the flutter_local_notifications package
void prepareNotification(Item item) {
    
      var androidDetails = new AndroidNotificationDetails("Channel ID", "Channel Name", "Channel description", importance: Importance.max);
      var iOSDetails = new IOSNotificationDetails();
      var generalNotificationDetails = new NotificationDetails(android : androidDetails, iOS : iOSDetails);
      String sometDateTime =  item.somedate.split('T')[0] + 'T' + (item.sometime);
      var scheduledTime = DateTime.parse(DateFormat('yyyy-MM-dd HH:mm:ss').format(DateTime.parse(someDateTime)));
      String notificationSummary = 'Notification';
      String notificationDescription = 'This is description. ';
      nonDrugTreatmentReminderNotification.schedule(generateNotificationId(), notificationSummary , notificationDescription ,  scheduledTime, generalNotificationDetails, payload : notificationDescription);
    }