Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error whe use where statement on flutter drift query

Tags:

flutter

drift

It's been several hours and I couldn't find a solution. I have multiple queries working fine with flutter drift, but when I add a where statement I get the following error:

Unhandled Exception: type '(dynamic) => dynamic' is not a subtype of type '(HasResultSet) => Expression' of 'filter'

The query is:

Future<dynamic> getById(int id) async {
  return await (db.select(table)..where((tbl) => tbl.id.equals(id))).getSingle();
}

If I remove ..where and add ..limit(1) the query runs fine:

Future<dynamic> getById(int id) async {
  return await (db.select(table)..limit(1)).getSingle();
}

Any clue?

like image 495
Iker Vázquez Avatar asked Mar 17 '26 03:03

Iker Vázquez


1 Answers

The problem seems that flutter can't infer the types, so I made the query with the requested ones:

Future<dynamic> getById(int id) async {
  return await (db.select(table)..where((HasResultSet tbl) => table.id.equals(id) as Expression<bool>)).getSingle();
}

And now it's working fine.

like image 132
Iker Vázquez Avatar answered Mar 19 '26 20:03

Iker Vázquez