Initial commit du projet Flutter

This commit is contained in:
2025-12-01 10:56:37 +01:00
commit 8a728a612e
162 changed files with 33799 additions and 0 deletions

View File

@@ -0,0 +1,328 @@
// lib/widgets/balance_widget.dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../main.dart';
import '../services/wortis_api_service.dart';
class BalanceWidget extends StatefulWidget {
final bool showIcon;
final bool compact;
final Color? textColor;
final Color? backgroundColor;
const BalanceWidget({
super.key,
this.showIcon = true,
this.compact = false,
this.textColor,
this.backgroundColor,
});
@override
_BalanceWidgetState createState() => _BalanceWidgetState();
}
class _BalanceWidgetState extends State<BalanceWidget> {
bool _isRefreshing = false;
DateTime _lastRefresh = DateTime.now();
@override
void initState() {
super.initState();
// Rafraîchir le solde au démarrage
WidgetsBinding.instance.addPostFrameCallback((_) {
_refreshBalance();
});
}
Future<void> _refreshBalance() async {
final authController = Provider.of<AuthController>(context, listen: false);
final agentId = authController.agentId;
if (agentId == null || _isRefreshing) return;
setState(() {
_isRefreshing = true;
});
try {
// Test de connexion API d'abord
final isConnected = await AuthApiService.testConnection();
if (isConnected) {
final response = await AuthApiService.getAgentBalance(agentId);
if (response['success'] == true && mounted) {
final nouveauSolde = (response['solde'] ?? 0.0).toDouble();
authController.updateBalance(nouveauSolde);
setState(() {
_lastRefresh = DateTime.now();
});
// Afficher un message si le solde a changé significativement
final ancienSolde = authController.balance;
if ((nouveauSolde - ancienSolde).abs() > 100) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
Icon(Icons.refresh, color: Colors.white, size: 16),
SizedBox(width: 8),
Text(
'Solde mis à jour: ${nouveauSolde.toStringAsFixed(0)} XAF',
),
],
),
backgroundColor: Colors.green,
duration: Duration(seconds: 2),
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
);
}
}
}
} catch (e) {
print('Erreur rafraîchissement solde: $e');
} finally {
if (mounted) {
setState(() {
_isRefreshing = false;
});
}
}
}
String _getTimeAgo() {
final now = DateTime.now();
final difference = now.difference(_lastRefresh);
if (difference.inMinutes < 1) {
return 'À l\'instant';
} else if (difference.inMinutes < 60) {
return 'Il y a ${difference.inMinutes}min';
} else {
return 'Il y a ${difference.inHours}h';
}
}
@override
Widget build(BuildContext context) {
return Consumer<AuthController>(
builder: (context, authController, child) {
// Utiliser le solde actif (entreprise ou personnel selon le type de compte)
final solde = authController.activeBalance;
final isEnterprise = authController.isEnterpriseMember;
final textColor = widget.textColor ?? Colors.white;
if (widget.compact) {
return GestureDetector(
onTap: _refreshBalance,
child: Container(
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: widget.backgroundColor ?? Colors.white.withOpacity(0.2),
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: (widget.backgroundColor ?? Colors.white).withOpacity(
0.3,
),
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (widget.showIcon) ...[
Icon(
isEnterprise ? Icons.business_center : Icons.account_balance_wallet,
color: textColor,
size: 14,
),
SizedBox(width: 6),
],
if (_isRefreshing)
SizedBox(
width: 12,
height: 12,
child: CircularProgressIndicator(
strokeWidth: 1.5,
valueColor: AlwaysStoppedAnimation<Color>(textColor),
),
)
else
Text(
'${solde.toStringAsFixed(0)} XAF',
style: TextStyle(
color: textColor,
fontSize: 12,
fontWeight: FontWeight.w600,
),
),
],
),
),
);
}
// Version étendue
final enterpriseColor = Color(0xFF8B5CF6);
final displayColor = isEnterprise ? enterpriseColor : Color(0xFF006699);
return Container(
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: widget.backgroundColor ?? Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
blurRadius: 10,
offset: Offset(0, 4),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(
isEnterprise ? Icons.business_center : Icons.account_balance_wallet,
color: displayColor,
size: 24,
),
SizedBox(width: 8),
Flexible(
child: Text(
isEnterprise ? 'Solde entreprise' : 'Solde disponible',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.black87,
),
overflow: TextOverflow.ellipsis,
),
),
],
),
if (isEnterprise && authController.enterprise?.nomEntreprise != null) ...[
SizedBox(height: 4),
Text(
authController.enterprise!.nomEntreprise,
style: TextStyle(
fontSize: 12,
color: Colors.grey[600],
),
overflow: TextOverflow.ellipsis,
),
],
],
),
),
GestureDetector(
onTap: _isRefreshing ? null : _refreshBalance,
child: Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
color: displayColor.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
),
child:
_isRefreshing
? SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(displayColor),
),
)
: Icon(
Icons.refresh,
color: displayColor,
size: 16,
),
),
),
],
),
SizedBox(height: 12),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Flexible(
child: Text(
solde.toStringAsFixed(0),
style: TextStyle(
fontSize: 32,
fontWeight: FontWeight.bold,
color: displayColor,
),
overflow: TextOverflow.ellipsis,
),
),
SizedBox(width: 8),
Padding(
padding: EdgeInsets.only(bottom: 4),
child: Text(
'XAF',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.grey[600],
),
),
),
],
),
SizedBox(height: 8),
Row(
children: [
Expanded(
child: Text(
'Dernière mise à jour: ${_getTimeAgo()}',
style: TextStyle(fontSize: 12, color: Colors.grey[500]),
),
),
if (isEnterprise)
Container(
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: enterpriseColor.withOpacity(0.1),
borderRadius: BorderRadius.circular(12),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.business, size: 10, color: enterpriseColor),
SizedBox(width: 4),
Text(
'PRO',
style: TextStyle(
fontSize: 10,
color: enterpriseColor,
fontWeight: FontWeight.bold,
),
),
],
),
),
],
),
],
),
);
},
);
}
}

View File

View File

@@ -0,0 +1,484 @@
// widgets/pin_verification_dialog.dart - Version mise à jour
import 'package:flutter/material.dart';
import 'package:intl/intl.dart';
class PinVerificationDialog extends StatefulWidget {
final String agentName;
final String serviceName;
final double baseAmount;
final double fees;
final double totalAmount;
final double agentBalance; // Nouveau paramètre
final Function(String) onPinConfirmed;
final VoidCallback onCancel;
const PinVerificationDialog({
super.key,
required this.agentName,
required this.serviceName,
required this.baseAmount,
required this.fees,
required this.totalAmount,
required this.agentBalance, // Nouveau paramètre requis
required this.onPinConfirmed,
required this.onCancel,
});
@override
_PinVerificationDialogState createState() => _PinVerificationDialogState();
}
class _PinVerificationDialogState extends State<PinVerificationDialog> {
final TextEditingController _pinController = TextEditingController();
bool _isObscured = true;
bool _isLoading = false;
String? _errorMessage;
// Formatter pour les montants
String _formatAmount(double amount) {
final formatter = NumberFormat('#,###', 'fr_FR');
return formatter.format(amount);
}
// Vérifier si l'agent a suffisamment de solde
bool get _hasSufficientBalance {
return widget.agentBalance >= widget.totalAmount;
}
@override
void dispose() {
_pinController.dispose();
super.dispose();
}
Future<void> _handlePinConfirmation() async {
if (_pinController.text.length < 4) {
setState(() {
_errorMessage = 'Le PIN doit contenir au moins 4 chiffres';
});
return;
}
if (!_hasSufficientBalance) {
setState(() {
_errorMessage = 'Solde insuffisant pour effectuer cette transaction';
});
return;
}
setState(() {
_isLoading = true;
_errorMessage = null;
});
try {
// Simuler une vérification (remplacez par votre logique de vérification)
await Future.delayed(const Duration(seconds: 1));
widget.onPinConfirmed(_pinController.text);
} catch (e) {
setState(() {
_errorMessage = 'Erreur lors de la vérification du PIN';
_isLoading = false;
});
}
}
@override
Widget build(BuildContext context) {
final size = MediaQuery.of(context).size;
final isSmallScreen = size.width < 360;
return Dialog(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
elevation: 0,
backgroundColor: Colors.transparent,
child: Container(
constraints: BoxConstraints(
maxWidth: size.width * 0.9,
maxHeight: size.height * 0.8,
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.1),
spreadRadius: 0,
blurRadius: 10,
offset: const Offset(0, 4),
),
],
),
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.all(isSmallScreen ? 16 : 24),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
// En-tête avec icône de sécurité
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: const Color(0xFF006699).withOpacity(0.1),
shape: BoxShape.circle,
),
child: const Icon(
Icons.security,
size: 32,
color: Color(0xFF006699),
),
),
const SizedBox(height: 16),
// Titre
Text(
'Confirmation sécurisée',
style: TextStyle(
fontSize: isSmallScreen ? 20 : 24,
fontWeight: FontWeight.bold,
color: Colors.black87,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 8),
Text(
'Vérifiez les détails et confirmez avec votre PIN',
style: TextStyle(
fontSize: isSmallScreen ? 14 : 16,
color: Colors.black54,
),
textAlign: TextAlign.center,
),
const SizedBox(height: 24),
// Informations de la transaction
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.grey[50],
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.grey[200]!),
),
child: Column(
children: [
// Service
_buildDetailRow(
icon: Icons.business_center,
label: 'Service',
value: widget.serviceName,
isSmallScreen: isSmallScreen,
),
if (widget.baseAmount > 0) ...[
const SizedBox(height: 12),
_buildDetailRow(
icon: Icons.account_balance_wallet,
label: 'Montant à payer',
value: '${_formatAmount(widget.baseAmount)} FCFA',
isSmallScreen: isSmallScreen,
),
],
if (widget.fees > 0) ...[
const SizedBox(height: 12),
_buildDetailRow(
icon: Icons.receipt_long,
label: 'Frais',
value: '${_formatAmount(widget.fees)} FCFA',
isSmallScreen: isSmallScreen,
),
],
const SizedBox(height: 12),
Divider(color: Colors.grey[300]),
const SizedBox(height: 12),
// Total
_buildDetailRow(
icon: Icons.payments,
label: 'Total',
value: '${_formatAmount(widget.totalAmount)} FCFA',
isTotal: true,
isSmallScreen: isSmallScreen,
),
const SizedBox(height: 16),
// Solde agent avec indicateur de suffisance
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color:
_hasSufficientBalance
? Colors.green[50]
: Colors.red[50],
borderRadius: BorderRadius.circular(8),
border: Border.all(
color:
_hasSufficientBalance
? Colors.green[200]!
: Colors.red[200]!,
),
),
child: Row(
children: [
Icon(
_hasSufficientBalance
? Icons.check_circle
: Icons.warning,
color:
_hasSufficientBalance
? Colors.green[600]
: Colors.red[600],
size: 20,
),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Votre solde',
style: TextStyle(
fontSize: 12,
color: Colors.grey[600],
fontWeight: FontWeight.w500,
),
),
Text(
'${_formatAmount(widget.agentBalance)} FCFA',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
color:
_hasSufficientBalance
? Colors.green[700]
: Colors.red[700],
),
),
if (!_hasSufficientBalance)
Text(
'Solde insuffisant',
style: TextStyle(
fontSize: 12,
color: Colors.red[600],
fontStyle: FontStyle.italic,
),
),
],
),
),
],
),
),
],
),
),
const SizedBox(height: 24),
// Champ PIN
Text(
'PIN de sécurité',
style: TextStyle(
fontSize: isSmallScreen ? 14 : 16,
fontWeight: FontWeight.w600,
color: Colors.black87,
),
),
const SizedBox(height: 8),
TextField(
controller: _pinController,
keyboardType: TextInputType.number,
obscureText: _isObscured,
maxLength: 6,
enabled: !_isLoading && _hasSufficientBalance,
decoration: InputDecoration(
hintText: 'Saisissez votre PIN',
prefixIcon: const Icon(
Icons.lock,
color: Color(0xFF006699),
),
suffixIcon: IconButton(
icon: Icon(
_isObscured ? Icons.visibility : Icons.visibility_off,
color: Colors.grey,
),
onPressed: () {
setState(() {
_isObscured = !_isObscured;
});
},
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: Color(0xFFE0E7FF)),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: Color(0xFFE0E7FF)),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(
color: Color(0xFF006699),
width: 2,
),
),
counterText: '',
),
onSubmitted:
_hasSufficientBalance
? (_) => _handlePinConfirmation()
: null,
),
if (_errorMessage != null) ...[
const SizedBox(height: 8),
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.red[50],
borderRadius: BorderRadius.circular(8),
border: Border.all(color: Colors.red[200]!),
),
child: Row(
children: [
Icon(
Icons.error_outline,
color: Colors.red[600],
size: 16,
),
const SizedBox(width: 8),
Expanded(
child: Text(
_errorMessage!,
style: TextStyle(
color: Colors.red[600],
fontSize: 12,
),
),
),
],
),
),
],
const SizedBox(height: 24),
// Boutons
Row(
children: [
Expanded(
child: TextButton(
onPressed: _isLoading ? null : widget.onCancel,
style: TextButton.styleFrom(
padding: EdgeInsets.symmetric(
vertical: isSmallScreen ? 12 : 16,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child: Text(
'Annuler',
style: TextStyle(
fontSize: isSmallScreen ? 14 : 16,
color: Colors.grey[600],
),
),
),
),
const SizedBox(width: 12),
Expanded(
child: ElevatedButton(
onPressed:
(_isLoading || !_hasSufficientBalance)
? null
: _handlePinConfirmation,
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF006699),
foregroundColor: Colors.white,
padding: EdgeInsets.symmetric(
vertical: isSmallScreen ? 12 : 16,
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
elevation: 0,
),
child:
_isLoading
? SizedBox(
height: isSmallScreen ? 16 : 20,
width: isSmallScreen ? 16 : 20,
child: const CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(
Colors.white,
),
),
)
: Text(
'CONFIRMER',
style: TextStyle(
fontSize: isSmallScreen ? 14 : 16,
fontWeight: FontWeight.w600,
),
),
),
),
],
),
],
),
),
),
),
);
}
Widget _buildDetailRow({
required IconData icon,
required String label,
required String value,
bool isTotal = false,
required bool isSmallScreen,
}) {
return Row(
children: [
Icon(
icon,
size: isSmallScreen ? 16 : 18,
color: isTotal ? const Color(0xFF006699) : Colors.grey[600],
),
const SizedBox(width: 8),
Expanded(
child: Text(
label,
style: TextStyle(
fontSize: isSmallScreen ? 13 : 14,
fontWeight: isTotal ? FontWeight.w600 : FontWeight.w500,
color: isTotal ? const Color(0xFF006699) : Colors.grey[700],
),
),
),
Text(
value,
style: TextStyle(
fontSize: isSmallScreen ? 13 : 14,
fontWeight: isTotal ? FontWeight.bold : FontWeight.w600,
color: isTotal ? const Color(0xFF006699) : Colors.black87,
),
),
],
);
}
}

View File

@@ -0,0 +1,377 @@
// ===== lib/utils/responsive_helper.dart =====
// Système de responsivité centralisé pour tablettes et rotation
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'dart:math' as math;
/// Gestionnaire principal de la responsivité et rotation
class ResponsiveHelper {
// =================== CONSTANTES DE BREAKPOINTS ===================
/// Breakpoints pour différentes tailles d'écran
static const double phoneMaxWidth = 400;
static const double tabletMinWidth = 600;
static const double desktopMinWidth = 1024;
/// Hauteurs critiques pour détection d'orientation
static const double portraitMinHeight = 600;
static const double landscapeMaxHeight = 500;
// =================== DÉTECTION DE TYPE D'APPAREIL ===================
/// Détermine si c'est un petit téléphone
static bool isSmallPhone(BuildContext context) {
return MediaQuery.of(context).size.width < phoneMaxWidth;
}
/// Détermine si c'est un téléphone standard
static bool isPhone(BuildContext context) {
return MediaQuery.of(context).size.width < tabletMinWidth;
}
/// Détermine si c'est une tablette
static bool isTablet(BuildContext context) {
final width = MediaQuery.of(context).size.width;
return width >= tabletMinWidth && width < desktopMinWidth;
}
/// Détermine si c'est un grand écran/desktop
static bool isDesktop(BuildContext context) {
return MediaQuery.of(context).size.width >= desktopMinWidth;
}
// =================== DÉTECTION D'ORIENTATION ===================
/// Détection précise de l'orientation
static bool isPortrait(BuildContext context) {
final size = MediaQuery.of(context).size;
return size.height > size.width;
}
/// Détection du mode paysage
static bool isLandscape(BuildContext context) {
final size = MediaQuery.of(context).size;
return size.width > size.height;
}
/// Détection spéciale pour tablette en mode paysage
static bool isTabletLandscape(BuildContext context) {
return isTablet(context) && isLandscape(context);
}
/// Détection spéciale pour téléphone en mode paysage
static bool isPhoneLandscape(BuildContext context) {
return isPhone(context) && isLandscape(context);
}
// =================== CONFIGURATION D'ORIENTATION ===================
/// Force l'orientation portrait et paysage pour tablettes
static void enableAllOrientations() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}
/// Force uniquement le mode portrait (pour certains écrans si nécessaire)
static void enablePortraitOnly() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
}
/// Force uniquement le mode paysage
static void enableLandscapeOnly() {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
DeviceOrientation.landscapeRight,
]);
}
// =================== DIMENSIONS RESPONSIVES ===================
/// Obtient la largeur responsive selon l'appareil
static double getResponsiveWidth(BuildContext context, {
double? phone,
double? tablet,
double? desktop,
}) {
if (isDesktop(context)) return desktop ?? tablet ?? phone ?? 0;
if (isTablet(context)) return tablet ?? phone ?? 0;
return phone ?? 0;
}
/// Obtient la hauteur responsive selon l'appareil
static double getResponsiveHeight(BuildContext context, {
double? phone,
double? tablet,
double? desktop,
}) {
if (isDesktop(context)) return desktop ?? tablet ?? phone ?? 0;
if (isTablet(context)) return tablet ?? phone ?? 0;
return phone ?? 0;
}
/// Padding responsive adaptatif
static EdgeInsets getResponsivePadding(BuildContext context, {
EdgeInsets? phone,
EdgeInsets? tablet,
EdgeInsets? desktop,
}) {
if (isDesktop(context)) return desktop ?? tablet ?? phone ?? EdgeInsets.zero;
if (isTablet(context)) return tablet ?? phone ?? EdgeInsets.zero;
return phone ?? EdgeInsets.zero;
}
/// Taille de police responsive
static double getResponsiveFontSize(BuildContext context, {
double? phone,
double? tablet,
double? desktop,
}) {
if (isDesktop(context)) return desktop ?? tablet ?? phone ?? 14;
if (isTablet(context)) return tablet ?? phone ?? 14;
return phone ?? 14;
}
// =================== GRILLES RESPONSIVES ===================
/// Nombre de colonnes selon la taille d'écran
static int getGridColumns(BuildContext context, {
int phoneColumns = 2,
int tabletPortraitColumns = 3,
int tabletLandscapeColumns = 4,
int desktopColumns = 5,
}) {
if (isDesktop(context)) return desktopColumns;
if (isTabletLandscape(context)) return tabletLandscapeColumns;
if (isTablet(context)) return tabletPortraitColumns;
return phoneColumns;
}
/// Ratio d'aspect adaptatif pour les cartes
static double getCardAspectRatio(BuildContext context) {
if (isPhoneLandscape(context)) return 2.5;
if (isTabletLandscape(context)) return 1.8;
if (isTablet(context)) return 1.4;
return 1.2; // Portrait par défaut
}
// =================== WIDGETS RESPONSIVES ===================
/// Container responsive avec padding adaptatif
static Widget responsiveContainer({
required BuildContext context,
required Widget child,
EdgeInsets? phonePadding,
EdgeInsets? tabletPadding,
EdgeInsets? desktopPadding,
Color? backgroundColor,
BorderRadius? borderRadius,
}) {
return Container(
padding: getResponsivePadding(
context,
phone: phonePadding ?? const EdgeInsets.all(16),
tablet: tabletPadding ?? const EdgeInsets.all(24),
desktop: desktopPadding ?? const EdgeInsets.all(32),
),
decoration: BoxDecoration(
color: backgroundColor,
borderRadius: borderRadius ?? BorderRadius.circular(12),
),
child: child,
);
}
/// Texte responsive avec tailles adaptatives
static Widget responsiveText(
String text, {
required BuildContext context,
double? phoneSize,
double? tabletSize,
double? desktopSize,
FontWeight? fontWeight,
Color? color,
TextAlign? textAlign,
int? maxLines,
TextOverflow? overflow,
}) {
return Text(
text,
style: TextStyle(
fontSize: getResponsiveFontSize(
context,
phone: phoneSize ?? 14,
tablet: tabletSize ?? 16,
desktop: desktopSize ?? 18,
),
fontWeight: fontWeight,
color: color,
),
textAlign: textAlign,
maxLines: maxLines,
overflow: overflow,
);
}
// =================== LAYOUTS RESPONSIVES ===================
/// Layout responsive en colonnes
static Widget responsiveRow({
required BuildContext context,
required List<Widget> children,
MainAxisAlignment mainAxisAlignment = MainAxisAlignment.start,
CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
bool forceColumnOnPhone = true,
}) {
if (forceColumnOnPhone && isPhone(context)) {
return Column(
mainAxisAlignment: mainAxisAlignment,
crossAxisAlignment: crossAxisAlignment,
children: children,
);
}
return Row(
mainAxisAlignment: mainAxisAlignment,
crossAxisAlignment: crossAxisAlignment,
children: children,
);
}
/// GridView responsive adaptatif
static Widget responsiveGridView({
required BuildContext context,
required List<Widget> children,
int? phoneColumns,
int? tabletPortraitColumns,
int? tabletLandscapeColumns,
int? desktopColumns,
double childAspectRatio = 1.0,
double crossAxisSpacing = 8.0,
double mainAxisSpacing = 8.0,
EdgeInsets? padding,
ScrollPhysics? physics,
}) {
final columns = getGridColumns(
context,
phoneColumns: phoneColumns ?? 2,
tabletPortraitColumns: tabletPortraitColumns ?? 3,
tabletLandscapeColumns: tabletLandscapeColumns ?? 4,
desktopColumns: desktopColumns ?? 5,
);
return GridView.count(
shrinkWrap: true,
physics: physics ?? const NeverScrollableScrollPhysics(),
crossAxisCount: columns,
childAspectRatio: childAspectRatio,
crossAxisSpacing: crossAxisSpacing,
mainAxisSpacing: mainAxisSpacing,
padding: padding ?? getResponsivePadding(
context,
phone: const EdgeInsets.all(16),
tablet: const EdgeInsets.all(24),
),
children: children,
);
}
// =================== NAVIGATION RESPONSIVE ===================
/// Détermine si on doit utiliser un Drawer ou une BottomNavigationBar
static bool shouldUseDrawer(BuildContext context) {
return isTabletLandscape(context) || isDesktop(context);
}
/// Détermine si on doit utiliser une navigation rail (côté gauche)
static bool shouldUseNavigationRail(BuildContext context) {
return isTabletLandscape(context) || isDesktop(context);
}
// =================== ORIENTATIONS SPÉCIFIQUES ===================
/// Initialise les orientations selon l'appareil
static void initializeOrientations(BuildContext context) {
if (isTablet(context) || isDesktop(context)) {
enableAllOrientations();
} else {
// Pour les téléphones, on peut choisir de limiter ou non
enableAllOrientations(); // Ou enablePortraitOnly() selon les besoins
}
}
// =================== UTILITAIRES DIVERS ===================
/// Obtient la largeur maximale recommandée pour le contenu
static double getMaxContentWidth(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
if (isDesktop(context)) {
return math.min(screenWidth * 0.8, 1200); // Max 1200px sur desktop
} else if (isTablet(context)) {
return screenWidth * 0.9; // 90% sur tablette
}
return screenWidth; // 100% sur téléphone
}
/// Centre le contenu avec une largeur maximale
static Widget centerContent({
required BuildContext context,
required Widget child,
double? maxWidth,
}) {
return Center(
child: ConstrainedBox(
constraints: BoxConstraints(
maxWidth: maxWidth ?? getMaxContentWidth(context),
),
child: child,
),
);
}
/// Détermine l'espacement entre les éléments
static double getSpacing(BuildContext context, {
double? small,
double? medium,
double? large,
}) {
if (isDesktop(context)) return large ?? 24;
if (isTablet(context)) return medium ?? 16;
return small ?? 12;
}
}
// =================== EXTENSION POUR MEDIAQUERY ===================
/// Extension pour simplifier l'utilisation de ResponsiveHelper
extension ResponsiveExtension on BuildContext {
bool get isSmallPhone => ResponsiveHelper.isSmallPhone(this);
bool get isPhone => ResponsiveHelper.isPhone(this);
bool get isTablet => ResponsiveHelper.isTablet(this);
bool get isDesktop => ResponsiveHelper.isDesktop(this);
bool get isPortrait => ResponsiveHelper.isPortrait(this);
bool get isLandscape => ResponsiveHelper.isLandscape(this);
bool get isTabletLandscape => ResponsiveHelper.isTabletLandscape(this);
bool get isPhoneLandscape => ResponsiveHelper.isPhoneLandscape(this);
double responsiveWidth({double? phone, double? tablet, double? desktop}) =>
ResponsiveHelper.getResponsiveWidth(this, phone: phone, tablet: tablet, desktop: desktop);
double responsiveHeight({double? phone, double? tablet, double? desktop}) =>
ResponsiveHelper.getResponsiveHeight(this, phone: phone, tablet: tablet, desktop: desktop);
double responsiveFontSize({double? phone, double? tablet, double? desktop}) =>
ResponsiveHelper.getResponsiveFontSize(this, phone: phone, tablet: tablet, desktop: desktop);
EdgeInsets responsivePadding({EdgeInsets? phone, EdgeInsets? tablet, EdgeInsets? desktop}) =>
ResponsiveHelper.getResponsivePadding(this, phone: phone, tablet: tablet, desktop: desktop);
}

View File

@@ -0,0 +1,108 @@
// ===== lib/widgets/wortis_logo.dart FONCTIONNEL =====
import 'package:flutter/material.dart';
class WortisLogoWidget extends StatelessWidget {
final double size;
final bool isWhite;
final bool withShadow;
final String? customPath;
const WortisLogoWidget({
super.key,
this.size = 100,
this.isWhite = false,
this.withShadow = true,
this.customPath,
});
@override
Widget build(BuildContext context) {
// Utilise exactement vos noms de fichiers
String logoPath =
customPath ??
(isWhite
? 'assets/images/wortis_logo_white.png'
: 'assets/images/wortis_logo.png');
return Container(
width: size,
height: size,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(size * 0.15),
boxShadow:
withShadow
? [
BoxShadow(
color: Colors.black.withOpacity(0.2),
blurRadius: size * 0.1,
offset: Offset(0, size * 0.05),
spreadRadius: 1,
),
]
: null,
),
child: ClipRRect(
borderRadius: BorderRadius.circular(size * 0.15),
child: Image.asset(
logoPath,
width: size,
height: size,
fit: BoxFit.contain,
errorBuilder: (context, error, stackTrace) {
// Debug : Afficher l'erreur pour diagnostiquer
print('Erreur chargement logo: $error');
print('Chemin tenté: $logoPath');
// Fallback avec le "W" stylisé
return Container(
width: size,
height: size,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Color(0xFF006699), Color(0xFF0088CC)],
),
borderRadius: BorderRadius.circular(size * 0.15),
boxShadow:
withShadow
? [
BoxShadow(
color: Color(0xFF006699).withOpacity(0.3),
blurRadius: size * 0.15,
offset: Offset(0, size * 0.08),
),
]
: null,
),
);
},
),
),
);
}
}
/*
DIAGNOSTIC : Si les images ne s'affichent toujours pas, vérifiez :
1. pubspec.yaml contient bien :
flutter:
assets:
- assets/images/
2. Redémarrez l'app complètement (hot restart, pas hot reload)
3. Dans votre terminal, exécutez :
flutter clean
flutter pub get
flutter run
4. Vérifiez que les images sont bien au format PNG/JPG valide
5. Si ça ne marche toujours pas, essayez de renommer temporairement
vos fichiers en :
- logo1.png
- logo2.png
Et modifiez les chemins dans le code pour tester.
*/