tekartik / sqflite

SQLite flutter plugin
BSD 2-Clause "Simplified" License
2.88k stars 527 forks source link

Cursor closed despite moveNext() returning true #1113

Open Erfa opened 5 months ago

Erfa commented 5 months ago

I've seen this for a long time and it seems strange. I have something simple like this:

final isOpen = await cursor.moveNext();

if (isOpen) {
    final row = cursor.current;
    // Do something with row
}

I often see that accessing the current row fails with StateError: Cursor is closed, cannot get current row. Seems to happen more often if I have a query in a parent page that exists while I navigate into a child page in Flutter.

How is this possible? Isn't the entire point of the return value from moveNext() to say that it's safe to access current?

alextekartik commented 5 months ago

Indeed that should not happen. Hard to say without seeing more code as I cannot manage to reproduce. Do you have a way to reproduce in a simple example?