refactoring
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
/// BLoC pour la gestion des sauvegardes
|
||||
library backup_bloc;
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
@@ -105,6 +106,7 @@ class BackupBloc extends Bloc<BackupEvent, BackupState> {
|
||||
final backups = await _repository.getAll();
|
||||
emit(BackupsLoaded(backups));
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(BackupError('Erreur: ${e.toString()}'));
|
||||
}
|
||||
}
|
||||
@@ -117,6 +119,7 @@ class BackupBloc extends Bloc<BackupEvent, BackupState> {
|
||||
emit(BackupsLoaded(backups));
|
||||
emit(BackupSuccess('Sauvegarde créée'));
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(BackupError('Erreur: ${e.toString()}'));
|
||||
}
|
||||
}
|
||||
@@ -127,6 +130,7 @@ class BackupBloc extends Bloc<BackupEvent, BackupState> {
|
||||
await _repository.restore(event.backupId);
|
||||
emit(BackupSuccess('Restauration en cours'));
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(BackupError('Erreur: ${e.toString()}'));
|
||||
}
|
||||
}
|
||||
@@ -139,6 +143,7 @@ class BackupBloc extends Bloc<BackupEvent, BackupState> {
|
||||
emit(BackupsLoaded(backups));
|
||||
emit(BackupSuccess('Sauvegarde supprimée'));
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(BackupError('Erreur: ${e.toString()}'));
|
||||
}
|
||||
}
|
||||
@@ -149,6 +154,7 @@ class BackupBloc extends Bloc<BackupEvent, BackupState> {
|
||||
final config = await _repository.getConfig();
|
||||
emit(BackupConfigLoaded(config));
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(BackupError('Erreur: ${e.toString()}'));
|
||||
}
|
||||
}
|
||||
@@ -160,6 +166,7 @@ class BackupBloc extends Bloc<BackupEvent, BackupState> {
|
||||
emit(BackupConfigLoaded(config));
|
||||
emit(BackupSuccess('Configuration mise à jour'));
|
||||
} catch (e) {
|
||||
if (e is DioException && e.type == DioExceptionType.cancel) return;
|
||||
emit(BackupError('Erreur: ${e.toString()}'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import '../../../../shared/design_system/tokens/app_colors.dart';
|
||||
import '../../../../shared/design_system/tokens/color_tokens.dart';
|
||||
import '../../../../shared/design_system/tokens/spacing_tokens.dart';
|
||||
import '../../../../core/di/injection_container.dart';
|
||||
@@ -65,7 +66,7 @@ class _BackupPageState extends State<BackupPage>
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.message),
|
||||
backgroundColor: const Color(0xFF00B894),
|
||||
backgroundColor: AppColors.success,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
@@ -73,7 +74,7 @@ class _BackupPageState extends State<BackupPage>
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(state.error),
|
||||
backgroundColor: const Color(0xFFD63031),
|
||||
backgroundColor: AppColors.error,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
),
|
||||
);
|
||||
@@ -81,7 +82,7 @@ class _BackupPageState extends State<BackupPage>
|
||||
},
|
||||
builder: (context, state) {
|
||||
return Scaffold(
|
||||
backgroundColor: ColorTokens.background,
|
||||
backgroundColor: AppColors.lightBackground,
|
||||
body: Column(
|
||||
children: [
|
||||
_buildHeader(),
|
||||
@@ -107,8 +108,8 @@ class _BackupPageState extends State<BackupPage>
|
||||
/// Header harmonisé
|
||||
Widget _buildHeader() {
|
||||
return Container(
|
||||
margin: const EdgeInsets.all(SpacingTokens.lg),
|
||||
padding: const EdgeInsets.all(SpacingTokens.xl),
|
||||
margin: const EdgeInsets.symmetric(horizontal: SpacingTokens.sm, vertical: SpacingTokens.xs),
|
||||
padding: const EdgeInsets.all(SpacingTokens.md),
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
colors: ColorTokens.primaryGradient,
|
||||
@@ -129,18 +130,18 @@ class _BackupPageState extends State<BackupPage>
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.backup,
|
||||
color: Colors.white,
|
||||
size: 24,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -314,9 +315,9 @@ class _BackupPageState extends State<BackupPage>
|
||||
),
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
labelColor: const Color(0xFF6C5CE7),
|
||||
labelColor: AppColors.primaryGreen,
|
||||
unselectedLabelColor: Colors.grey[600],
|
||||
indicatorColor: const Color(0xFF6C5CE7),
|
||||
indicatorColor: AppColors.primaryGreen,
|
||||
indicatorWeight: 3,
|
||||
labelStyle: const TextStyle(fontWeight: FontWeight.w600, fontSize: 12),
|
||||
tabs: const [
|
||||
@@ -334,7 +335,7 @@ class _BackupPageState extends State<BackupPage>
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
children: [
|
||||
const SizedBox(height: 16),
|
||||
const SizedBox(height: 8),
|
||||
state is BackupLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: _buildBackupsList(state is BackupsLoaded ? state.backups : (_cachedBackups ?? [])),
|
||||
@@ -372,7 +373,7 @@ class _BackupPageState extends State<BackupPage>
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.folder, color: Color(0xFF6C5CE7), size: 20),
|
||||
const Icon(Icons.folder, color: AppColors.primaryGreen, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Sauvegardes disponibles',
|
||||
@@ -404,7 +405,7 @@ class _BackupPageState extends State<BackupPage>
|
||||
children: [
|
||||
Icon(
|
||||
backup['type'] == 'Auto' ? Icons.schedule : Icons.touch_app,
|
||||
color: backup['type'] == 'Auto' ? Colors.blue : Colors.green,
|
||||
color: backup['type'] == 'Auto' ? AppColors.primaryGreen : AppColors.success,
|
||||
size: 20,
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
@@ -417,7 +418,7 @@ class _BackupPageState extends State<BackupPage>
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Color(0xFF1F2937),
|
||||
color: AppColors.textPrimaryLight,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
@@ -478,7 +479,7 @@ class _BackupPageState extends State<BackupPage>
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.schedule, color: Color(0xFF6C5CE7), size: 20),
|
||||
const Icon(Icons.schedule, color: AppColors.primaryGreen, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Configuration automatique',
|
||||
@@ -550,7 +551,7 @@ class _BackupPageState extends State<BackupPage>
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.restore, color: Color(0xFF6C5CE7), size: 20),
|
||||
const Icon(Icons.restore, color: AppColors.primaryGreen, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Options de restauration',
|
||||
@@ -567,7 +568,7 @@ class _BackupPageState extends State<BackupPage>
|
||||
'Restaurer depuis un fichier',
|
||||
'Importer une sauvegarde externe',
|
||||
Icons.file_upload,
|
||||
const Color(0xFF0984E3),
|
||||
AppColors.primaryGreen,
|
||||
() => _restoreFromFile(),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
@@ -575,7 +576,7 @@ class _BackupPageState extends State<BackupPage>
|
||||
'Restauration sélective',
|
||||
'Restaurer uniquement certaines données',
|
||||
Icons.checklist,
|
||||
const Color(0xFF00B894),
|
||||
AppColors.success,
|
||||
() => _selectiveRestore(),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
@@ -583,7 +584,7 @@ class _BackupPageState extends State<BackupPage>
|
||||
'Point de restauration',
|
||||
'Créer un point de restauration avant modification',
|
||||
Icons.bookmark,
|
||||
const Color(0xFFE17055),
|
||||
AppColors.warning,
|
||||
() => _createRestorePoint(),
|
||||
),
|
||||
],
|
||||
@@ -604,7 +605,7 @@ class _BackupPageState extends State<BackupPage>
|
||||
],
|
||||
),
|
||||
),
|
||||
Switch(value: value, onChanged: onChanged, activeColor: const Color(0xFF6C5CE7)),
|
||||
Switch(value: value, onChanged: onChanged, activeColor: AppColors.primaryGreen),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -708,7 +709,7 @@ class _BackupPageState extends State<BackupPage>
|
||||
AppLogger.error('BackupPage: téléchargement échoué', error: e, stackTrace: st);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Impossible de récupérer la sauvegarde.'), backgroundColor: Color(0xFFD63031)),
|
||||
const SnackBar(content: Text('Impossible de récupérer la sauvegarde.'), backgroundColor: AppColors.error),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -731,7 +732,7 @@ class _BackupPageState extends State<BackupPage>
|
||||
AppLogger.error('BackupPage: restauration depuis fichier', error: e, stackTrace: st);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Sélection de fichier impossible.'), backgroundColor: Color(0xFFD63031)),
|
||||
const SnackBar(content: Text('Sélection de fichier impossible.'), backgroundColor: AppColors.error),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -755,7 +756,7 @@ class _BackupPageState extends State<BackupPage>
|
||||
AppLogger.error('BackupPage: restauration sélective', error: e, stackTrace: st);
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Sélection impossible.'), backgroundColor: Color(0xFFD63031)),
|
||||
const SnackBar(content: Text('Sélection impossible.'), backgroundColor: AppColors.error),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -767,7 +768,7 @@ class _BackupPageState extends State<BackupPage>
|
||||
|
||||
void _showSuccessSnackBar(String message) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(message), backgroundColor: const Color(0xFF00B894), behavior: SnackBarBehavior.floating),
|
||||
SnackBar(content: Text(message), backgroundColor: AppColors.success, behavior: SnackBarBehavior.floating),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user