Your error says that the method updateUserData() is receiving the Player class instead of a map().
In this case, you can create a method in UserData class, called UserData.toJson().
Supposing your Json should be like this:
{
"player": [
{
"name": "name",
"rol": "rol"
},
{
"name": "name",
"rol": "rol"
},
{
"name": "name",
"rol": "rol"
}
]
}
Your UserData and Player classes should be like this:
import 'dart:convert';
UserData userDataFromJson(String str) => UserData.fromJson(json.decode(str));
String userDataToJson(UserData data) => json.encode(data.toJson());
class UserData {
UserData({
this.player,
});
List<Player> player;
factory UserData.fromJson(Map<String, dynamic> json) => UserData(
player: List<Player>.from(json["player"].map((x) => Player.fromJson(x))),
);
Map<String, dynamic> toJson() => {
"player": List<dynamic>.from(player.map((x) => x.toJson())),
};
}
class Player {
Player({
this.name,
this.rol,
});
String name;
String rol;
factory Player.fromJson(Map<String, dynamic> json) => Player(
name: json["name"],
rol: json["rol"],
);
Map<String, dynamic> toJson() => {
"name": name,
"rol": rol,
};
}
Then in your function call:
...updateUserData(UserData.toJson());
This is a tool that can help you with your model classes in this case https://app.quicktype.io/