When retrieving data from a Drift database using the .getSingle() method, if there is no row matching the search criterion, a StateError (Bad state: No element) error is thrown. Is this expected behavior?
Future<MyData> singleMyData(String id) {
return (select(myDatas)..where((t) => t.id.equals(id)))
.getSingle();
}
...
var singleData = await myDatabase.singleMyData("theId");
It means that the element is not in the database. Try this instead: