33 lines
730 B
Dart
33 lines
730 B
Dart
class Role {
|
|
// Proprietà della classe
|
|
final int id;
|
|
final String name;
|
|
final String description;
|
|
|
|
// Costruttore con parametri nominati e 'required'
|
|
Role({
|
|
required this.id,
|
|
required this.name,
|
|
required this.description,
|
|
});
|
|
|
|
// ---
|
|
|
|
/// Converte l'oggetto Role in una mappa per la serializzazione JSON.
|
|
Map<String, dynamic> toJson() {
|
|
return {
|
|
'id': id,
|
|
'name': name,
|
|
'description': description,
|
|
};
|
|
}
|
|
|
|
/// Crea un oggetto Role da una mappa (es. da una risposta JSON).
|
|
factory Role.fromJson(Map<String, dynamic> json) {
|
|
return Role(
|
|
id: json['id'] as int,
|
|
name: json['name'] as String,
|
|
description: json['description'] as String,
|
|
);
|
|
}
|
|
} |