Refactor provider and store models to use fromMap method; update associated stores handling in UI
This commit is contained in:
@@ -11,6 +11,9 @@ class StoreModel extends Equatable {
|
||||
final String cap;
|
||||
final String comune;
|
||||
final String provincia;
|
||||
final int providersCount; // Numero di provider associati, utile per la lista
|
||||
final int
|
||||
staffMembersCount; // Numero di membri dello staff associati, utile per la lista
|
||||
|
||||
const StoreModel({
|
||||
this.id,
|
||||
@@ -23,6 +26,8 @@ class StoreModel extends Equatable {
|
||||
required this.cap,
|
||||
required this.comune,
|
||||
required this.provincia,
|
||||
this.providersCount = 0, // Default a 0 se non specificato
|
||||
this.staffMembersCount = 0, // Default a 0 se non specificato
|
||||
});
|
||||
|
||||
// Fondamentale per Equatable: definisce quali proprietà determinano l'uguaglianza
|
||||
@@ -38,6 +43,8 @@ class StoreModel extends Equatable {
|
||||
cap,
|
||||
comune,
|
||||
provincia,
|
||||
providersCount,
|
||||
staffMembersCount,
|
||||
];
|
||||
|
||||
// Il mitico copyWith per creare nuove istanze modificando solo ciò che serve
|
||||
@@ -52,6 +59,8 @@ class StoreModel extends Equatable {
|
||||
String? cap,
|
||||
String? comune,
|
||||
String? provincia,
|
||||
int? providersCount,
|
||||
int? staffMembersCount,
|
||||
}) {
|
||||
return StoreModel(
|
||||
id: id ?? this.id,
|
||||
@@ -64,27 +73,38 @@ class StoreModel extends Equatable {
|
||||
cap: cap ?? this.cap,
|
||||
comune: comune ?? this.comune,
|
||||
provincia: provincia ?? this.provincia,
|
||||
providersCount: providersCount ?? this.providersCount,
|
||||
staffMembersCount: staffMembersCount ?? this.staffMembersCount,
|
||||
);
|
||||
}
|
||||
|
||||
factory StoreModel.fromJson(Map<String, dynamic> json) {
|
||||
factory StoreModel.fromMap(Map<String, dynamic> map) {
|
||||
return StoreModel(
|
||||
id: json['id'] as String,
|
||||
nome: json['nome'],
|
||||
companyId: json['company_id'] as String,
|
||||
isActive: json['is_active'] ?? true,
|
||||
isPaid: json['is_paid'] ?? false,
|
||||
paymentExpiration: json['payment_expiration'] != null
|
||||
? DateTime.parse(json['payment_expiration'])
|
||||
id: map['id'] as String,
|
||||
nome: map['nome'],
|
||||
companyId: map['company_id'] as String,
|
||||
isActive: map['is_active'] ?? true,
|
||||
isPaid: map['is_paid'] ?? false,
|
||||
paymentExpiration: map['payment_expiration'] != null
|
||||
? DateTime.parse(map['payment_expiration'])
|
||||
: null,
|
||||
indirizzo: json['indirizzo'],
|
||||
cap: json['cap'],
|
||||
comune: json['comune'],
|
||||
provincia: json['provincia'],
|
||||
indirizzo: map['indirizzo'],
|
||||
cap: map['cap'],
|
||||
comune: map['comune'],
|
||||
provincia: map['provincia'],
|
||||
providersCount:
|
||||
map['providers_count'] != null && map['providers_count'].isNotEmpty
|
||||
? map['providers_count'][0]['count'] as int
|
||||
: 0,
|
||||
staffMembersCount:
|
||||
map['staff_members_count'] != null &&
|
||||
map['staff_members_count'].isNotEmpty
|
||||
? map['staff_members_count'][0]['count'] as int
|
||||
: 0,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
Map<String, dynamic> toMap() {
|
||||
return {
|
||||
if (id != null) 'id': id,
|
||||
'nome': nome,
|
||||
|
||||
Reference in New Issue
Block a user