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,160 @@
/// BLoC pour la gestion des paramètres système (Clean Architecture)
library system_settings_bloc;
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:injectable/injectable.dart';
import '../../domain/usecases/get_settings.dart';
import '../../domain/usecases/update_settings.dart';
import '../../domain/usecases/get_cache_stats.dart';
import '../../domain/usecases/clear_cache.dart' as uc;
import '../../domain/usecases/reset_settings.dart';
import '../../domain/repositories/system_config_repository.dart';
import 'system_settings_event.dart';
import 'system_settings_state.dart';
@injectable
class SystemSettingsBloc extends Bloc<SystemSettingsEvent, SystemSettingsState> {
final GetSettings _getSettings;
final UpdateSettings _updateSettings;
final GetCacheStats _getCacheStats;
final uc.ClearCache _clearCache;
final ResetSettings _resetSettings;
final ISystemConfigRepository _repository; // Pour méthodes non-couvertes (metrics, test DB, test email)
SystemSettingsBloc(
this._getSettings,
this._updateSettings,
this._getCacheStats,
this._clearCache,
this._resetSettings,
this._repository,
) : super(SystemSettingsInitial()) {
on<LoadSystemConfig>(_onLoadSystemConfig);
on<UpdateSystemConfig>(_onUpdateSystemConfig);
on<LoadCacheStats>(_onLoadCacheStats);
on<LoadSystemMetrics>(_onLoadSystemMetrics);
on<ClearCache>(_onClearCache);
on<TestDatabaseConnection>(_onTestDatabaseConnection);
on<TestEmailConfiguration>(_onTestEmailConfiguration);
on<ResetSystemConfig>(_onResetSystemConfig);
}
Future<void> _onLoadSystemConfig(
LoadSystemConfig event,
Emitter<SystemSettingsState> emit,
) async {
emit(SystemSettingsLoading());
try {
final config = await _getSettings(); // ✅ Use case
emit(SystemConfigLoaded(config));
} catch (e) {
emit(SystemSettingsError('Erreur de chargement: ${e.toString()}'));
}
}
Future<void> _onUpdateSystemConfig(
UpdateSystemConfig event,
Emitter<SystemSettingsState> emit,
) async {
emit(SystemSettingsLoading());
try {
final config = await _updateSettings(event.config); // ✅ Use case
emit(SystemConfigLoaded(config));
emit(const SystemSettingsSuccess('Configuration mise à jour'));
} catch (e) {
emit(SystemSettingsError('Erreur de mise à jour: ${e.toString()}'));
}
}
Future<void> _onLoadCacheStats(
LoadCacheStats event,
Emitter<SystemSettingsState> emit,
) async {
emit(SystemSettingsLoading());
try {
final stats = await _getCacheStats(); // ✅ Use case
emit(CacheStatsLoaded(stats));
} catch (e) {
emit(SystemSettingsError('Erreur de chargement: ${e.toString()}'));
}
}
Future<void> _onLoadSystemMetrics(
LoadSystemMetrics event,
Emitter<SystemSettingsState> emit,
) async {
emit(SystemSettingsLoading());
try {
final metrics = await _repository.getMetrics();
emit(SystemMetricsLoaded(metrics));
} catch (e) {
emit(SystemSettingsError('Erreur de chargement des métriques: ${e.toString()}'));
}
}
Future<void> _onClearCache(
ClearCache event,
Emitter<SystemSettingsState> emit,
) async {
emit(SystemSettingsLoading());
try {
await _clearCache(); // ✅ Use case
emit(const SystemSettingsSuccess('Cache vidé avec succès'));
} catch (e) {
emit(SystemSettingsError('Erreur: ${e.toString()}'));
}
}
Future<void> _onTestDatabaseConnection(
TestDatabaseConnection event,
Emitter<SystemSettingsState> emit,
) async {
emit(SystemSettingsLoading());
try {
final result = await _repository.testDatabase();
final success = result['success'] as bool? ?? false;
final message = result['message'] as String? ?? 'Test terminé';
if (success) {
emit(SystemSettingsSuccess(message));
} else {
emit(SystemSettingsError(message));
}
} catch (e) {
emit(SystemSettingsError('Erreur de test: ${e.toString()}'));
}
}
Future<void> _onTestEmailConfiguration(
TestEmailConfiguration event,
Emitter<SystemSettingsState> emit,
) async {
emit(SystemSettingsLoading());
try {
final result = await _repository.testEmail();
final success = result['success'] as bool? ?? false;
final message = result['message'] as String? ?? 'Test terminé';
if (success) {
emit(SystemSettingsSuccess(message));
} else {
emit(SystemSettingsError(message));
}
} catch (e) {
emit(SystemSettingsError('Erreur de test: ${e.toString()}'));
}
}
/// Réinitialise la configuration système aux valeurs par défaut
Future<void> _onResetSystemConfig(
ResetSystemConfig event,
Emitter<SystemSettingsState> emit,
) async {
emit(SystemSettingsLoading());
try {
final config = await _resetSettings(); // ✅ Use case
emit(SystemConfigLoaded(config));
emit(const SystemSettingsSuccess('Configuration réinitialisée'));
} catch (e) {
emit(SystemSettingsError('Erreur de réinitialisation: ${e.toString()}'));
}
}
}

View File

@@ -0,0 +1,34 @@
/// Events pour SystemSettingsBloc
library system_settings_event;
import 'package:equatable/equatable.dart';
abstract class SystemSettingsEvent extends Equatable {
const SystemSettingsEvent();
@override
List<Object?> get props => [];
}
class LoadSystemConfig extends SystemSettingsEvent {}
class UpdateSystemConfig extends SystemSettingsEvent {
final Map<String, dynamic> config;
const UpdateSystemConfig(this.config);
@override
List<Object?> get props => [config];
}
class LoadCacheStats extends SystemSettingsEvent {}
class LoadSystemMetrics extends SystemSettingsEvent {}
class ClearCache extends SystemSettingsEvent {}
class TestDatabaseConnection extends SystemSettingsEvent {}
class TestEmailConfiguration extends SystemSettingsEvent {}
class ResetSystemConfig extends SystemSettingsEvent {}

View File

@@ -0,0 +1,63 @@
/// States pour SystemSettingsBloc
library system_settings_state;
import 'package:equatable/equatable.dart';
import '../../data/models/system_config_model.dart';
import '../../data/models/cache_stats_model.dart';
import '../../data/models/system_metrics_model.dart';
abstract class SystemSettingsState extends Equatable {
const SystemSettingsState();
@override
List<Object?> get props => [];
}
class SystemSettingsInitial extends SystemSettingsState {}
class SystemSettingsLoading extends SystemSettingsState {}
class SystemConfigLoaded extends SystemSettingsState {
final SystemConfigModel config;
const SystemConfigLoaded(this.config);
@override
List<Object?> get props => [config];
}
class CacheStatsLoaded extends SystemSettingsState {
final CacheStatsModel stats;
const CacheStatsLoaded(this.stats);
@override
List<Object?> get props => [stats];
}
class SystemMetricsLoaded extends SystemSettingsState {
final SystemMetricsModel metrics;
const SystemMetricsLoaded(this.metrics);
@override
List<Object?> get props => [metrics];
}
class SystemSettingsSuccess extends SystemSettingsState {
final String message;
const SystemSettingsSuccess(this.message);
@override
List<Object?> get props => [message];
}
class SystemSettingsError extends SystemSettingsState {
final String error;
const SystemSettingsError(this.error);
@override
List<Object?> get props => [error];
}

View File

@@ -0,0 +1,345 @@
/// Page dédiée à l'envoi de commentaires / feedback
/// Permet de soumettre des suggestions, signaler des bugs, ou proposer des idées
library feedback_page;
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:dio/dio.dart';
import '../../../../core/utils/logger.dart';
import '../../../../shared/design_system/unionflow_design_system.dart';
class FeedbackPage extends StatefulWidget {
const FeedbackPage({super.key});
@override
State<FeedbackPage> createState() => _FeedbackPageState();
}
class _FeedbackPageState extends State<FeedbackPage> {
final _messageController = TextEditingController();
String _selectedCategory = 'suggestion';
bool _isSending = false;
static const _categories = [
_FeedbackCategory('suggestion', 'Suggestion', Icons.lightbulb, Color(0xFF6C5CE7)),
_FeedbackCategory('bug', 'Bug / Problème', Icons.bug_report, Color(0xFFE17055)),
_FeedbackCategory('amelioration', 'Amélioration', Icons.trending_up, Color(0xFF00B894)),
_FeedbackCategory('autre', 'Autre', Icons.help_outline, Color(0xFF0984E3)),
];
@override
void dispose() {
_messageController.dispose();
super.dispose();
}
Future<void> _submitFeedback() async {
final message = _messageController.text.trim();
if (message.isEmpty) {
_showSnackBar('Veuillez saisir un message.', isError: true);
return;
}
setState(() => _isSending = true);
try {
await GetIt.I<Dio>().post(
'/api/feedback',
data: {
'subject': 'Feedback mobile [$_selectedCategory]',
'message': message,
'categorie': _selectedCategory,
},
);
if (mounted) {
_messageController.clear();
_showSnackBar('Merci pour votre retour !');
}
} catch (e, st) {
AppLogger.error('FeedbackPage: envoi feedback échoué', error: e, stackTrace: st);
if (mounted) {
_showSnackBar('Envoi échoué. Réessayez plus tard.', isError: true);
}
} finally {
if (mounted) setState(() => _isSending = false);
}
}
void _showSnackBar(String message, {bool isError = false}) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: isError ? Colors.red : const Color(0xFF00B894),
behavior: SnackBarBehavior.floating,
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF8F9FA),
body: Column(
children: [
_buildHeader(),
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.all(12),
child: Column(
children: [
const SizedBox(height: 16),
_buildCategorySection(),
const SizedBox(height: 16),
_buildMessageSection(),
const SizedBox(height: 16),
_buildSubmitButton(),
const SizedBox(height: 80),
],
),
),
),
],
),
);
}
Widget _buildHeader() {
return Container(
margin: const EdgeInsets.all(SpacingTokens.lg),
padding: const EdgeInsets.all(SpacingTokens.xxl),
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: ColorTokens.primaryGradient,
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(SpacingTokens.xl),
boxShadow: [
BoxShadow(
color: ColorTokens.primary.withOpacity(0.3),
blurRadius: 20,
offset: const Offset(0, 8),
),
],
),
child: SafeArea(
bottom: false,
child: Row(
children: [
IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: const Icon(Icons.arrow_back, color: Colors.white),
),
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
borderRadius: BorderRadius.circular(12),
),
child: const Icon(Icons.feedback, color: Colors.white, size: 24),
),
const SizedBox(width: 16),
const Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Commentaires',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
Text(
'Aidez-nous à améliorer UnionFlow',
style: TextStyle(
fontSize: 14,
color: Colors.white70,
),
),
],
),
),
],
),
),
);
}
Widget _buildCategorySection() {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(Icons.category, color: Colors.grey[600], size: 20),
const SizedBox(width: 8),
Text(
'Type de retour',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.grey[800],
),
),
],
),
const SizedBox(height: 16),
Wrap(
spacing: 10,
runSpacing: 10,
children: _categories.map((cat) => _buildCategoryChip(cat)).toList(),
),
],
),
);
}
Widget _buildCategoryChip(_FeedbackCategory cat) {
final isSelected = _selectedCategory == cat.id;
return InkWell(
onTap: () => setState(() => _selectedCategory = cat.id),
borderRadius: BorderRadius.circular(12),
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
decoration: BoxDecoration(
color: isSelected ? cat.color.withOpacity(0.12) : Colors.grey[50],
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: isSelected ? cat.color.withOpacity(0.5) : Colors.grey[200]!,
width: isSelected ? 1.5 : 1,
),
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(cat.icon, size: 18, color: isSelected ? cat.color : Colors.grey[500]),
const SizedBox(width: 8),
Text(
cat.label,
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.w600,
color: isSelected ? cat.color : Colors.grey[700],
),
),
],
),
),
);
}
Widget _buildMessageSection() {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(Icons.edit_note, color: Colors.grey[600], size: 20),
const SizedBox(width: 8),
Text(
'Votre message',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.grey[800],
),
),
],
),
const SizedBox(height: 16),
TextField(
controller: _messageController,
maxLines: 6,
decoration: InputDecoration(
hintText: 'Décrivez votre suggestion, problème ou idée...',
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: Colors.grey[300]!),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: BorderSide(color: Colors.grey[300]!),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12),
borderSide: const BorderSide(color: ColorTokens.primary, width: 1.5),
),
filled: true,
fillColor: Colors.grey[50],
alignLabelWithHint: true,
),
),
],
),
);
}
Widget _buildSubmitButton() {
return SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: _isSending ? null : _submitFeedback,
icon: _isSending
? const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white),
)
: const Icon(Icons.send, color: Colors.white),
label: Text(
_isSending ? 'Envoi en cours...' : 'Envoyer le commentaire',
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.white,
),
),
style: ElevatedButton.styleFrom(
backgroundColor: ColorTokens.primary,
padding: const EdgeInsets.symmetric(vertical: 16),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
),
elevation: 2,
),
),
);
}
}
class _FeedbackCategory {
final String id;
final String label;
final IconData icon;
final Color color;
const _FeedbackCategory(this.id, this.label, this.icon, this.color);
}

View File

@@ -0,0 +1,281 @@
/// Page dédiée aux paramètres de langue
/// Permet de changer la langue de l'interface et la région
library language_settings_page;
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../../../../core/l10n/locale_provider.dart';
import '../../../../shared/design_system/unionflow_design_system.dart';
class LanguageSettingsPage extends StatefulWidget {
const LanguageSettingsPage({super.key});
@override
State<LanguageSettingsPage> createState() => _LanguageSettingsPageState();
}
class _LanguageSettingsPageState extends State<LanguageSettingsPage> {
String _selectedLanguage = 'Français';
static const _supportedLanguages = [
_LanguageOption('Français', 'fr', '🇫🇷', 'Langue par défaut'),
_LanguageOption('English', 'en', '🇬🇧', 'Default language'),
];
@override
void didChangeDependencies() {
super.didChangeDependencies();
_syncFromProvider();
}
void _syncFromProvider() {
final lp = context.read<LocaleProvider>();
if (lp.currentLanguageName != _selectedLanguage) {
setState(() => _selectedLanguage = lp.currentLanguageName);
}
}
Future<void> _changeLanguage(String languageName, String code) async {
final lp = context.read<LocaleProvider>();
await lp.setLocale(Locale(code));
if (mounted) {
setState(() => _selectedLanguage = languageName);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('Langue changée en $languageName'),
backgroundColor: const Color(0xFF00B894),
behavior: SnackBarBehavior.floating,
),
);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF8F9FA),
body: Column(
children: [
_buildHeader(),
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.all(12),
child: Column(
children: [
const SizedBox(height: 16),
_buildLanguageList(),
const SizedBox(height: 16),
_buildInfoSection(),
const SizedBox(height: 80),
],
),
),
),
],
),
);
}
Widget _buildHeader() {
return Container(
margin: const EdgeInsets.all(SpacingTokens.lg),
padding: const EdgeInsets.all(SpacingTokens.xxl),
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: ColorTokens.primaryGradient,
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(SpacingTokens.xl),
boxShadow: [
BoxShadow(
color: ColorTokens.primary.withOpacity(0.3),
blurRadius: 20,
offset: const Offset(0, 8),
),
],
),
child: SafeArea(
bottom: false,
child: Row(
children: [
IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: const Icon(Icons.arrow_back, color: Colors.white),
),
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
borderRadius: BorderRadius.circular(12),
),
child: const Icon(Icons.language, color: Colors.white, size: 24),
),
const SizedBox(width: 16),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Langue',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
Text(
'Langue actuelle : $_selectedLanguage',
style: TextStyle(
fontSize: 14,
color: Colors.white.withOpacity(0.8),
),
),
],
),
),
],
),
),
);
}
Widget _buildLanguageList() {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(Icons.translate, color: Colors.grey[600], size: 20),
const SizedBox(width: 8),
Text(
'Langues disponibles',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.grey[800],
),
),
],
),
const SizedBox(height: 16),
..._supportedLanguages.map((lang) => _buildLanguageTile(lang)),
],
),
);
}
Widget _buildLanguageTile(_LanguageOption lang) {
final isSelected = _selectedLanguage == lang.name;
return Padding(
padding: const EdgeInsets.only(bottom: 8),
child: InkWell(
onTap: () => _changeLanguage(lang.name, lang.code),
borderRadius: BorderRadius.circular(12),
child: Container(
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
color: isSelected
? ColorTokens.primary.withOpacity(0.08)
: Colors.grey[50],
borderRadius: BorderRadius.circular(12),
border: isSelected
? Border.all(color: ColorTokens.primary.withOpacity(0.4), width: 1.5)
: Border.all(color: Colors.grey[200]!),
),
child: Row(
children: [
Text(lang.flag, style: const TextStyle(fontSize: 28)),
const SizedBox(width: 14),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
lang.name,
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.w600,
color: isSelected ? ColorTokens.primary : const Color(0xFF1F2937),
),
),
Text(
lang.description,
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
),
],
),
),
if (isSelected)
const Icon(Icons.check_circle, color: ColorTokens.primary, size: 22),
],
),
),
),
);
}
Widget _buildInfoSection() {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(Icons.info_outline, color: Colors.grey[600], size: 20),
const SizedBox(width: 8),
Text(
'Information',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.grey[800],
),
),
],
),
const SizedBox(height: 12),
Text(
'Le changement de langue s\'applique immédiatement à toute l\'interface. '
'Les contenus générés par le serveur restent dans leur langue d\'origine.',
style: TextStyle(fontSize: 13, color: Colors.grey[600], height: 1.5),
),
],
),
);
}
}
class _LanguageOption {
final String name;
final String code;
final String flag;
final String description;
const _LanguageOption(this.name, this.code, this.flag, this.description);
}

View File

@@ -0,0 +1,395 @@
/// Page dédiée aux paramètres de confidentialité
/// Gestion du profil public, partage de données, et suppression de compte
library privacy_settings_page;
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../../../shared/design_system/unionflow_design_system.dart';
class PrivacySettingsPage extends StatefulWidget {
const PrivacySettingsPage({super.key});
@override
State<PrivacySettingsPage> createState() => _PrivacySettingsPageState();
}
class _PrivacySettingsPageState extends State<PrivacySettingsPage> {
bool _profilePublic = false;
bool _shareAnalytics = true;
bool _showOnlineStatus = true;
bool _allowSearchByEmail = true;
static const String _keyProfilePublic = 'profile_public';
static const String _keyShareAnalytics = 'share_analytics';
static const String _keyShowOnlineStatus = 'show_online_status';
static const String _keyAllowSearchByEmail = 'allow_search_by_email';
@override
void initState() {
super.initState();
_loadPreferences();
}
Future<void> _loadPreferences() async {
final prefs = await SharedPreferences.getInstance();
if (mounted) {
setState(() {
_profilePublic = prefs.getBool(_keyProfilePublic) ?? false;
_shareAnalytics = prefs.getBool(_keyShareAnalytics) ?? true;
_showOnlineStatus = prefs.getBool(_keyShowOnlineStatus) ?? true;
_allowSearchByEmail = prefs.getBool(_keyAllowSearchByEmail) ?? true;
});
}
}
Future<void> _savePreference(String key, bool value) async {
final prefs = await SharedPreferences.getInstance();
await prefs.setBool(key, value);
}
void _showSnackBar(String message) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: const Color(0xFF00B894),
behavior: SnackBarBehavior.floating,
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: const Color(0xFFF8F9FA),
body: Column(
children: [
_buildHeader(),
Expanded(
child: SingleChildScrollView(
padding: const EdgeInsets.all(12),
child: Column(
children: [
const SizedBox(height: 16),
_buildVisibilitySection(),
const SizedBox(height: 16),
_buildDataSection(),
const SizedBox(height: 16),
_buildDangerSection(),
const SizedBox(height: 80),
],
),
),
),
],
),
);
}
Widget _buildHeader() {
return Container(
margin: const EdgeInsets.all(SpacingTokens.lg),
padding: const EdgeInsets.all(SpacingTokens.xxl),
decoration: BoxDecoration(
gradient: const LinearGradient(
colors: ColorTokens.primaryGradient,
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
borderRadius: BorderRadius.circular(SpacingTokens.xl),
boxShadow: [
BoxShadow(
color: ColorTokens.primary.withOpacity(0.3),
blurRadius: 20,
offset: const Offset(0, 8),
),
],
),
child: SafeArea(
bottom: false,
child: Row(
children: [
IconButton(
onPressed: () => Navigator.of(context).pop(),
icon: const Icon(Icons.arrow_back, color: Colors.white),
),
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.white.withOpacity(0.2),
borderRadius: BorderRadius.circular(12),
),
child: const Icon(Icons.privacy_tip, color: Colors.white, size: 24),
),
const SizedBox(width: 16),
const Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Confidentialité',
style: TextStyle(
fontSize: 20,
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
Text(
'Contrôler la visibilité de vos données',
style: TextStyle(
fontSize: 14,
color: Colors.white70,
),
),
],
),
),
],
),
),
);
}
Widget _buildVisibilitySection() {
return _buildSection(
'Visibilité du profil',
'Qui peut voir vos informations',
Icons.visibility,
[
_buildSwitchTile(
'Profil public',
'Permettre aux autres membres de voir votre profil',
_profilePublic,
(value) async {
setState(() => _profilePublic = value);
await _savePreference(_keyProfilePublic, value);
_showSnackBar(value ? 'Profil public activé' : 'Profil public désactivé');
},
),
_buildSwitchTile(
'Statut en ligne',
'Afficher quand vous êtes connecté',
_showOnlineStatus,
(value) async {
setState(() => _showOnlineStatus = value);
await _savePreference(_keyShowOnlineStatus, value);
_showSnackBar(value ? 'Statut en ligne visible' : 'Statut en ligne masqué');
},
),
_buildSwitchTile(
'Recherche par email',
'Permettre de vous trouver via votre adresse email',
_allowSearchByEmail,
(value) async {
setState(() => _allowSearchByEmail = value);
await _savePreference(_keyAllowSearchByEmail, value);
_showSnackBar(value ? 'Recherche par email activée' : 'Recherche par email désactivée');
},
),
],
);
}
Widget _buildDataSection() {
return _buildSection(
'Données et analyses',
'Utilisation de vos données',
Icons.analytics,
[
_buildSwitchTile(
'Partage de données anonymes',
'Aider à améliorer l\'application avec des statistiques d\'usage anonymisées',
_shareAnalytics,
(value) async {
setState(() => _shareAnalytics = value);
await _savePreference(_keyShareAnalytics, value);
_showSnackBar(value ? 'Partage de données activé' : 'Partage de données désactivé');
},
),
],
);
}
Widget _buildDangerSection() {
return _buildSection(
'Zone sensible',
'Actions irréversibles',
Icons.warning_amber,
[
InkWell(
onTap: _showDeleteAccountDialog,
borderRadius: BorderRadius.circular(12),
child: Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.red.withOpacity(0.05),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.red.withOpacity(0.2)),
),
child: Row(
children: [
const Icon(Icons.delete_forever, color: Colors.red, size: 20),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'Supprimer mon compte',
style: TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Colors.red,
),
),
Text(
'Supprimer définitivement toutes vos données',
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
),
],
),
),
Icon(Icons.arrow_forward_ios, color: Colors.grey[400], size: 16),
],
),
),
),
],
);
}
void _showDeleteAccountDialog() {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Row(
children: [
Icon(Icons.warning, color: Colors.red),
SizedBox(width: 8),
Text('Supprimer le compte'),
],
),
content: const Text(
'Cette action est irréversible. Toutes vos données seront supprimées définitivement.\n\n'
'Pour confirmer, veuillez contacter l\'administrateur de votre organisation.',
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Annuler'),
),
ElevatedButton(
onPressed: () async {
Navigator.of(context).pop();
final uri = Uri.parse('mailto:support@unionflow.com?subject=Demande de suppression de compte');
if (await canLaunchUrl(uri)) {
await launchUrl(uri, mode: LaunchMode.externalApplication);
}
},
style: ElevatedButton.styleFrom(backgroundColor: Colors.red),
child: const Text('Contacter l\'administrateur', style: TextStyle(color: Colors.white)),
),
],
),
);
}
Widget _buildSection(String title, String subtitle, IconData icon, List<Widget> children) {
return Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(16),
boxShadow: [
BoxShadow(
color: Colors.black.withOpacity(0.05),
blurRadius: 10,
offset: const Offset(0, 2),
),
],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Icon(icon, color: Colors.grey[600], size: 20),
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
color: Colors.grey[800],
),
),
Text(
subtitle,
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
),
],
),
),
],
),
const SizedBox(height: 16),
...children.map((child) => Padding(
padding: const EdgeInsets.only(bottom: 12),
child: child,
)),
],
),
);
}
Widget _buildSwitchTile(
String title,
String subtitle,
bool value,
ValueChanged<bool> onChanged,
) {
return Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: Colors.grey[50],
borderRadius: BorderRadius.circular(12),
),
child: Row(
children: [
const Icon(Icons.toggle_on, color: ColorTokens.primary, size: 20),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w600,
color: Color(0xFF1F2937),
),
),
Text(
subtitle,
style: TextStyle(fontSize: 12, color: Colors.grey[600]),
),
],
),
),
Switch(
value: value,
onChanged: onChanged,
activeTrackColor: ColorTokens.primary,
thumbColor: WidgetStateProperty.resolveWith((states) =>
states.contains(WidgetState.selected) ? Colors.white : null),
),
],
),
);
}
}

File diff suppressed because it is too large Load Diff