since a few days ago there was a flutter update my code shows the following error:
_TypeError (type 'String' is not a subtype of type 'int')
Obviously the application worked perfectly before this update, even after changing from "int" to "String" the same error I get but the other way around:
_TypeError (type 'int' is not a subtype of type 'String')
As much as I change the values the same error still appears to me, it is also clear that the RestApi that I am using did not have any changes.
I get the error when I get to "Chip", after I change it to String I get the same error in "Number", and after I change both the same error appears but the other way around as I indicated above
Here the Json file model:
class EventoModel {
String id;
String nombreEvento;
List<Participantes> participantes;
EventoModel({
this.id,
this.nombreEvento,
this.participantes
});
factory EventoModel.fromJson(Map<String, dynamic> parsedJson){
var list = parsedJson['participantes'] as List;
//print(list.runtimeType);
List<Participantes> participantesList = list.map((i) => Participantes.fromJson(i)).toList();
return EventoModel(
id : parsedJson ['id'],
nombreEvento : parsedJson ['nombreEvento'],
participantes : participantesList
);
}
}
class Participantes {
String uniqueId;
String apellido;
int chip;
String nombre;
int numero;
String place;
String tiempo;
Participantes({
this.apellido,
this.chip,
this.nombre,
this.numero,
this.place,
this.tiempo,
});
factory Participantes.fromJson(Map<String, dynamic> parsedJson) {
//print(list.runtimeType);
return Participantes(
apellido : parsedJson['Apellido'],
chip : parsedJson['Chip'],
nombre : parsedJson['Nombre'],
numero : parsedJson['Numero'],
place : parsedJson['Place'],
tiempo : parsedJson['Tiempo'],
);
}
Map<String, dynamic> toJson() {
return {
'Apellido' : apellido,
'Chip' : chip,
'Nombre' : nombre,
'Numero' : numero,
'Place' : place,
'Tiempo' : tiempo,
};
}
}
This is the Json file Example:
{
"nombreEvento" : "Clasico El Colombiano 2020",
"participantes" : [ {
"Apellido" : "MARTINEZ GUTIERREZ",
"Chip" : "739",
"Nombre" : "JOSE",
"Numero" : "139",
"Place" : "1.",
"Tiempo" : "00:30:12,91"
}, {
"Apellido" : "SUAREZ MORERA",
"Chip" : "707",
"Nombre" : "DANIEL",
"Numero" : "107",
"Place" : "2.",
"Tiempo" : "02:00:17,54"
}, {
"Apellido" : "RODRIGUEZ VARGAS",
"Chip" : "1686",
"Nombre" : "JOSE LUIS",
"Numero" : "274",
"Place" : "3.",
"Tiempo" : "02:01:09,09"
}
]
}
Could someone please help me?
If the type of a variable is not explicitly specified, the variable’s type is dynamic. The dynamic keyword can also be used as a type annotation explicitly.
Instead of int you can use dynamic and it will solve the issue.
class Participantes {
String uniqueId;
String apellido;
dynamic chip;
String nombre;
dynamic numero;
String place;
String tiempo;
Participantes({
this.apellido,
this.chip,
this.nombre,
this.numero,
this.place,
this.tiempo,
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With