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

File diff suppressed because it is too large Load Diff

840
lib/pages/class.dart Normal file
View File

@@ -0,0 +1,840 @@
// lib/class/class.dart
import 'package:flutter/material.dart';
/// Gestionnaire de connectivité
class ConnectivityManager {
final BuildContext context;
ConnectivityManager(this.context);
/// Initialiser la connectivité
void get initConnectivity {
print('Initialisation de la connectivité');
}
}
/// Gestionnaire d'overlays personnalisés
class CustomOverlay {
static OverlayEntry? _currentOverlay;
/// Afficher un message d'erreur
static void showError(BuildContext context, {required String message}) {
hide();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
Icon(Icons.error, color: Colors.white, size: 20),
SizedBox(width: 8),
Expanded(
child: Text(
message,
style: TextStyle(color: Colors.white, fontSize: 14),
),
),
],
),
backgroundColor: Colors.red,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
duration: Duration(seconds: 4),
),
);
}
/// Afficher un message de succès
static void showSuccess(BuildContext context, {required String message}) {
hide();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
Icon(Icons.check_circle, color: Colors.white, size: 20),
SizedBox(width: 8),
Expanded(
child: Text(
message,
style: TextStyle(color: Colors.white, fontSize: 14),
),
),
],
),
backgroundColor: Colors.green,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
duration: Duration(seconds: 3),
),
);
}
/// Afficher un message d'information
static void showInfo(BuildContext context, {required String message}) {
hide();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
Icon(Icons.info_outline, color: Colors.white, size: 20),
SizedBox(width: 8),
Expanded(
child: Text(
message,
style: TextStyle(color: Colors.white, fontSize: 14),
),
),
],
),
backgroundColor: Color(0xFF006699),
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
duration: Duration(seconds: 3),
),
);
}
/// Afficher un avertissement
static void showWarning(BuildContext context, {required String message}) {
hide();
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
Icon(Icons.warning_amber, color: Colors.white, size: 20),
SizedBox(width: 8),
Expanded(
child: Text(
message,
style: TextStyle(color: Colors.white, fontSize: 14),
),
),
],
),
backgroundColor: Colors.orange,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
duration: Duration(seconds: 4),
),
);
}
/// Afficher un indicateur de chargement
static void showLoading(
BuildContext context, {
String message = 'Chargement...',
}) {
hide();
_currentOverlay = OverlayEntry(
builder:
(context) => Material(
color: Colors.black54,
child: Center(
child: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(12),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
Color(0xFF006699),
),
),
SizedBox(height: 16),
Text(
message,
style: TextStyle(fontSize: 16, color: Colors.black87),
),
],
),
),
),
),
);
Overlay.of(context).insert(_currentOverlay!);
}
/// Masquer l'overlay
static void hide() {
if (_currentOverlay != null) {
_currentOverlay!.remove();
_currentOverlay = null;
}
}
}
/// Classe utilitaire pour les widgets personnalisés
class CustomWidgets {
/// Créer un champ de saisie stylé
static Widget buildStyledTextField({
required String label,
required String hint,
required IconData icon,
TextEditingController? controller,
bool obscureText = false,
String? Function(String?)? validator,
void Function(String)? onChanged,
bool readOnly = false,
VoidCallback? onTap,
TextInputType? keyboardType,
int? maxLength,
String? suffixText,
Widget? suffix,
}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
label,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w500,
color: Color(0xFF2C3E50),
),
),
SizedBox(height: 8),
TextFormField(
controller: controller,
validator: validator,
obscureText: obscureText,
readOnly: readOnly,
onTap: onTap,
onChanged: onChanged,
keyboardType: keyboardType,
maxLength: maxLength,
decoration: InputDecoration(
hintText: hint,
prefixIcon: Icon(icon, color: Color(0xFF006699)),
suffixText: suffixText,
suffix: suffix,
filled: true,
fillColor: Colors.white,
counterText: '',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(color: Color(0xFFE0E7FF)),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(color: Color(0xFFE0E7FF)),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(color: Color(0xFF006699), width: 2),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
borderSide: BorderSide(color: Colors.red),
),
),
),
],
);
}
/// Créer un bouton stylé
static Widget buildStyledButton({
required String text,
required VoidCallback onPressed,
bool isLoading = false,
Color? backgroundColor,
Color? textColor,
IconData? icon,
double? height,
double? width,
bool enabled = true,
}) {
return SizedBox(
width: width ?? double.infinity,
height: height ?? 48,
child: ElevatedButton(
onPressed: (isLoading || !enabled) ? null : onPressed,
style: ElevatedButton.styleFrom(
backgroundColor: backgroundColor ?? Color(0xFF006699),
foregroundColor: textColor ?? Colors.white,
elevation: 2,
disabledBackgroundColor: Colors.grey[300],
disabledForegroundColor: Colors.grey[600],
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
child:
isLoading
? SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
)
: Row(
mainAxisAlignment: MainAxisAlignment.center,
mainAxisSize: MainAxisSize.min,
children: [
if (icon != null) ...[
Icon(icon, size: 18),
SizedBox(width: 8),
],
Text(
text,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
],
),
),
);
}
/// ===== NOUVEAU: Badge de type de compte =====
static Widget buildAccountTypeBadge({
required bool isEnterprise,
double fontSize = 12,
EdgeInsets? padding,
}) {
return Container(
padding: padding ?? EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color:
isEnterprise
? Color(0xFF8B5CF6).withOpacity(0.1)
: Color(0xFF006699).withOpacity(0.1),
borderRadius: BorderRadius.circular(20),
border: Border.all(
color:
isEnterprise
? Color(0xFF8B5CF6).withOpacity(0.3)
: Color(0xFF006699).withOpacity(0.3),
width: 1,
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
isEnterprise ? Icons.business : Icons.person,
color: isEnterprise ? Color(0xFF8B5CF6) : Color(0xFF006699),
size: fontSize + 2,
),
SizedBox(width: 6),
Text(
isEnterprise ? 'Entreprise' : 'Agent',
style: TextStyle(
color: isEnterprise ? Color(0xFF8B5CF6) : Color(0xFF006699),
fontSize: fontSize,
fontWeight: FontWeight.w600,
),
),
],
),
);
}
/// ===== NOUVEAU: Carte d'information avec icône =====
static Widget buildInfoCard({
required String title,
required String value,
required IconData icon,
Color? iconColor,
Color? backgroundColor,
VoidCallback? onTap,
}) {
return InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(12),
child: Container(
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
color: backgroundColor ?? Colors.white,
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: (iconColor ?? Color(0xFF006699)).withOpacity(0.2),
width: 1,
),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: Offset(0, 4),
),
],
),
child: Row(
children: [
Container(
padding: EdgeInsets.all(12),
decoration: BoxDecoration(
color: (iconColor ?? Color(0xFF006699)).withOpacity(0.1),
borderRadius: BorderRadius.circular(10),
),
child: Icon(
icon,
color: iconColor ?? Color(0xFF006699),
size: 24,
),
),
SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: TextStyle(
fontSize: 12,
color: Colors.grey[600],
fontWeight: FontWeight.w500,
),
),
SizedBox(height: 4),
Text(
value,
style: TextStyle(
fontSize: 16,
color: Colors.black87,
fontWeight: FontWeight.bold,
),
overflow: TextOverflow.ellipsis,
),
],
),
),
if (onTap != null)
Icon(Icons.arrow_forward_ios, size: 16, color: Colors.grey[400]),
],
),
),
);
}
/// ===== NOUVEAU: Carte de statistique =====
static Widget buildStatCard({
required String title,
required String value,
required IconData icon,
Color? color,
String? subtitle,
}) {
final cardColor = color ?? Color(0xFF006699);
return Container(
padding: EdgeInsets.all(16),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [cardColor.withOpacity(0.8), cardColor],
),
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: cardColor.withOpacity(0.3),
blurRadius: 10,
offset: Offset(0, 4),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Icon(icon, color: Colors.white, size: 32),
Container(
padding: EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
borderRadius: BorderRadius.circular(12),
),
child: Icon(Icons.trending_up, color: Colors.white, size: 16),
),
],
),
SizedBox(height: 12),
Text(
value,
style: TextStyle(
color: Colors.white,
fontSize: 28,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 4),
Text(
title,
style: TextStyle(
color: Colors.white.withOpacity(0.9),
fontSize: 14,
fontWeight: FontWeight.w500,
),
),
if (subtitle != null) ...[
SizedBox(height: 4),
Text(
subtitle,
style: TextStyle(
color: Colors.white.withOpacity(0.7),
fontSize: 12,
),
),
],
],
),
);
}
/// ===== NOUVEAU: Séparateur avec texte =====
static Widget buildDividerWithText(String text) {
return Row(
children: [
Expanded(child: Divider(color: Colors.grey[300], thickness: 1)),
Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
child: Text(
text,
style: TextStyle(
color: Colors.grey[600],
fontSize: 12,
fontWeight: FontWeight.w500,
),
),
),
Expanded(child: Divider(color: Colors.grey[300], thickness: 1)),
],
);
}
/// ===== NOUVEAU: Liste vide stylée =====
static Widget buildEmptyState({
required String message,
String? subtitle,
IconData? icon,
VoidCallback? onRefresh,
}) {
return Center(
child: Padding(
padding: EdgeInsets.all(24),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
icon ?? Icons.inbox_outlined,
size: 80,
color: Colors.grey[400],
),
SizedBox(height: 16),
Text(
message,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: Colors.grey[700],
),
textAlign: TextAlign.center,
),
if (subtitle != null) ...[
SizedBox(height: 8),
Text(
subtitle,
style: TextStyle(fontSize: 14, color: Colors.grey[500]),
textAlign: TextAlign.center,
),
],
if (onRefresh != null) ...[
SizedBox(height: 24),
ElevatedButton.icon(
onPressed: onRefresh,
icon: Icon(Icons.refresh),
label: Text('Actualiser'),
style: ElevatedButton.styleFrom(
backgroundColor: Color(0xFF006699),
foregroundColor: Colors.white,
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 12),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
),
),
],
],
),
),
);
}
/// ===== NOUVEAU: Dialog de confirmation =====
static Future<bool> showConfirmDialog({
required BuildContext context,
required String title,
required String message,
String confirmText = 'Confirmer',
String cancelText = 'Annuler',
Color? confirmColor,
IconData? icon,
}) async {
final result = await showDialog<bool>(
context: context,
builder:
(context) => AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
title: Row(
children: [
if (icon != null) ...[
Icon(icon, color: confirmColor ?? Color(0xFF006699)),
SizedBox(width: 12),
],
Expanded(child: Text(title, style: TextStyle(fontSize: 18))),
],
),
content: Text(
message,
style: TextStyle(fontSize: 14, color: Colors.grey[700]),
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(false),
child: Text(
cancelText,
style: TextStyle(color: Colors.grey[600]),
),
),
ElevatedButton(
onPressed: () => Navigator.of(context).pop(true),
style: ElevatedButton.styleFrom(
backgroundColor: confirmColor ?? Color(0xFF006699),
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: Text(confirmText),
),
],
),
);
return result ?? false;
}
/// ===== NOUVEAU: Badge de statut =====
static Widget buildStatusBadge({
required String text,
required bool isActive,
double fontSize = 12,
}) {
return Container(
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color:
isActive
? Colors.green.withOpacity(0.1)
: Colors.orange.withOpacity(0.1),
borderRadius: BorderRadius.circular(20),
border: Border.all(
color:
isActive
? Colors.green.withOpacity(0.3)
: Colors.orange.withOpacity(0.3),
width: 1,
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 8,
height: 8,
decoration: BoxDecoration(
color: isActive ? Colors.green : Colors.orange,
shape: BoxShape.circle,
),
),
SizedBox(width: 6),
Text(
text,
style: TextStyle(
color: isActive ? Colors.green[700] : Colors.orange[700],
fontSize: fontSize,
fontWeight: FontWeight.w600,
),
),
],
),
);
}
}
/// ===== NOUVELLE CLASSE: Utilitaires pour entreprises =====
class EnterpriseWidgets {
/// Badge entreprise
static Widget buildEnterpriseBadge({
required String enterpriseName,
double fontSize = 12,
EdgeInsets? padding,
}) {
return Container(
padding: padding ?? EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [Color(0xFF8B5CF6).withOpacity(0.8), Color(0xFF8B5CF6)],
),
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Color(0xFF8B5CF6).withOpacity(0.3),
blurRadius: 8,
offset: Offset(0, 2),
),
],
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.business, color: Colors.white, size: fontSize + 2),
SizedBox(width: 6),
Flexible(
child: Text(
enterpriseName,
style: TextStyle(
color: Colors.white,
fontSize: fontSize,
fontWeight: FontWeight.w600,
),
overflow: TextOverflow.ellipsis,
),
),
],
),
);
}
/// Carte d'information entreprise
static Widget buildEnterpriseInfoCard({
required String enterpriseId,
required String enterpriseName,
required double balance,
int? totalMembers,
VoidCallback? onTap,
}) {
return InkWell(
onTap: onTap,
borderRadius: BorderRadius.circular(16),
child: Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [Color(0xFF8B5CF6).withOpacity(0.8), Color(0xFF8B5CF6)],
),
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Color(0xFF8B5CF6).withOpacity(0.3),
blurRadius: 15,
offset: Offset(0, 8),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Icon(Icons.business, color: Colors.white, size: 32),
Container(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
borderRadius: BorderRadius.circular(12),
),
child: Text(
enterpriseId,
style: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w600,
),
),
),
],
),
SizedBox(height: 16),
Text(
enterpriseName,
style: TextStyle(
color: Colors.white,
fontSize: 20,
fontWeight: FontWeight.bold,
),
overflow: TextOverflow.ellipsis,
),
SizedBox(height: 8),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Solde disponible',
style: TextStyle(
color: Colors.white.withOpacity(0.8),
fontSize: 12,
),
),
SizedBox(height: 4),
Text(
'${balance.toStringAsFixed(0)} FCFA',
style: TextStyle(
color: Colors.white,
fontSize: 24,
fontWeight: FontWeight.bold,
),
),
],
),
if (totalMembers != null)
Column(
children: [
Icon(Icons.people, color: Colors.white, size: 24),
SizedBox(height: 4),
Text(
'$totalMembers',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
Text(
'Membres',
style: TextStyle(
color: Colors.white.withOpacity(0.8),
fontSize: 10,
),
),
],
),
],
),
],
),
),
);
}
}

2695
lib/pages/dashboard.dart Normal file

File diff suppressed because it is too large Load Diff

2348
lib/pages/form_service.dart Normal file

File diff suppressed because it is too large Load Diff

1451
lib/pages/home.dart Normal file

File diff suppressed because it is too large Load Diff

946
lib/pages/login.dart Normal file
View File

@@ -0,0 +1,946 @@
// ===== lib/pages/login.dart AVEC SUPPORT ENTREPRISE =====
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:wtpe/widgets/wortis_logo.dart';
import '../main.dart';
import '../services/wortis_api_service.dart';
import 'role_navigator.dart';
class LoginPage extends StatefulWidget {
const LoginPage({super.key});
@override
_LoginPageState createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage>
with SingleTickerProviderStateMixin {
final _formKey = GlobalKey<FormState>();
final _agentIdController = TextEditingController();
final _pinController = TextEditingController();
bool _obscurePin = true;
bool _apiConnected = false;
bool _testingConnection = false;
late AnimationController _animationController;
late Animation<double> _fadeAnimation;
late Animation<Offset> _slideAnimation;
// Couleurs Wortis
static const Color primaryColor = Color(0xFF006699);
static const Color secondaryColor = Color(0xFF0088CC);
static const Color accentColor = Color(0xFFFF6B35);
static const Color backgroundColor = Color(0xFFF8FAFC);
static const Color surfaceColor = Colors.white;
static const Color errorColor = Color(0xFFE53E3E);
static const Color textPrimaryColor = Color(0xFF1A202C);
static const Color textSecondaryColor = Color(0xFF718096);
static const Color borderColor = Color(0xFFE2E8F0);
static const Color enterpriseColor = Color(0xFF8B5CF6);
@override
void initState() {
super.initState();
_setupAnimations();
_testApiConnection();
}
void _setupAnimations() {
_animationController = AnimationController(
duration: Duration(milliseconds: 1500),
vsync: this,
);
_fadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
CurvedAnimation(
parent: _animationController,
curve: Interval(0.0, 0.8, curve: Curves.easeOut),
),
);
_slideAnimation = Tween<Offset>(
begin: Offset(0, 0.3),
end: Offset.zero,
).animate(
CurvedAnimation(
parent: _animationController,
curve: Interval(0.3, 1.0, curve: Curves.easeOut),
),
);
_animationController.forward();
}
Future<void> _testApiConnection() async {
setState(() {
_testingConnection = true;
});
final isConnected = await AuthApiService.testConnection();
if (mounted) {
setState(() {
_apiConnected = isConnected;
_testingConnection = false;
});
}
}
Future<void> _createTestUser() async {
String? nom = await _showCreateUserDialog();
if (nom == null || nom.isEmpty) return;
final result = await AuthApiService.createUser(nom, '1234');
if (result['success'] == true) {
final agentId = result['generated_agent_id'];
setState(() {
_agentIdController.text = agentId;
_pinController.text = '1234';
});
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
Icon(Icons.check_circle, color: Colors.white),
SizedBox(width: 8),
Expanded(child: Text('Utilisateur créé: $agentId / PIN: 1234')),
],
),
backgroundColor: Colors.green,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Erreur: ${result['message']}'),
backgroundColor: Colors.orange,
),
);
}
}
Future<String?> _showCreateUserDialog() async {
final nameController = TextEditingController();
return showDialog<String>(
context: context,
builder:
(context) => AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
title: Row(
children: [
Icon(Icons.person_add, color: primaryColor),
SizedBox(width: 12),
Text('Créer un utilisateur'),
],
),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
padding: EdgeInsets.all(12),
decoration: BoxDecoration(
color: primaryColor.withOpacity(0.1),
borderRadius: BorderRadius.circular(8),
border: Border.all(color: primaryColor.withOpacity(0.3)),
),
child: Row(
children: [
Icon(Icons.info_outline, color: primaryColor, size: 20),
SizedBox(width: 8),
Expanded(
child: Text(
'L\'ID agent sera généré automatiquement (WRT####)',
style: TextStyle(fontSize: 12, color: primaryColor),
),
),
],
),
),
SizedBox(height: 16),
TextField(
controller: nameController,
decoration: InputDecoration(
labelText: 'Nom complet',
hintText: 'Ex: Jean Dupont',
prefixIcon: Icon(Icons.person_outline),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(8),
),
),
autofocus: true,
),
],
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: Text('Annuler'),
),
ElevatedButton(
onPressed:
() => Navigator.pop(context, nameController.text.trim()),
style: ElevatedButton.styleFrom(
backgroundColor: primaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
),
child: Text('Créer', style: TextStyle(color: Colors.white)),
),
],
),
);
}
@override
void dispose() {
_agentIdController.dispose();
_pinController.dispose();
_animationController.dispose();
super.dispose();
}
void _login() async {
if (_formKey.currentState!.validate()) {
final authController = Provider.of<AuthController>(
context,
listen: false,
);
authController.clearError();
bool success = await authController.login(
_agentIdController.text.trim(),
_pinController.text.trim(),
false,
);
if (success && mounted) {
// Afficher un message de bienvenue personnalisé
final isEnterprise = authController.isEnterpriseMember;
final accountType = isEnterprise ? 'Entreprise' : 'Agent';
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
shape: BoxShape.circle,
),
child: Icon(
isEnterprise ? Icons.business : Icons.person,
color: Colors.white,
size: 20,
),
),
SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Bienvenue ${authController.agentName}',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
if (isEnterprise &&
authController.enterprise?.nomEntreprise != null) ...[
SizedBox(height: 2),
Text(
authController.enterprise!.nomEntreprise,
style: TextStyle(
color: Colors.white.withOpacity(0.9),
fontSize: 12,
),
),
],
],
),
),
Container(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 4),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
borderRadius: BorderRadius.circular(12),
),
child: Text(
accountType,
style: TextStyle(
color: Colors.white,
fontSize: 10,
fontWeight: FontWeight.w600,
),
),
),
],
),
backgroundColor: isEnterprise ? enterpriseColor : Colors.green,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
duration: Duration(seconds: 2),
margin: EdgeInsets.all(16),
),
);
// Navigation basée sur le rôle
final userRole = authController.role ?? 'agent';
RoleNavigator.navigateByRole(context, userRole);
} else if (mounted) {
final errorMessage =
authController.errorMessage ?? 'Erreur de connexion';
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Row(
children: [
Icon(Icons.error_outline, color: Colors.white, size: 24),
SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
'Connexion échouée',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
),
),
SizedBox(height: 2),
Text(errorMessage, style: TextStyle(fontSize: 12)),
],
),
),
],
),
backgroundColor: errorColor,
behavior: SnackBarBehavior.floating,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
duration: Duration(seconds: 4),
margin: EdgeInsets.all(16),
),
);
}
}
}
void _openWifiSettings() async {
try {
const platform = MethodChannel('com.wortis.agent/settings');
await platform.invokeMethod('exitKioskMode');
await platform.invokeMethod('openWifiSettings');
} catch (e) {
print('Erreur ouverture WiFi: $e');
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Impossible d\'ouvrir les paramètres WiFi'),
backgroundColor: Colors.orange,
),
);
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: backgroundColor,
body: SafeArea(
child: SingleChildScrollView(
physics: BouncingScrollPhysics(),
padding: EdgeInsets.all(24),
child: FadeTransition(
opacity: _fadeAnimation,
child: SlideTransition(
position: _slideAnimation,
child: Column(
children: [
SizedBox(height: 20),
_buildApiStatusIndicator(),
SizedBox(height: 20),
_buildHeader(),
SizedBox(height: 50),
_buildLoginForm(),
SizedBox(height: 30),
_buildHelpSection(),
SizedBox(height: 20),
],
),
),
),
),
),
);
}
Widget _buildApiStatusIndicator() {
return Container(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration(
color:
_testingConnection
? Colors.orange.withOpacity(0.1)
: _apiConnected
? Colors.green.withOpacity(0.1)
: Colors.red.withOpacity(0.1),
borderRadius: BorderRadius.circular(25),
border: Border.all(
color:
_testingConnection
? Colors.orange.withOpacity(0.3)
: _apiConnected
? Colors.green.withOpacity(0.3)
: Colors.red.withOpacity(0.3),
width: 1.5,
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (_testingConnection) ...[
SizedBox(
width: 16,
height: 16,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(Colors.orange),
),
),
SizedBox(width: 8),
Text(
'Test connexion...',
style: TextStyle(
color: Colors.orange.shade700,
fontSize: 12,
fontWeight: FontWeight.w600,
),
),
] else ...[
Container(
padding: EdgeInsets.all(4),
decoration: BoxDecoration(
color:
_apiConnected
? Colors.green.withOpacity(0.2)
: Colors.red.withOpacity(0.2),
shape: BoxShape.circle,
),
child: Icon(
_apiConnected
? Icons.cloud_done_rounded
: Icons.cloud_off_rounded,
size: 16,
color:
_apiConnected ? Colors.green.shade700 : Colors.red.shade700,
),
),
SizedBox(width: 8),
Text(
_apiConnected ? 'API connectée' : 'API déconnectée',
style: TextStyle(
color:
_apiConnected ? Colors.green.shade700 : Colors.red.shade700,
fontSize: 12,
fontWeight: FontWeight.w600,
),
),
SizedBox(width: 8),
GestureDetector(
onTap: _testApiConnection,
child: Container(
padding: EdgeInsets.all(4),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.5),
shape: BoxShape.circle,
),
child: Icon(
Icons.refresh_rounded,
size: 16,
color:
_apiConnected
? Colors.green.shade700
: Colors.red.shade700,
),
),
),
],
],
),
);
}
Widget _buildHeader() {
return Column(
children: [
WortisLogoWidget(size: 100, isWhite: false, withShadow: true),
SizedBox(height: 24),
ShaderMask(
shaderCallback:
(bounds) => LinearGradient(
colors: [primaryColor, secondaryColor],
).createShader(bounds),
child: Text(
'WORTIS AGENT',
style: TextStyle(
fontSize: 28,
fontWeight: FontWeight.bold,
color: Colors.white,
letterSpacing: 2,
),
),
),
SizedBox(height: 8),
Text(
'Connexion à votre espace',
style: TextStyle(
fontSize: 16,
color: textSecondaryColor,
fontWeight: FontWeight.w400,
),
),
SizedBox(height: 12),
// Badges des types de comptes supportés
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
_buildAccountTypeBadge(
icon: Icons.person,
label: 'Agent',
color: primaryColor,
),
SizedBox(width: 12),
_buildAccountTypeBadge(
icon: Icons.business,
label: 'Entreprise',
color: enterpriseColor,
),
],
),
],
);
}
Widget _buildAccountTypeBadge({
required IconData icon,
required String label,
required Color color,
}) {
return Container(
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: color.withOpacity(0.1),
borderRadius: BorderRadius.circular(20),
border: Border.all(color: color.withOpacity(0.3), width: 1),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(icon, color: color, size: 14),
SizedBox(width: 6),
Text(
label,
style: TextStyle(
color: color,
fontSize: 11,
fontWeight: FontWeight.w600,
),
),
],
),
);
}
Widget _buildLoginForm() {
return Container(
padding: EdgeInsets.all(28),
decoration: BoxDecoration(
color: surfaceColor,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.08),
blurRadius: 20,
offset: Offset(0, 4),
),
],
),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
Container(
padding: EdgeInsets.all(8),
decoration: BoxDecoration(
color: primaryColor.withOpacity(0.1),
borderRadius: BorderRadius.circular(10),
),
child: Icon(
Icons.login_rounded,
color: primaryColor,
size: 24,
),
),
SizedBox(width: 12),
Text(
'Identifiants',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
color: textPrimaryColor,
),
),
],
),
SizedBox(height: 24),
_buildTextField(
controller: _agentIdController,
label: 'ID Agent',
hint: 'Entrez votre identifiant',
prefixIcon: Icons.badge_outlined,
validator: (value) {
if (value == null || value.isEmpty) {
return 'L\'ID agent est requis';
}
if (value.length < 3) {
return 'ID agent trop court (min. 3 caractères)';
}
return null;
},
),
SizedBox(height: 20),
_buildTextField(
controller: _pinController,
label: 'Code PIN',
hint: 'Entrez votre code PIN',
prefixIcon: Icons.lock_outline,
obscureText: _obscurePin,
suffixIcon: IconButton(
icon: Icon(
_obscurePin
? Icons.visibility_outlined
: Icons.visibility_off_outlined,
color: textSecondaryColor,
),
onPressed: () {
setState(() {
_obscurePin = !_obscurePin;
});
},
),
validator: (value) {
if (value == null || value.isEmpty) {
return 'Le code PIN est requis';
}
if (value.length < 4) {
return 'Le PIN doit contenir au moins 4 chiffres';
}
return null;
},
),
SizedBox(height: 32),
Consumer<AuthController>(
builder: (context, authController, child) {
return _buildLoginButton(authController);
},
),
SizedBox(height: 16),
Container(
width: double.infinity,
child: OutlinedButton.icon(
onPressed: _openWifiSettings,
icon: Icon(Icons.wifi_find_rounded, size: 20),
label: Text('Paramètres WiFi'),
style: OutlinedButton.styleFrom(
padding: EdgeInsets.symmetric(vertical: 14),
side: BorderSide(color: primaryColor, width: 1.5),
foregroundColor: primaryColor,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
),
),
// Bouton de test (commenté par défaut)
// if (_apiConnected) ...[
// SizedBox(height: 16),
// TextButton.icon(
// onPressed: _createTestUser,
// icon: Icon(Icons.add_circle_outline, size: 18),
// label: Text('Créer utilisateur test'),
// style: TextButton.styleFrom(foregroundColor: primaryColor),
// ),
// ],
],
),
),
);
}
Widget _buildTextField({
required TextEditingController controller,
required String label,
required String hint,
required IconData prefixIcon,
Widget? suffixIcon,
bool obscureText = false,
String? Function(String?)? validator,
}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
label,
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: textPrimaryColor,
),
),
SizedBox(height: 8),
TextFormField(
controller: controller,
validator: validator,
obscureText: obscureText,
decoration: InputDecoration(
hintText: hint,
hintStyle: TextStyle(color: textSecondaryColor),
prefixIcon: Icon(prefixIcon, color: primaryColor),
suffixIcon: suffixIcon,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: borderColor),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: borderColor),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: primaryColor, width: 2),
),
errorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: errorColor),
),
focusedErrorBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: errorColor, width: 2),
),
contentPadding: EdgeInsets.symmetric(horizontal: 16, vertical: 16),
filled: true,
fillColor: backgroundColor.withOpacity(0.3),
),
),
],
);
}
Widget _buildLoginButton(AuthController authController) {
return Container(
height: 54,
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [primaryColor, secondaryColor],
begin: Alignment.centerLeft,
end: Alignment.centerRight,
),
borderRadius: BorderRadius.circular(12),
boxShadow: [
BoxShadow(
color: primaryColor.withOpacity(0.4),
blurRadius: 10,
offset: Offset(0, 4),
),
],
),
child: ElevatedButton(
onPressed: authController.isLoading ? null : _login,
style: ElevatedButton.styleFrom(
backgroundColor: Colors.transparent,
shadowColor: Colors.transparent,
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
),
child:
authController.isLoading
? SizedBox(
width: 24,
height: 24,
child: CircularProgressIndicator(
strokeWidth: 2.5,
valueColor: AlwaysStoppedAnimation<Color>(Colors.white),
),
)
: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.login_rounded, size: 22),
SizedBox(width: 10),
Text(
'SE CONNECTER',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
letterSpacing: 1.2,
),
),
],
),
),
);
}
Widget _buildHelpSection() {
return Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [
secondaryColor.withOpacity(0.1),
primaryColor.withOpacity(0.05),
],
),
borderRadius: BorderRadius.circular(16),
border: Border.all(color: secondaryColor.withOpacity(0.3), width: 1.5),
),
child: Column(
children: [
Container(
padding: EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white,
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
color: primaryColor.withOpacity(0.2),
blurRadius: 10,
offset: Offset(0, 4),
),
],
),
child: Icon(
Icons.help_outline_rounded,
color: primaryColor,
size: 32,
),
),
SizedBox(height: 16),
Text(
'Besoin d\'aide ?',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
color: textPrimaryColor,
),
),
SizedBox(height: 12),
Container(
padding: EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.7),
borderRadius: BorderRadius.circular(12),
),
// child: Column(
// children: [
// Row(
// children: [
// Icon(Icons.person, color: primaryColor, size: 16),
// SizedBox(width: 8),
// Expanded(
// child: Text(
// 'Compte Agent - Accès individuel',
// style: TextStyle(fontSize: 13, color: textPrimaryColor),
// ),
// ),
// ],
// ),
// SizedBox(height: 8),
// Row(
// children: [
// Icon(Icons.business, color: enterpriseColor, size: 16),
// SizedBox(width: 8),
// Expanded(
// child: Text(
// 'Compte Entreprise - Solde partagé',
// style: TextStyle(fontSize: 13, color: textPrimaryColor),
// ),
// ),
// ],
// ),
// ],
// ),
),
SizedBox(height: 16),
Container(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 10),
decoration: BoxDecoration(
color: primaryColor,
borderRadius: BorderRadius.circular(25),
boxShadow: [
BoxShadow(
color: primaryColor.withOpacity(0.3),
blurRadius: 8,
offset: Offset(0, 4),
),
],
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(Icons.phone, color: Colors.white, size: 18),
SizedBox(width: 8),
Text(
'Support: 50 05',
style: TextStyle(
fontSize: 14,
color: Colors.white,
fontWeight: FontWeight.w600,
),
),
],
),
),
],
),
);
}
}

File diff suppressed because it is too large Load Diff

1
lib/pages/profile.dart Normal file
View File

@@ -0,0 +1 @@
// TODO Implement this library.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,85 @@
// lib/utils/role_navigator.dart
import 'package:flutter/material.dart';
import '../pages/main_navigation.dart';
import '../pages/admin_dashboard.dart';
import '../pages/rechargeur_dashboard.dart';
class RoleNavigator {
/// Naviguer vers la page appropriée selon le rôle
static void navigateByRole(BuildContext context, String role) {
Widget destination;
switch (role.toLowerCase()) {
case 'admin':
destination = AdminDashboard();
break;
case 'rechargeur':
destination = RechargeurDashboard();
break;
case 'agent':
default:
destination = MainNavigationPage(initialIndex: 0);
break;
}
Navigator.of(context).pushReplacement(
PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) => destination,
transitionsBuilder: (context, animation, secondaryAnimation, child) {
return FadeTransition(
opacity: animation,
child: SlideTransition(
position: Tween<Offset>(
begin: Offset(0.1, 0),
end: Offset.zero,
).animate(
CurvedAnimation(parent: animation, curve: Curves.easeOut),
),
child: child,
),
);
},
transitionDuration: Duration(milliseconds: 600),
),
);
}
/// Obtenir l'icône selon le rôle
static IconData getRoleIcon(String role) {
switch (role.toLowerCase()) {
case 'admin':
return Icons.admin_panel_settings;
case 'rechargeur':
return Icons.add_circle;
case 'agent':
default:
return Icons.person;
}
}
/// Obtenir la couleur selon le rôle
static Color getRoleColor(String role) {
switch (role.toLowerCase()) {
case 'admin':
return Color(0xFFE53E3E); // Rouge
case 'rechargeur':
return Color(0xFF38A169); // Vert
case 'agent':
default:
return Color(0xFF006699); // Bleu Wortis
}
}
/// Obtenir le nom d'affichage du rôle
static String getRoleDisplayName(String role) {
switch (role.toLowerCase()) {
case 'admin':
return 'Administrateur';
case 'rechargeur':
return 'Rechargeur';
case 'agent':
default:
return 'Agent';
}
}
}

371
lib/pages/service.json Normal file
View File

@@ -0,0 +1,371 @@
{
"_id": {
"$oid": "67800eeeaff834f203a70cad"
},
"name": "Cartes Play Store",
"Type_Service": "PaiementImmediat",
"SecteurActivite": "Cartes Virtuelles",
"icon": "credit_score_outlined",
"banner": "https://apigede.wortispay.cg/apk-mobile/banner_service/wsgaming.jpg",
"description": "Achetez des cartes Google Play pour accéder à des applications, des jeux, de la musique et bien plus encore sur votre appareil Android.\nVeuillez vous rassurer que votre compte est bien localisé en France.",
"tite_description": "Potentiel déverrouillé",
"status": true,
"error_400": "Pas encore defenit",
"error_500": "Quelque chose a mal fonctioné",
"comment_payer": "1.\tSélectionnez le montant de la carte Play Store.\n\n2.\tRenseignez vos détails pour l'achat.\n\n3.\tPayez via Mobile Money ou carte bancaire.",
"button_service": "Payer",
"bouton_list": "Ajouter un élément",
"steps": [
{
"request": "POST",
"fields": [
{
"name": "Service",
"type": "selecteur",
"options": [
{
"value": "Google Play",
"label": "Google Play"
},
{
"value": "Apple",
"label": "Apple"
}
],
"required": true
}
],
"link": "https://api.live.wortis.cg/verify_card_apk",
"title_button": "Suivant",
"body": {
"service": "Service"
}
},
{
"request": "POST",
"fields": [
{
"name": "typeCard",
"type": "selecteur",
"label": "Choisir votre forfait",
"options": [
{
"value": "Google Play Essentiel 10 €/8 913 Fcfa",
"label": "Google Play Essentiel\n10 €/8 913 Fcfa\n"
},
{
"value": "Google Play Découverte 15 €/13 369 Fcfa",
"label": "Google Play Découverte\n15 €/13 369 Fcfa\n"
},
{
"value": "Google Avancée 25 €/22 281 Fcfa",
"label": "Google Avancée\n25 €/22 281 Fcfa\n"
},
{
"value": "Google Deluxe 50€ 50 €/44 563 Fcfa",
"label": "Google Deluxe 50€\n50 €/44 563 Fcfa\n"
},
{
"value": "Google Deluxe 100€ 100 €/89 125 Fcfa",
"label": "Google Deluxe 100€\n100 €/89 125 Fcfa"
}
],
"dependencies": [
{
"field": "service_selected",
"value": "Google Play"
}
],
"required": true
},
{
"name": "typeCard",
"type": "selecteur",
"label": "Choisir votre forfait",
"options": [
{
"value": "Apple Essentiel 10 €/8 913 Fcfa",
"label": "Apple Essentiel\n 10 €/8 913 Fcfa\n"
},
{
"value": "Apple Découverte 15 €/13 369 Fcfa",
"label": "Apple Découverte \n15 €/13 369 Fcfa\n"
},
{
"value": "Apple Avancée 25 €/22 281 Fcfa",
"label": "Apple Avancée \n25 €/22 281 Fcfa\n"
},
{
"value": "Apple Deluxe 50 €/44 563 Fcfa",
"label": "Apple Deluxe \n50 €/44 563 Fcfa"
}
],
"dependencies": [
{
"field": "service_selected",
"value": "Apple"
}
],
"required": true
},
{
"name": "nom",
"type": "text",
"label": "Nom et Prénoms",
"required": true
},
{
"name": "email",
"type": "text",
"label": "Email",
"required": true
},
{
"name": "mobile",
"type": "number",
"label": "Numéro de paiement",
"required": true
},
{
"name": "token",
"type": "hidden",
"required": true
}
],
"body": {
"nom": "nom",
"service": "service_selected",
"email": "email",
"mobile": "mobile",
"typeCard": "typeCard",
"token": "token"
},
"link_momo": "https://api.live.wortis.cg/commande_card_apk",
"api_fields": {
"service_selected": {
"type": "text",
"readonly": true,
"label": "Service Sélectionné",
"key": "service"
}
},
"link_cb": "https://api.live.wortis.cg/commande_card_apk"
}
],
"logo": "https://apigede.wortispay.cg/apk-mobile/service_logo/game.png"
}
{
"_id": {
"$oid": "677d5e75c11a9f6c491f288e"
},
"name": "Cartes Gaming",
"Type_Service": "PaiementImmediat",
"SecteurActivite": "Cartes Virtuelles",
"icon": "credit_score_outlined",
"banner": "https://apigede.wortispay.cg/apk-mobile/banner_service/wsgaming.jpg",
"description": "Achetez des cartes de jeu en ligne pour vos plateformes favorites (PlayStation, Xbox, Steam, etc.). Profitez d'une expérience de jeu ininterrompue et d'un accès rapide à des contenus premium.",
"tite_description": "Accès jeux",
"status": true,
"error_400": "Pas encore defenit",
"error_500": "Quelque chose a mal fonctioné",
"comment_payer": "1.\tSélectionnez la carte de jeu souhaitée.\n\n2.\tIndiquez le montant et vos détails de livraison.\n\n3.\tProcédez au paiement via Mobile Money ou carte bancaire.",
"button_service": "Payer",
"bouton_list": "Ajouter un élément",
"steps": [
{
"request": "POST",
"fields": [
{
"name": "Service",
"type": "selecteur",
"options": [
{
"value": "Steam",
"label": "Steam"
},
{
"value": "Nitendo",
"label": "Nitendo"
},
{
"value": "Fortnite",
"label": "Fortnite"
},
{
"value": "PlayStation",
"label": "PlayStation"
}
],
"required": true
}
],
"link": "https://api.live.wortis.cg/verify_card_apk",
"title_button": "Suivant",
"body": {
"service": "Service"
}
},
{
"request": "POST",
"fields": [
{
"name": "TypeCard",
"type": "selecteur",
"options": [
{
"value": "Steam Essentiel 10 €/ 8 913 Fcfa",
"label": "Steam Essentiel \n10 €/ 8 913 Fcfa\n"
},
{
"value": "Steam Standard 20 €/17 825 Fcfa",
"label": "Steam Standard \n20 €/17 825 Fcfa\n"
},
{
"value": "Steam Delux 50 €/ 44 563 Fcfa",
"label": "Steam Delux \n50 €/ 44 563 Fcfa\n"
},
{
"value": "Steam Ultime 100 €/ 89 125 Fcfa",
"label": "Steam Ultime \n100 €/ 89 125 Fcfa"
}
],
"dependencies": [
{
"field": "service_selected",
"value": "Steam"
}
],
"required": true
},
{
"name": "TypeCard",
"type": "selecteur",
"options": [
{
"value": "Nitendo Décourte 15 €/ 13 369 Fcfa",
"label": "Nitendo Décourte \n15 €/ 13 369 Fcfa"
},
{
"value": "Nitendo Avancée 25 €/22 281 Fcfa",
"label": "Nitendo Avancée \n25 €/22 281 Fcfa\n"
},
{
"value": "Nitendo Delux 50 €/ 44 563 Fcfa",
"label": "Nitendo Delux \n50 €/ 44 563 Fcfa\n"
},
{
"value": "Nitendo Ultime 100 €/ 89 125 Fcfa",
"label": "Nitendo Ultime \n100 €/ 89 125 Fcfa"
}
],
"dependencies": [
{
"field": "service_selected",
"value": "Nitendo"
}
],
"required": true
},
{
"name": "TypeCard",
"type": "selecteur",
"options": [
{
"value": "Fortnite-1 8.99 €/8 012 Fcfa",
"label": "Fortnite-1 \n8.99 €/8 012 Fcfa\n"
},
{
"value": "Fortnite-2 22.99 €/20 490 Fcfa",
"label": "Fortnite-2 \n22.99 €/20 490 Fcfa\n"
},
{
"value": "Fortnite-5 36.99 €/32 967 Fcfa",
"label": "Fortnite-5 \n36.99 €/32 967 Fcfa\n"
},
{
"value": "Fortnite-13 89.99 €/80 204 Fcfa",
"label": "Fortnite-13 \n89.99 €/80 204 Fcfa"
}
],
"dependencies": [
{
"field": "service_selected",
"value": "Fortnite"
}
],
"required": true
},
{
"name": "TypeCard",
"type": "selecteur",
"options": [
{
"value": "PS Essentiel 10 €/8 913 Fcfa",
"label": "PS Essentiel \n10 €/8 913 Fcfa\n"
},
{
"value": "PS Standard 20 €/17 825 Fcfa",
"label": "PS Standard \n20 €/17 825 Fcfa\n"
},
{
"value": "PS Prenium 50 €/44 463 Fcfa",
"label": "PS Prenium \n50 €/44 463 Fcfa\n"
},
{
"value": "PS Avant-Garde 100 €/89 125 Fcfa",
"label": "PS Avant-Garde \n100 €/89 125 Fcfa"
}
],
"dependencies": [
{
"field": "service_selected",
"value": "PlayStation"
}
],
"required": true
},
{
"name": "Nom et Prénoms",
"type": "text",
"required": true
},
{
"name": "Email",
"type": "text",
"required": true
},
{
"name": "Numéro de paiement",
"type": "number",
"required": true
}
],
"body": {
"nom": "Nom et Prénoms",
"service": "service_selected",
"email": "Email",
"mobile": "Numéro de paiement",
"typeCard": "typeCard"
},
"link_momo": "https://api.live.wortis.cg/commande_card_apk",
"api_fields": {
"service_selected": {
"type": "text",
"readonly": true,
"label": "Service Sélectionné",
"key": "service"
}
},
"link_cb": "https://api.live.wortis.cg/commande_card_apk"
}
],
"logo": "https://apigede.wortispay.cg/apk-mobile/service_logo/game.png"
}

View File

@@ -0,0 +1,157 @@
import 'package:shared_preferences/shared_preferences.dart';
class SessionManager {
static const String _keyUserId = 'user_id';
static const String _keyToken = 'user_token';
static const String _keyRole = 'user_role';
static const String _keyPIN = 'user_pin'; // Ajouté pour le PIN
static const String _keyLoginDate = 'login_date';
static const String _keyIsLoggedIn = 'is_logged_in';
static SessionManager? _instance;
static SharedPreferences? _prefs;
SessionManager._internal();
factory SessionManager() {
_instance ??= SessionManager._internal();
return _instance!;
}
Future<void> _initPrefs() async {
_prefs ??= await SharedPreferences.getInstance();
}
/// Sauvegarder une session
Future<void> saveSession(
String userId, {
String? token,
String? role,
String? pinkey, // Ajouté pour le PIN
}) async {
await _initPrefs();
await _prefs!.setString(_keyUserId, userId);
await _prefs!.setBool(_keyIsLoggedIn, true);
await _prefs!.setString(_keyLoginDate, DateTime.now().toIso8601String());
if (token != null) {
await _prefs!.setString(_keyToken, token);
}
if (role != null) {
await _prefs!.setString(_keyRole, role);
}
if (pinkey != null) {
await _prefs!.setString(_keyPIN, pinkey);
}
print('Session sauvegardée pour $userId');
}
/// Vérifier si l'utilisateur est connecté
Future<bool> isLoggedIn() async {
await _initPrefs();
return _prefs!.getBool(_keyIsLoggedIn) ?? false;
}
/// Récupérer l'ID utilisateur
Future<String?> getUserId() async {
await _initPrefs();
return _prefs!.getString(_keyUserId);
}
/// Récupérer le token
Future<String?> getToken() async {
await _initPrefs();
return _prefs!.getString(_keyToken);
}
/// Récupérer le rôle
Future<String?> getRole() async {
await _initPrefs();
return _prefs!.getString(_keyRole);
}
/// Récupérer le PIN (nouvelle méthode)
Future<String?> getPIN() async {
await _initPrefs();
return _prefs!.getString(_keyPIN);
}
/// Méthode synchrone pour le PIN (utilisée dans AuthController)
String? getPINSync() {
return _prefs?.getString(_keyPIN);
}
/// Récupérer la date de connexion
Future<DateTime?> getLoginDate() async {
await _initPrefs();
String? dateString = _prefs!.getString(_keyLoginDate);
if (dateString != null) {
return DateTime.parse(dateString);
}
return null;
}
/// Effacer la session
Future<void> clearSession() async {
await _initPrefs();
await _prefs!.remove(_keyUserId);
await _prefs!.remove(_keyToken);
await _prefs!.remove(_keyRole);
await _prefs!.remove(_keyPIN); // Supprimer aussi le PIN
await _prefs!.remove(_keyLoginDate);
await _prefs!.setBool(_keyIsLoggedIn, false);
print('Session effacée');
}
/// Mettre à jour le token uniquement
Future<void> updateToken(String newToken) async {
await _initPrefs();
await _prefs!.setString(_keyToken, newToken);
}
/// Vérifier si la session a expiré
Future<bool> isSessionExpired({Duration? maxAge}) async {
maxAge ??= Duration(days: 30); // 30 jours par défaut
DateTime? loginDate = await getLoginDate();
if (loginDate == null) return true;
return DateTime.now().difference(loginDate) > maxAge;
}
/// Obtenir toutes les informations de session
Future<Map<String, dynamic>> getSessionInfo() async {
await _initPrefs();
return {
'user_id': await getUserId(),
'token': await getToken(),
'role': await getRole(),
'pin': await getPIN(),
'login_date': await getLoginDate(),
'is_logged_in': await isLoggedIn(),
'is_expired': await isSessionExpired(),
};
}
/// Debug: Afficher les informations de session
Future<void> debugPrintSession() async {
Map<String, dynamic> sessionInfo = await getSessionInfo();
print('=== Informations de Session ===');
sessionInfo.forEach((key, value) {
if (key == 'pin' || key == 'token') {
// Masquer les données sensibles
print('$key: ${value?.toString().substring(0, 4) ?? 'null'}...');
} else {
print('$key: $value');
}
});
print('================================');
}
}

View File

@@ -0,0 +1,533 @@
// ===== lib/pages/splash_screen.dart MODIFIÉ AVEC API =====
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../main.dart'; // Pour AuthController
import '../widgets/wortis_logo.dart'; // NOUVEAU: Import du widget logo
import 'login.dart';
import 'main_navigation.dart';
class SplashScreen extends StatefulWidget {
const SplashScreen({super.key});
@override
_SplashScreenState createState() => _SplashScreenState();
}
class _SplashScreenState extends State<SplashScreen>
with TickerProviderStateMixin {
late AnimationController _logoController;
late AnimationController _textController;
late AnimationController _loadingController;
late Animation<double> _logoFadeAnimation;
late Animation<double> _logoScaleAnimation;
late Animation<Offset> _logoSlideAnimation;
late Animation<double> _textFadeAnimation;
late Animation<Offset> _textSlideAnimation;
late Animation<double> _loadingFadeAnimation;
String _statusMessage = 'Initialisation...';
bool _hasApiConnection = false;
// Couleurs Wortis
static const Color primaryColor = Color(0xFF006699);
static const Color secondaryColor = Color(0xFF0088CC);
static const Color accentColor = Color(0xFFFF6B35);
@override
void initState() {
super.initState();
_setupAnimations();
_startAnimationSequence();
_checkAuthStatus();
}
void _setupAnimations() {
_logoController = AnimationController(
duration: Duration(milliseconds: 2000),
vsync: this,
);
_textController = AnimationController(
duration: Duration(milliseconds: 1500),
vsync: this,
);
_loadingController = AnimationController(
duration: Duration(milliseconds: 1200),
vsync: this,
);
_logoFadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
CurvedAnimation(
parent: _logoController,
curve: Interval(0.0, 0.6, curve: Curves.easeOut),
),
);
_logoScaleAnimation = Tween<double>(begin: 0.3, end: 1.0).animate(
CurvedAnimation(
parent: _logoController,
curve: Interval(0.0, 0.8, curve: Curves.elasticOut),
),
);
_logoSlideAnimation = Tween<Offset>(
begin: Offset(0, -0.5),
end: Offset.zero,
).animate(
CurvedAnimation(
parent: _logoController,
curve: Interval(0.2, 1.0, curve: Curves.easeOutCubic),
),
);
_textFadeAnimation = Tween<double>(
begin: 0.0,
end: 1.0,
).animate(CurvedAnimation(parent: _textController, curve: Curves.easeOut));
_textSlideAnimation = Tween<Offset>(
begin: Offset(0, 0.3),
end: Offset.zero,
).animate(CurvedAnimation(parent: _textController, curve: Curves.easeOut));
_loadingFadeAnimation = Tween<double>(begin: 0.0, end: 1.0).animate(
CurvedAnimation(parent: _loadingController, curve: Curves.easeIn),
);
}
void _startAnimationSequence() async {
_logoController.forward();
await Future.delayed(Duration(milliseconds: 800));
if (mounted) _textController.forward();
await Future.delayed(Duration(milliseconds: 400));
if (mounted) _loadingController.repeat();
}
void _updateStatus(String message) {
if (mounted) {
setState(() {
_statusMessage = message;
});
}
}
void _checkAuthStatus() async {
try {
// Étape 1: Test de connexion API
_updateStatus('Test de connexion API...');
await Future.delayed(Duration(milliseconds: 800));
if (!mounted) return;
final authController = Provider.of<AuthController>(
context,
listen: false,
);
// Tester la connexion à l'API
_hasApiConnection = await authController.testApiConnection();
if (_hasApiConnection) {
_updateStatus('API connectée ✓');
await Future.delayed(Duration(milliseconds: 600));
} else {
_updateStatus('Mode hors ligne');
await Future.delayed(Duration(milliseconds: 600));
}
// Étape 2: Vérification de l'authentification
_updateStatus('Vérification de session...');
await Future.delayed(Duration(milliseconds: 800));
if (!mounted) return;
bool isLoggedIn = await authController.checkLoginStatus(context);
print('L\'utilisateur est : $isLoggedIn');
_updateStatus('Finalisation...');
await Future.delayed(Duration(milliseconds: 500));
if (!mounted) return;
// Animation de sortie
await _logoController.reverse();
if (!mounted) return;
// Navigation
Navigator.of(context).pushReplacement(
PageRouteBuilder(
pageBuilder: (context, animation, secondaryAnimation) {
return isLoggedIn
? MainNavigationPage(initialIndex: 0)
: LoginPage();
},
transitionsBuilder: (context, animation, secondaryAnimation, child) {
return FadeTransition(
opacity: animation,
child: SlideTransition(
position: Tween<Offset>(
begin: Offset(0.0, 0.1),
end: Offset.zero,
).animate(
CurvedAnimation(parent: animation, curve: Curves.easeOut),
),
child: child,
),
);
},
transitionDuration: Duration(milliseconds: 600),
),
);
} catch (e) {
print('Erreur lors de la vérification d\'authentification: $e');
_updateStatus('Erreur de connexion');
await Future.delayed(Duration(seconds: 2));
if (mounted) {
Navigator.of(
context,
).pushReplacement(MaterialPageRoute(builder: (context) => LoginPage()));
}
}
}
void _showConnectionError() {
if (mounted) {
showDialog(
context: context,
barrierDismissible: false,
builder:
(context) => AlertDialog(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
),
title: Row(
children: [
Icon(Icons.warning, color: Colors.orange),
SizedBox(width: 8),
Text('Connexion API'),
],
),
content: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Impossible de se connecter au serveur Flask.\n',
style: TextStyle(fontWeight: FontWeight.w500),
),
Text('Vérifiez que :'),
SizedBox(height: 8),
Text('• Le serveur Flask est démarré'),
Text('• MongoDB fonctionne'),
Text('• L\'URL API est correcte'),
Text('• Votre connexion réseau'),
SizedBox(height: 12),
Container(
padding: EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.grey.shade100,
borderRadius: BorderRadius.circular(8),
),
child: Text(
'Vous pouvez continuer en mode hors ligne avec des données de démonstration.',
style: TextStyle(
fontSize: 13,
color: Colors.grey.shade700,
),
),
),
],
),
actions: [
TextButton(
onPressed: () {
Navigator.of(context).pop();
_checkAuthStatus(); // Réessayer
},
child: Text('Réessayer'),
),
ElevatedButton(
onPressed: () {
Navigator.of(context).pop();
Navigator.of(context).pushReplacement(
MaterialPageRoute(builder: (context) => LoginPage()),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: primaryColor,
),
child: Text(
'Continuer',
style: TextStyle(color: Colors.white),
),
),
],
),
);
}
}
@override
void dispose() {
_logoController.dispose();
_textController.dispose();
_loadingController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Container(
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topLeft,
end: Alignment.bottomRight,
colors: [
primaryColor,
primaryColor.withOpacity(0.8),
secondaryColor,
],
stops: [0.0, 0.6, 1.0],
),
),
child: SafeArea(
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Spacer(flex: 2),
// Logo principal animé
_buildAnimatedLogo(),
SizedBox(height: 40),
// Texte principal animé
_buildAnimatedText(),
Spacer(flex: 2),
// Section loading avec statut API
_buildLoadingSection(),
SizedBox(height: 60),
],
),
),
),
),
);
}
Widget _buildAnimatedLogo() {
return AnimatedBuilder(
animation: _logoController,
builder: (context, child) {
return SlideTransition(
position: _logoSlideAnimation,
child: FadeTransition(
opacity: _logoFadeAnimation,
child: Transform.scale(
scale: _logoScaleAnimation.value,
child: WortisLogoWidget(
size: 130,
isWhite: true, // Logo blanc pour le fond bleu
withShadow: true,
),
),
),
);
},
);
}
Widget _buildAnimatedText() {
return AnimatedBuilder(
animation: _textController,
builder: (context, child) {
return SlideTransition(
position: _textSlideAnimation,
child: FadeTransition(
opacity: _textFadeAnimation,
child: Column(
children: [
Text(
'WORTIS',
style: TextStyle(
fontSize: 42,
fontWeight: FontWeight.bold,
color: Colors.white,
letterSpacing: 8,
shadows: [
Shadow(
offset: Offset(0, 3),
blurRadius: 6,
color: Colors.black.withOpacity(0.4),
),
],
),
),
SizedBox(height: 12),
Text(
'Réseau Commercial',
style: TextStyle(
fontSize: 18,
color: Colors.white.withOpacity(0.9),
letterSpacing: 3,
fontWeight: FontWeight.w300,
shadows: [
Shadow(
offset: Offset(0, 1),
blurRadius: 3,
color: Colors.black.withOpacity(0.3),
),
],
),
),
SizedBox(height: 8),
Container(
padding: EdgeInsets.symmetric(horizontal: 16, vertical: 6),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: Colors.white.withOpacity(0.3),
width: 1,
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
_hasApiConnection ? Icons.cloud_done : Icons.cloud_off,
color: Colors.white.withOpacity(0.8),
size: 14,
),
SizedBox(width: 6),
Text(
'Agent Mobile App v1.0',
style: TextStyle(
fontSize: 13,
color: Colors.white.withOpacity(0.8),
letterSpacing: 1,
fontWeight: FontWeight.w400,
),
),
],
),
),
],
),
),
);
},
);
}
Widget _buildLoadingSection() {
return AnimatedBuilder(
animation: _loadingController,
builder: (context, child) {
return FadeTransition(
opacity: _loadingFadeAnimation,
child: Column(
children: [
Stack(
alignment: Alignment.center,
children: [
SizedBox(
width: 50,
height: 50,
child: CircularProgressIndicator(
strokeWidth: 3,
valueColor: AlwaysStoppedAnimation<Color>(
Colors.white.withOpacity(0.8),
),
backgroundColor: Colors.white.withOpacity(0.2),
),
),
Container(
width: 8,
height: 8,
decoration: BoxDecoration(
color: _hasApiConnection ? Colors.green : Colors.orange,
shape: BoxShape.circle,
),
),
],
),
SizedBox(height: 20),
// Message de statut dynamique
Text(
_statusMessage,
style: TextStyle(
fontSize: 16,
color: Colors.white.withOpacity(0.9),
fontWeight: FontWeight.w300,
letterSpacing: 1,
),
),
SizedBox(height: 8),
Text(
'Initialisation de votre espace agent',
style: TextStyle(
fontSize: 12,
color: Colors.white.withOpacity(0.7),
fontWeight: FontWeight.w300,
),
),
if (!_hasApiConnection &&
_statusMessage.contains('hors ligne')) ...[
SizedBox(height: 12),
Container(
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: Colors.orange.withOpacity(0.2),
borderRadius: BorderRadius.circular(16),
border: Border.all(color: Colors.orange.withOpacity(0.3)),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
Icons.wifi_off,
color: Colors.white.withOpacity(0.8),
size: 14,
),
SizedBox(width: 6),
Text(
'Mode démo',
style: TextStyle(
fontSize: 12,
color: Colors.white.withOpacity(0.8),
),
),
],
),
),
],
],
),
);
},
);
}
}