Initial commit: unionflow-mobile-apps

Application Flutter complète (sans build artifacts).

Signed-off-by: lions dev Team
This commit is contained in:
dahoud
2026-03-15 16:30:08 +00:00
commit d094d6db9c
1790 changed files with 507435 additions and 0 deletions

View File

@@ -0,0 +1,256 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:intl/intl.dart';
import '../../../../shared/design_system/unionflow_design_system.dart';
import '../../../../shared/widgets/core_card.dart';
import '../../../../shared/widgets/info_badge.dart';
import '../../../../shared/widgets/mini_avatar.dart';
import '../../bloc/solidarity_bloc.dart';
import '../../data/models/demande_aide_model.dart';
import '../../../authentication/presentation/bloc/auth_bloc.dart';
class DemandeAideDetailPage extends StatefulWidget {
final String demandeId;
const DemandeAideDetailPage({super.key, required this.demandeId});
@override
State<DemandeAideDetailPage> createState() => _DemandeAideDetailPageState();
}
class _DemandeAideDetailPageState extends State<DemandeAideDetailPage> {
final _currencyFormat = NumberFormat.currency(locale: 'fr_FR', symbol: 'FCFA');
@override
void initState() {
super.initState();
context.read<SolidarityBloc>().add(LoadDemandeAideById(widget.demandeId));
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: AppColors.background,
appBar: const UFAppBar(
title: 'DÉTAIL DEMANDE',
backgroundColor: AppColors.surface,
foregroundColor: AppColors.textPrimaryLight,
),
body: BlocConsumer<SolidarityBloc, SolidarityState>(
listenWhen: (prev, curr) => prev.status != curr.status,
listener: (context, state) {
if (state.status == SolidarityStatus.error && state.message != null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(state.message!), backgroundColor: Colors.red),
);
}
},
buildWhen: (prev, curr) =>
prev.demandeDetail != curr.demandeDetail || prev.status != curr.status,
builder: (context, state) {
if (state.status == SolidarityStatus.loading && state.demandeDetail == null) {
return const Center(child: CircularProgressIndicator());
}
final d = state.demandeDetail;
if (d == null) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.error_outline, size: 64, color: Colors.grey),
const SizedBox(height: 16),
Text(
'Demande introuvable',
style: Theme.of(context).textTheme.titleMedium,
),
],
),
);
}
return SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_InfoCard(title: 'Référence', value: d.numeroReference ?? d.id ?? ''),
_InfoCard(title: 'Statut', value: d.statutLibelle),
_InfoCard(title: 'Titre', value: d.titre ?? ''),
if (d.type != null) _InfoCard(title: 'Type', value: d.typeLibelle),
if (d.description != null && d.description!.isNotEmpty)
_InfoCard(title: 'Description', value: d.description!),
if (d.montantDemande != null && d.montantDemande! > 0)
_InfoCard(
title: 'Montant demandé',
value: _currencyFormat.format(d.montantDemande!),
),
if (d.montantAccorde != null && d.montantAccorde! > 0)
_InfoCard(
title: 'Montant accordé',
value: _currencyFormat.format(d.montantAccorde!),
),
if (d.demandeur != null) _InfoCard(title: 'Demandeur', value: d.demandeur!),
if (d.dateDemande != null)
_InfoCard(
title: 'Date demande',
value: DateFormat('dd/MM/yyyy').format(d.dateDemande!),
),
if (d.motif != null && d.motif!.isNotEmpty)
_InfoCard(title: 'Motif', value: d.motif!),
_ActionsSection(demande: d, isGestionnaire: _isGestionnaire()),
],
),
);
},
),
);
}
bool _isGestionnaire() {
final state = context.read<AuthBloc>().state;
if (state is AuthAuthenticated) {
return state.effectiveRole.level >= 50;
}
return false;
}
}
class _InfoCard extends StatelessWidget {
final String title;
final String value;
final Widget? trail;
const _InfoCard({required this.title, required this.value, this.trail});
@override
Widget build(BuildContext context) {
return CoreCard(
margin: const EdgeInsets.only(bottom: 8),
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title.toUpperCase(),
style: AppTypography.subtitleSmall.copyWith(
fontWeight: FontWeight.bold,
fontSize: 9,
color: AppColors.textSecondaryLight,
),
),
const SizedBox(height: 2),
Text(
value,
style: AppTypography.bodyTextSmall.copyWith(fontSize: 12),
),
],
),
),
if (trail != null) trail!,
],
),
);
}
}
class _ActionsSection extends StatelessWidget {
final DemandeAideModel demande;
final bool isGestionnaire;
const _ActionsSection({required this.demande, required this.isGestionnaire});
@override
Widget build(BuildContext context) {
if (!isGestionnaire) return const SizedBox.shrink();
final bloc = context.read<SolidarityBloc>();
if (demande.statut != 'EN_ATTENTE' && demande.statut != 'SOUMISE') {
return const SizedBox.shrink();
}
if (demande.id == null) return const SizedBox.shrink();
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Text(
'ACTIONS ADMINISTRATIVES',
style: AppTypography.subtitleSmall.copyWith(
fontWeight: FontWeight.bold,
letterSpacing: 1.1,
),
),
),
const SizedBox(height: 8),
Row(
children: [
Expanded(
child: ElevatedButton(
onPressed: () => bloc.add(ApprouverDemandeAide(demande.id!)),
style: ElevatedButton.styleFrom(
backgroundColor: AppColors.success,
foregroundColor: Colors.white,
elevation: 0,
padding: const EdgeInsets.symmetric(vertical: 12),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
),
child: Text('APPROUVER', style: AppTypography.actionText.copyWith(fontSize: 11, color: Colors.white)),
),
),
const SizedBox(width: 12),
Expanded(
child: OutlinedButton(
onPressed: () => _showRejetDialog(context, demande.id!, bloc),
style: OutlinedButton.styleFrom(
foregroundColor: AppColors.error,
side: const BorderSide(color: AppColors.error),
padding: const EdgeInsets.symmetric(vertical: 12),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(4)),
),
child: Text('REJETER', style: AppTypography.actionText.copyWith(fontSize: 11)),
),
),
],
),
],
);
}
void _showRejetDialog(BuildContext context, String demandeId, SolidarityBloc bloc) {
final motifController = TextEditingController();
showDialog<void>(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('Rejeter la demande'),
content: TextField(
controller: motifController,
decoration: const InputDecoration(
labelText: 'Motif du rejet (recommandé pour traçabilité)',
hintText: 'Saisir le motif...',
border: OutlineInputBorder(),
),
maxLines: 3,
autofocus: true,
),
actions: [
TextButton(
onPressed: () => Navigator.pop(ctx),
child: const Text('Annuler'),
),
FilledButton(
onPressed: () {
final motif = motifController.text.trim();
Navigator.pop(ctx);
bloc.add(RejeterDemandeAide(demandeId, motif: motif.isNotEmpty ? motif : null));
},
style: FilledButton.styleFrom(backgroundColor: AppColors.error),
child: const Text('Rejeter'),
),
],
),
);
}
}

View File

@@ -0,0 +1,257 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:intl/intl.dart';
import '../../../../shared/design_system/unionflow_design_system.dart';
import '../../../../shared/widgets/core_card.dart';
import '../../../../shared/widgets/info_badge.dart';
import '../../../../shared/widgets/mini_avatar.dart';
import '../../bloc/solidarity_bloc.dart';
import '../../data/models/demande_aide_model.dart';
import 'demande_aide_detail_page.dart';
import '../widgets/create_demande_aide_dialog.dart';
import '../../../authentication/presentation/bloc/auth_bloc.dart';
/// Page liste des demandes d'aide (solidarité) - Version Épurée
class DemandesAidePage extends StatefulWidget {
const DemandesAidePage({super.key});
@override
State<DemandesAidePage> createState() => _DemandesAidePageState();
}
class _DemandesAidePageState extends State<DemandesAidePage>
with SingleTickerProviderStateMixin {
late TabController _tabController;
final _currencyFormat = NumberFormat.currency(locale: 'fr_FR', symbol: 'FCFA', decimalDigits: 0);
@override
void initState() {
super.initState();
_tabController = TabController(length: 3, vsync: this);
_loadTab(0);
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
void _loadTab(int index) {
bool isGestionnaire = false;
final authState = context.read<AuthBloc>().state;
if (authState is AuthAuthenticated) {
isGestionnaire = authState.effectiveRole.level >= 50;
}
if (isGestionnaire) {
switch (index) {
case 0:
context.read<SolidarityBloc>().add(const SearchDemandesAide()); // Search sans statut = getAll
break;
case 1:
context.read<SolidarityBloc>().add(const SearchDemandesAide(statut: 'EN_ATTENTE'));
break;
case 2:
context.read<SolidarityBloc>().add(const SearchDemandesAide(statut: 'APPROUVEE'));
break;
}
} else {
// Normal member always fetches their own requests
context.read<SolidarityBloc>().add(const LoadDemandesAide());
}
}
@override
Widget build(BuildContext context) {
return BlocListener<SolidarityBloc, SolidarityState>(
listener: (context, state) {
if (state.status == SolidarityStatus.error && state.message != null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(state.message!,
style: AppTypography.bodyTextSmall.copyWith(color: Colors.white)),
backgroundColor: AppColors.error,
),
);
}
},
child: Scaffold(
backgroundColor: AppColors.background,
appBar: UFAppBar(
title: 'SOLIDARITÉ',
backgroundColor: AppColors.surface,
foregroundColor: AppColors.textPrimaryLight,
bottom: TabBar(
controller: _tabController,
onTap: _loadTab,
labelColor: AppColors.primaryGreen,
unselectedLabelColor: AppColors.textSecondaryLight,
indicatorColor: AppColors.primaryGreen,
indicatorSize: TabBarIndicatorSize.label,
labelStyle: AppTypography.actionText.copyWith(fontSize: 10, fontWeight: FontWeight.bold),
tabs: const [
Tab(child: Text('TOUTES')),
Tab(child: Text('ATTENTE')),
Tab(child: Text('APPROUVÉES')),
],
),
),
body: TabBarView(
controller: _tabController,
children: [
_buildList(null),
_buildList('EN_ATTENTE'),
_buildList('APPROUVEE'),
],
),
),
);
}
Widget _buildList(String? statutFilter) {
return BlocBuilder<SolidarityBloc, SolidarityState>(
buildWhen: (prev, curr) =>
prev.status != curr.status || prev.demandes != curr.demandes,
builder: (context, state) {
if (state.status == SolidarityStatus.loading && state.demandes.isEmpty) {
return const Center(child: CircularProgressIndicator(strokeWidth: 2));
}
var list = state.demandes;
if (statutFilter != null) {
list = list.where((d) => d.statut == statutFilter).toList();
}
if (list.isEmpty) {
return Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.volunteer_activism_outlined, size: 32, color: AppColors.lightBorder),
const SizedBox(height: 12),
Text('Aucune demande', style: AppTypography.subtitleSmall),
],
),
);
}
return RefreshIndicator(
onRefresh: () async => _loadTab(_tabController.index),
child: ListView.builder(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 12),
itemCount: list.length,
itemBuilder: (context, index) {
return _DemandeCard(
demande: list[index],
currencyFormat: _currencyFormat,
onTap: () => _openDetail(list[index]),
);
},
),
);
},
);
}
void _openDetail(DemandeAideModel d) {
if (d.id == null) return;
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => BlocProvider.value(
value: context.read<SolidarityBloc>(),
child: DemandeAideDetailPage(demandeId: d.id!),
),
),
).then((_) => _loadTab(_tabController.index));
}
}
class _DemandeCard extends StatelessWidget {
final DemandeAideModel demande;
final NumberFormat currencyFormat;
final VoidCallback onTap;
const _DemandeCard({
required this.demande,
required this.currencyFormat,
required this.onTap,
});
@override
Widget build(BuildContext context) {
return CoreCard(
margin: const EdgeInsets.only(bottom: 10),
onTap: onTap,
padding: const EdgeInsets.all(12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
const MiniAvatar(size: 24, fallbackText: '?'),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
demande.titre ?? 'Demande sans titre',
style: AppTypography.actionText.copyWith(fontSize: 12),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Text(
demande.numeroReference ?? demande.id?.substring(0, 8) ?? '',
style: AppTypography.subtitleSmall.copyWith(fontSize: 9),
),
],
),
),
_buildStatutBadge(demande.statut),
],
),
const SizedBox(height: 12),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('MONTANT DEMANDÉ', style: AppTypography.subtitleSmall.copyWith(fontSize: 8, fontWeight: FontWeight.bold)),
Text(
currencyFormat.format(demande.montantDemande ?? 0),
style: AppTypography.headerSmall.copyWith(fontSize: 13, color: AppColors.primaryGreen),
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text('TYPE', style: AppTypography.subtitleSmall.copyWith(fontSize: 8, fontWeight: FontWeight.bold)),
Text(demande.typeLibelle, style: AppTypography.bodyTextSmall.copyWith(fontSize: 10)),
],
),
],
),
],
),
);
}
Widget _buildStatutBadge(String? statut) {
Color color;
switch (statut) {
case 'APPROUVEE':
color = AppColors.success;
break;
case 'REJETEE':
color = AppColors.error;
break;
case 'EN_ATTENTE':
case 'SOUMISE':
color = AppColors.brandGreenLight;
break;
default:
color = AppColors.textSecondaryLight;
}
return InfoBadge(text: statut ?? 'INCONNU', backgroundColor: color);
}
}

View File

@@ -0,0 +1,26 @@
/// Wrapper BLoC pour la page des demandes d'aide
library demandes_aide_page_wrapper;
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:get_it/get_it.dart';
import '../../bloc/solidarity_bloc.dart';
import 'demandes_aide_page.dart';
final _getIt = GetIt.instance;
class DemandesAidePageWrapper extends StatelessWidget {
const DemandesAidePageWrapper({super.key});
@override
Widget build(BuildContext context) {
return BlocProvider<SolidarityBloc>(
create: (context) {
final bloc = _getIt<SolidarityBloc>();
bloc.add(const LoadDemandesAide());
return bloc;
},
child: const DemandesAidePage(),
);
}
}