Enhance model and service documentation with detailed comments and descriptions
- Updated Group, Trip, User, and other model classes to include comprehensive documentation for better understanding and maintainability. - Improved error handling and logging in services, including AuthService, ErrorService, and StorageService. - Added validation and business logic explanations in ExpenseService and TripService. - Refactored method comments to follow a consistent format across the codebase. - Translated error messages and comments from French to English for consistency.
This commit is contained in:
@@ -1,18 +1,40 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../components/error/error_content.dart';
|
||||
|
||||
/// Service for handling application errors and user notifications.
|
||||
///
|
||||
/// This singleton service provides centralized error handling capabilities
|
||||
/// including displaying error dialogs, snackbars, and logging errors for
|
||||
/// debugging purposes. It uses a global navigator key to show notifications
|
||||
/// from anywhere in the application.
|
||||
class ErrorService {
|
||||
static final ErrorService _instance = ErrorService._internal();
|
||||
|
||||
/// Factory constructor that returns the singleton instance.
|
||||
factory ErrorService() => _instance;
|
||||
|
||||
/// Private constructor for singleton pattern.
|
||||
ErrorService._internal();
|
||||
|
||||
// GlobalKey pour accéder au context depuis n'importe où
|
||||
/// Global navigator key for accessing context from anywhere in the app.
|
||||
///
|
||||
/// This key should be assigned to the MaterialApp's navigatorKey property
|
||||
/// to enable error notifications from any part of the application.
|
||||
static GlobalKey<NavigatorState> navigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
// Afficher une erreur en dialog
|
||||
/// Displays an error message in a dialog.
|
||||
///
|
||||
/// Shows a modal dialog with the error message and optional retry functionality.
|
||||
/// The dialog appearance can be customized with different icons and colors.
|
||||
///
|
||||
/// [message] - The error message to display
|
||||
/// [title] - The dialog title (defaults to 'Error')
|
||||
/// [onRetry] - Optional callback for retry functionality
|
||||
/// [icon] - Icon to display in the dialog
|
||||
/// [iconColor] - Color of the icon
|
||||
void showError({
|
||||
required String message,
|
||||
String title = 'Erreur',
|
||||
String title = 'Error',
|
||||
VoidCallback? onRetry,
|
||||
IconData icon = Icons.error_outline,
|
||||
Color? iconColor,
|
||||
@@ -30,7 +52,14 @@ class ErrorService {
|
||||
}
|
||||
}
|
||||
|
||||
// Afficher une erreur en snackbar
|
||||
/// Displays an error or success message in a snackbar.
|
||||
///
|
||||
/// Shows a floating snackbar at the bottom of the screen with the message.
|
||||
/// The appearance changes based on whether it's an error or success message.
|
||||
///
|
||||
/// [message] - The message to display
|
||||
/// [onRetry] - Optional callback for retry functionality
|
||||
/// [isError] - Whether this is an error (true) or success (false) message
|
||||
void showSnackbar({
|
||||
required String message,
|
||||
VoidCallback? onRetry,
|
||||
@@ -45,7 +74,7 @@ class ErrorService {
|
||||
duration: const Duration(seconds: 4),
|
||||
action: onRetry != null
|
||||
? SnackBarAction(
|
||||
label: 'Réessayer',
|
||||
label: 'Retry',
|
||||
textColor: Colors.white,
|
||||
onPressed: onRetry,
|
||||
)
|
||||
@@ -59,10 +88,17 @@ class ErrorService {
|
||||
}
|
||||
}
|
||||
|
||||
// Logger dans la console (développement)
|
||||
/// Logs error messages to the console during development.
|
||||
///
|
||||
/// Formats and displays error information including source, error message,
|
||||
/// and optional stack trace in a visually distinct format.
|
||||
///
|
||||
/// [source] - The source or location where the error occurred
|
||||
/// [error] - The error object or message
|
||||
/// [stackTrace] - Optional stack trace for debugging
|
||||
void logError(String source, dynamic error, [StackTrace? stackTrace]) {
|
||||
print('═══════════════════════════════════');
|
||||
print('❌ ERREUR dans $source');
|
||||
print('❌ ERROR in $source');
|
||||
print('Message: $error');
|
||||
if (stackTrace != null) {
|
||||
print('StackTrace: $stackTrace');
|
||||
@@ -70,12 +106,18 @@ class ErrorService {
|
||||
print('═══════════════════════════════════');
|
||||
}
|
||||
|
||||
// Logger une info (développement)
|
||||
/// Logs informational messages to the console during development.
|
||||
///
|
||||
/// [source] - The source or location of the information
|
||||
/// [message] - The informational message
|
||||
void logInfo(String source, String message) {
|
||||
print('ℹ️ [$source] $message');
|
||||
}
|
||||
|
||||
// Logger un succès
|
||||
/// Logs success messages to the console during development.
|
||||
///
|
||||
/// [source] - The source or location of the success
|
||||
/// [message] - The success message
|
||||
void logSuccess(String source, String message) {
|
||||
print('✅ [$source] $message');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user