Initial commit: unionflow-mobile-apps
Application Flutter complète (sans build artifacts). Signed-off-by: lions dev Team
This commit is contained in:
125
lib/features/profile/presentation/bloc/profile_bloc.dart
Normal file
125
lib/features/profile/presentation/bloc/profile_bloc.dart
Normal file
@@ -0,0 +1,125 @@
|
||||
/// BLoC pour la gestion du profil utilisateur
|
||||
library profile_bloc;
|
||||
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import '../../domain/usecases/get_profile.dart';
|
||||
import '../../domain/usecases/update_profile.dart';
|
||||
import '../../domain/usecases/update_avatar.dart';
|
||||
import '../../domain/usecases/change_password.dart';
|
||||
import '../../domain/usecases/update_preferences.dart';
|
||||
import '../../domain/usecases/delete_account.dart';
|
||||
import '../../domain/repositories/profile_repository.dart';
|
||||
import '../../../members/data/models/membre_complete_model.dart';
|
||||
|
||||
part 'profile_event.dart';
|
||||
part 'profile_state.dart';
|
||||
|
||||
/// BLoC pour la gestion du profil (Clean Architecture)
|
||||
@injectable
|
||||
class ProfileBloc extends Bloc<ProfileEvent, ProfileState> {
|
||||
final GetProfile _getProfile;
|
||||
final UpdateProfile _updateProfile;
|
||||
final UpdateAvatar _updateAvatar;
|
||||
final ChangePassword _changePassword;
|
||||
final UpdatePreferences _updatePreferences;
|
||||
final DeleteAccount _deleteAccount;
|
||||
final IProfileRepository _repository; // Pour méthodes non-couvertes (getProfileByEmail)
|
||||
|
||||
ProfileBloc(
|
||||
this._getProfile,
|
||||
this._updateProfile,
|
||||
this._updateAvatar,
|
||||
this._changePassword,
|
||||
this._updatePreferences,
|
||||
this._deleteAccount,
|
||||
this._repository,
|
||||
) : super(const ProfileInitial()) {
|
||||
on<LoadMe>(_onLoadMe);
|
||||
on<LoadMyProfile>(_onLoadMyProfile);
|
||||
on<UpdateMyProfile>(_onUpdateMyProfile);
|
||||
}
|
||||
|
||||
/// Charge le profil du membre connecté
|
||||
Future<void> _onLoadMe(
|
||||
LoadMe event,
|
||||
Emitter<ProfileState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(const ProfileLoading());
|
||||
final membre = await _getProfile();
|
||||
if (membre != null) {
|
||||
emit(ProfileLoaded(membre));
|
||||
} else {
|
||||
emit(const ProfileNotFound());
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
emit(ProfileError(_networkErrorMessage(e)));
|
||||
} catch (e) {
|
||||
emit(ProfileError('Erreur lors du chargement du profil : $e'));
|
||||
}
|
||||
}
|
||||
|
||||
/// Charge le profil par email (recherche)
|
||||
/// Note: Cette méthode utilise directement le repository car elle n'a pas de use case dédié
|
||||
Future<void> _onLoadMyProfile(
|
||||
LoadMyProfile event,
|
||||
Emitter<ProfileState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(const ProfileLoading());
|
||||
final membre = await _repository.getProfileByEmail(event.email);
|
||||
if (membre != null) {
|
||||
emit(ProfileLoaded(membre));
|
||||
} else {
|
||||
emit(const ProfileNotFound());
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
emit(ProfileError(_networkErrorMessage(e)));
|
||||
} catch (e) {
|
||||
emit(ProfileError('Erreur lors du chargement du profil : $e'));
|
||||
}
|
||||
}
|
||||
|
||||
/// Met à jour le profil
|
||||
Future<void> _onUpdateMyProfile(
|
||||
UpdateMyProfile event,
|
||||
Emitter<ProfileState> emit,
|
||||
) async {
|
||||
final currentState = state;
|
||||
try {
|
||||
if (currentState is ProfileLoaded) {
|
||||
emit(ProfileUpdating(currentState.membre));
|
||||
}
|
||||
final updated = await _updateProfile(event.membreId, event.membre);
|
||||
emit(ProfileUpdated(updated));
|
||||
} on DioException catch (e) {
|
||||
if (currentState is ProfileLoaded) {
|
||||
emit(ProfileLoaded(currentState.membre));
|
||||
}
|
||||
emit(ProfileError(_networkErrorMessage(e)));
|
||||
} catch (e) {
|
||||
emit(ProfileError('Erreur lors de la mise à jour du profil : $e'));
|
||||
}
|
||||
}
|
||||
|
||||
String _networkErrorMessage(DioException e) {
|
||||
switch (e.type) {
|
||||
case DioExceptionType.connectionTimeout:
|
||||
case DioExceptionType.sendTimeout:
|
||||
case DioExceptionType.receiveTimeout:
|
||||
return 'Délai de connexion dépassé.';
|
||||
case DioExceptionType.badResponse:
|
||||
final code = e.response?.statusCode;
|
||||
if (code == 401) return 'Non autorisé. Veuillez vous reconnecter.';
|
||||
if (code == 403) return 'Accès refusé.';
|
||||
if (code == 404) return 'Profil non trouvé.';
|
||||
if (code != null && code >= 500) return 'Erreur serveur.';
|
||||
return 'Erreur de communication avec le serveur.';
|
||||
default:
|
||||
return 'Erreur réseau. Vérifiez votre connexion.';
|
||||
}
|
||||
}
|
||||
}
|
||||
32
lib/features/profile/presentation/bloc/profile_event.dart
Normal file
32
lib/features/profile/presentation/bloc/profile_event.dart
Normal file
@@ -0,0 +1,32 @@
|
||||
part of 'profile_bloc.dart';
|
||||
|
||||
abstract class ProfileEvent extends Equatable {
|
||||
const ProfileEvent();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
/// Charge le profil du membre connecté (GET /api/membres/me) - prioritaire
|
||||
class LoadMe extends ProfileEvent {
|
||||
const LoadMe();
|
||||
}
|
||||
|
||||
/// Charge le profil par email (recherche) - fallback ou admin
|
||||
class LoadMyProfile extends ProfileEvent {
|
||||
final String email;
|
||||
const LoadMyProfile(this.email);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [email];
|
||||
}
|
||||
|
||||
/// Met à jour le profil
|
||||
class UpdateMyProfile extends ProfileEvent {
|
||||
final String membreId;
|
||||
final MembreCompletModel membre;
|
||||
const UpdateMyProfile({required this.membreId, required this.membre});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [membreId, membre];
|
||||
}
|
||||
52
lib/features/profile/presentation/bloc/profile_state.dart
Normal file
52
lib/features/profile/presentation/bloc/profile_state.dart
Normal file
@@ -0,0 +1,52 @@
|
||||
part of 'profile_bloc.dart';
|
||||
|
||||
abstract class ProfileState extends Equatable {
|
||||
const ProfileState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class ProfileInitial extends ProfileState {
|
||||
const ProfileInitial();
|
||||
}
|
||||
|
||||
class ProfileLoading extends ProfileState {
|
||||
const ProfileLoading();
|
||||
}
|
||||
|
||||
class ProfileLoaded extends ProfileState {
|
||||
final MembreCompletModel membre;
|
||||
const ProfileLoaded(this.membre);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [membre];
|
||||
}
|
||||
|
||||
class ProfileUpdating extends ProfileState {
|
||||
final MembreCompletModel membre;
|
||||
const ProfileUpdating(this.membre);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [membre];
|
||||
}
|
||||
|
||||
class ProfileUpdated extends ProfileState {
|
||||
final MembreCompletModel membre;
|
||||
const ProfileUpdated(this.membre);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [membre];
|
||||
}
|
||||
|
||||
class ProfileError extends ProfileState {
|
||||
final String message;
|
||||
const ProfileError(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
|
||||
class ProfileNotFound extends ProfileState {
|
||||
const ProfileNotFound();
|
||||
}
|
||||
1624
lib/features/profile/presentation/pages/profile_page.dart
Normal file
1624
lib/features/profile/presentation/pages/profile_page.dart
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,20 @@
|
||||
library profile_page_wrapper;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../../../core/di/injection_container.dart';
|
||||
import '../bloc/profile_bloc.dart';
|
||||
import 'profile_page.dart';
|
||||
|
||||
/// Wrapper qui fournit le ProfileBloc à la ProfilePage
|
||||
class ProfilePageWrapper extends StatelessWidget {
|
||||
const ProfilePageWrapper({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocProvider<ProfileBloc>(
|
||||
create: (_) => sl<ProfileBloc>(),
|
||||
child: const ProfilePage(),
|
||||
);
|
||||
}
|
||||
}
|
||||
192
lib/features/profile/presentation/widgets/kyc_status_widget.dart
Normal file
192
lib/features/profile/presentation/widgets/kyc_status_widget.dart
Normal file
@@ -0,0 +1,192 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
import '../../../members/data/models/membre_complete_model.dart';
|
||||
|
||||
/// Widget d'affichage du statut KYC (Know Your Customer) d'un membre.
|
||||
/// Affiche en lecture seule le niveau de vigilance, le statut de vérification,
|
||||
/// et la date de vérification d'identité (conformité LCB-FT).
|
||||
class KycStatusWidget extends StatelessWidget {
|
||||
final NiveauVigilanceKyc? niveauVigilance;
|
||||
final StatutKyc? statutKyc;
|
||||
final DateTime? dateVerification;
|
||||
|
||||
const KycStatusWidget({
|
||||
super.key,
|
||||
this.niveauVigilance,
|
||||
this.statutKyc,
|
||||
this.dateVerification,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final colorScheme = theme.colorScheme;
|
||||
|
||||
return Card(
|
||||
margin: const EdgeInsets.all(16),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.verified_user,
|
||||
color: colorScheme.primary,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Vérification KYC (Anti-blanchiment)',
|
||||
style: theme.textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: colorScheme.primary,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'Conformité LCB-FT (Lutte contre le Blanchiment)',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
fontStyle: FontStyle.italic,
|
||||
),
|
||||
),
|
||||
const Divider(height: 24),
|
||||
_buildInfoRow(
|
||||
context,
|
||||
'Statut de vérification',
|
||||
_getStatutKycLabel(statutKyc),
|
||||
_getStatutKycColor(statutKyc),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow(
|
||||
context,
|
||||
'Niveau de vigilance',
|
||||
_getNiveauVigilanceLabel(niveauVigilance),
|
||||
_getNiveauVigilanceColor(niveauVigilance),
|
||||
),
|
||||
if (dateVerification != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
_buildInfoRow(
|
||||
context,
|
||||
'Date de vérification',
|
||||
DateFormat('dd/MM/yyyy').format(dateVerification!),
|
||||
colorScheme.onSurface,
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 16),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: colorScheme.primaryContainer.withOpacity(0.3),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.info_outline,
|
||||
size: 16,
|
||||
color: colorScheme.primary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Ces informations sont gérées par l\'administrateur et permettent de garantir la conformité aux normes BCEAO/OHADA.',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: colorScheme.onSurface,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInfoRow(
|
||||
BuildContext context,
|
||||
String label,
|
||||
String value,
|
||||
Color valueColor,
|
||||
) {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Text(
|
||||
value,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: valueColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String _getStatutKycLabel(StatutKyc? statut) {
|
||||
if (statut == null) return 'Non renseigné';
|
||||
switch (statut) {
|
||||
case StatutKyc.nonVerifie:
|
||||
return '⏸️ Non vérifié';
|
||||
case StatutKyc.enCours:
|
||||
return '⏳ En cours de vérification';
|
||||
case StatutKyc.verifie:
|
||||
return '✅ Vérifié';
|
||||
case StatutKyc.refuse:
|
||||
return '❌ Refusé';
|
||||
}
|
||||
}
|
||||
|
||||
Color _getStatutKycColor(StatutKyc? statut) {
|
||||
if (statut == null) return Colors.grey;
|
||||
switch (statut) {
|
||||
case StatutKyc.nonVerifie:
|
||||
return Colors.orange;
|
||||
case StatutKyc.enCours:
|
||||
return Colors.blue;
|
||||
case StatutKyc.verifie:
|
||||
return Colors.green;
|
||||
case StatutKyc.refuse:
|
||||
return Colors.red;
|
||||
}
|
||||
}
|
||||
|
||||
String _getNiveauVigilanceLabel(NiveauVigilanceKyc? niveau) {
|
||||
if (niveau == null) return 'Non renseigné';
|
||||
switch (niveau) {
|
||||
case NiveauVigilanceKyc.simplifie:
|
||||
return '🔵 Simplifiée';
|
||||
case NiveauVigilanceKyc.renforce:
|
||||
return '🔴 Renforcée';
|
||||
}
|
||||
}
|
||||
|
||||
Color _getNiveauVigilanceColor(NiveauVigilanceKyc? niveau) {
|
||||
if (niveau == null) return Colors.grey;
|
||||
switch (niveau) {
|
||||
case NiveauVigilanceKyc.simplifie:
|
||||
return Colors.blue;
|
||||
case NiveauVigilanceKyc.renforce:
|
||||
return Colors.deepOrange;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user