I’m using Drift to manage databases in my flutter app and I need to get a list from a database. When I call for a list it just returns something called a "Instance of ‘_MappedSelectable<QueryRow, String>’"
This is the SQL command that returns this getAllNicks: SELECT nickname FROM car_entries;
I’ve tried to convert it to a list a few ways but they all just turn up in errors. Here is one way i tried (DIDN’T WORK)
List<String> convertInstanceToList(instance) {
Map<String, dynamic> map = Map.from(instance);
List<String> stringList = map.values.toList().cast<String>();
return stringList;
}
I was hoping this would convert it to a map and then turn that into a usable list but I just get this error.
Class '_MappedSelectable<QueryRow, String>' has no instance method 'toList'.
Receiver: Instance of '_MappedSelectable<QueryRow, String>'
Tried calling: toList()
Anyone got anything that might work?
2
Answers
Using a snapshot on the future also seems to work in some cases.
You need a Converter:
And you can use this converter in your table definition:
And a custom model:
In this way you will be able to use a String list anywhere in your code:
I hope this can help you.