onCreate: (db, version) {
// Run the CREATE TABLE statement on the database.
return db.execute(
'CREATE TABLE favourites(id STRING PRIMARY KEY, stop STRING, stop_name STRING, bus STRING)',
);
//id shall consist of both stop and bus numbers
},
This is a segment of my code I used to create the table.
Future<List<Favourite>> getFavourites() async {
// Get a reference to the database.
final db = await database();
// Query the table for all The Dogs.
final List<Map<String, dynamic>> maps = await db.query('favourites');
print('maps line 165: $maps');
// Convert the List<Map<String, dynamic> into a List<Dog>.
return List.generate(maps.length, (i) {
return Favourite(
id: maps[i]['id'],
stop: maps[i]['stop'],
stopName: maps[i]['stopName'],
bus: maps[i]['bus'],
);
});
}
This function above is what I used to retrieve my data. However I got this error instead. "Unhandled Exception: type 'int' is not a subtype of type 'String'". This means that the numbers that I had inserted into the table as String were converted to int. For example, stop = "09038" would be converted to 9038 as an int.
All my objects were in String.
String id = '0';
String stop = '0';
String stopName = '0';
String bus = '0';
Any solution to this?