Files
unionflow-mobile-apps/lib/shared/constants/payment_method_assets.dart
dahoud d094d6db9c Initial commit: unionflow-mobile-apps
Application Flutter complète (sans build artifacts).

Signed-off-by: lions dev Team
2026-03-15 16:30:08 +00:00

85 lines
2.8 KiB
Dart

/// Chemins des icônes (logos) des moyens de paiement pour listes déroulantes et composants.
///
/// Les assets sont dans [assets/images/payment_methods/{compagnie}/logo.svg] ou logo.png.
/// Utiliser [paymentMethodIconAssetSvg] / [paymentMethodIconAssetPng] ou le widget [PaymentMethodIcon].
library;
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
/// Base path des icônes de moyens de paiement.
const String kPaymentMethodIconsBase = 'assets/images/payment_methods';
/// Retourne le chemin du logo SVG pour un code (ex: WAVE_MONEY).
String? paymentMethodIconAssetSvg(String? code) => _pathFor(code, 'logo.svg');
/// Retourne le chemin du logo PNG pour un code.
String? paymentMethodIconAssetPng(String? code) => _pathFor(code, 'logo.png');
/// Retourne le chemin SVG (rétrocompatibilité).
String? paymentMethodIconAsset(String? code) => paymentMethodIconAssetSvg(code);
String? _pathFor(String? code, String filename) {
if (code == null || code.isEmpty) return null;
final path = _codeToPath[code.toUpperCase().trim()];
if (path != null) return '$kPaymentMethodIconsBase/$path/$filename';
return null;
}
/// Mapping code API → sous-dossier asset.
const Map<String, String> _codeToPath = {
'ESPECES': 'especes',
'VIREMENT': 'virement',
'CHEQUE': 'cheque',
'CARTE_BANCAIRE': 'carte_bancaire',
'WAVE_MONEY': 'wave',
'ORANGE_MONEY': 'orange_money',
'FREE_MONEY': 'free_money',
'MTN_MONEY': 'mtn_money',
'MOOV_MONEY': 'moov_money',
'MOBILE_MONEY': 'mobile_money',
'AUTRE': 'autre',
};
/// Liste des codes de méthode de paiement ayant une icône (pour itération).
List<String> get paymentMethodCodesWithIcon => _codeToPath.keys.toList();
/// Widget qui affiche le logo (PNG prioritaire, sinon SVG) pour une méthode de paiement.
class PaymentMethodIcon extends StatelessWidget {
final String? paymentMethodCode;
final double width;
final double height;
const PaymentMethodIcon({
super.key,
required this.paymentMethodCode,
this.width = 24,
this.height = 24,
});
@override
Widget build(BuildContext context) {
final pngPath = paymentMethodIconAssetPng(paymentMethodCode);
final svgPath = paymentMethodIconAssetSvg(paymentMethodCode);
if (pngPath == null && svgPath == null) return const SizedBox.shrink();
if (pngPath != null) {
return Image.asset(
pngPath,
width: width,
height: height,
fit: BoxFit.contain,
errorBuilder: (_, __, ___) {
if (svgPath != null) {
return SvgPicture.asset(svgPath, width: width, height: height);
}
return const SizedBox.shrink();
},
);
}
if (svgPath != null) {
return SvgPicture.asset(svgPath, width: width, height: height);
}
return const SizedBox.shrink();
}
}