I have an error when I tried to run de future: DB_helper().fetchData(),
Future<List<Scale>>fetchData() async {
final Database db = await _initDatabase();
final List<Map<String, dynamic>> queryResult = await db.query(table);
//inspect(queryResult);
return queryResult.map((e) => Scale).toList(); //error
}
CodePudding user response:
In here
return queryResult.map((e) => Scale).toList();
You are returning the type Scale
instead of the Scale data.
it should be something like this
return queryResult.map((e) => Scale.fromMap(e)).toList();
CodePudding user response:
Code Scale
Maybe I need to change something in toMap() line?
class Scale {
int id;
String codigo,
ubicacion,
capacidad,
resolucion,
unidades,
marca,
modelo,
serie;
Scale({
required this.id,
required this.codigo,
required this.ubicacion,
required this.capacidad,
required this.resolucion,
required this.unidades,
required this.marca,
required this.modelo,
required this.serie,
});
Map<String, dynamic> toMap() {
return {
'id': id,
'codigo': codigo,
'ubicacion': ubicacion,
'capacidad': capacidad,
'resolucion': resolucion,
'unidades': unidades,
'marca': marca,
'modelo': modelo,
'serie': serie,
};
}
@override
String toString() {
return 'Scale{id: $id, codigo: $codigo, ubicacion: $ubicacion, capacidad: $capacidad, resolucion: $resolucion, unidades: $unidades, marca: $marca, modelo: $modelo, serie: $serie}';
}
static fromMap(e) {}
}