Flutter floor database: The select * query that returns a stream is not updated upon deleting a record

Viewed 732

Using the floor package for flutter: https://pub.dev/packages/floor

When trying to delete a record from a table ex."Car" using the below SQL statement, the record is deleted but the reactive stream that monitors changes in the table doesn't get updated.

@Query('DELETE FROM Car WHERE Id=:Id')
  Future<void> deleteById(int id);

@Query('SELECT * FROM Car')
  Stream<List<Car>?> getAllCars();
1 Answers

For some reason, the generated code in the DB.g.dart file does not notify the changeListener if you attempt to insert, modify or delete a record using SQL query statements. Thus, you should only use the @insert/update/delete methods for now, at least for version floor: ^1.2.0

Or, you can edit the DB.g.dart by adding changeListener.add('entity_name'); in every generated method that does changes in order to receive updates on your Stream. However, upon every regeneration of the DB.g.dart, you must remember to rewrite those edits again.

Related