Files
app_fideliter/lib/models/client.dart
T
Mathew 1d3ee69c6d Initial commit — app fidélité magasin (tablette)
App Flutter de programme de fidélité : login staff, clients (nom/prénom),
scan QR, factures (€→points), récompenses, réglages. Backend Supabase
(schéma SQL + RLS anti-triche dans supabase/). Icône incluse.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-17 21:37:06 +02:00

69 lines
1.8 KiB
Dart

/// Un client fidélité. Le [code] est ce qui est encodé dans son QR code :
/// scanner le QR permet de retrouver le compte.
class Client {
final String id; // uuid Supabase
/// Code unique du compte (encodé dans le QR), ex : « FID-3F9K2A ».
final String code;
final String nom;
final String? prenom;
final String? telephone;
/// Solde de points courant (peut être fractionnaire, ex : 12,48).
final double points;
const Client({
required this.id,
required this.code,
required this.nom,
this.prenom,
this.telephone,
this.points = 0,
});
/// Nom complet affiché : « Prénom Nom » (ou juste le nom si pas de prénom).
String get nomComplet {
final p = (prenom ?? '').trim();
return p.isEmpty ? nom : '$p $nom';
}
/// Initiales pour l'avatar (ex : « Jean Dupont » → « JD »).
String get initiales {
final p = (prenom ?? '').trim();
final n = nom.trim();
final a = p.isNotEmpty ? p[0] : (n.isNotEmpty ? n[0] : '?');
final b = n.isNotEmpty ? n[0] : '';
return (a + b).toUpperCase();
}
Client copyWith({
String? id,
String? code,
String? nom,
String? prenom,
String? telephone,
double? points,
}) {
return Client(
id: id ?? this.id,
code: code ?? this.code,
nom: nom ?? this.nom,
prenom: prenom ?? this.prenom,
telephone: telephone ?? this.telephone,
points: points ?? this.points,
);
}
factory Client.fromMap(Map<String, dynamic> map) {
return Client(
id: map['id'].toString(),
code: (map['code'] as String?) ?? '',
nom: (map['nom'] as String?) ?? '',
prenom: map['prenom'] as String?,
telephone: map['telephone'] as String?,
points: (map['points'] as num?)?.toDouble() ?? 0,
);
}
}