feat: Add logger service and improve expense dialog with enhanced receipt management and calculation logic.

This commit is contained in:
Van Leemput Dayron
2025-11-28 12:54:54 +01:00
parent cad9d42128
commit fd710b8cb8
35 changed files with 2148 additions and 1296 deletions

View File

@@ -1,32 +1,33 @@
import 'package:flutter/material.dart';
import '../components/error/error_content.dart';
import 'logger_service.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();
/// 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>();
/// 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
@@ -53,10 +54,10 @@ class ErrorService {
}
/// 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
@@ -89,36 +90,35 @@ class ErrorService {
}
/// 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('❌ ERROR in $source');
print('Message: $error');
if (stackTrace != null) {
print('StackTrace: $stackTrace');
}
print('═══════════════════════════════════');
LoggerService.error(
'❌ ERROR in $source\nMessage: $error',
name: source,
error: error,
stackTrace: stackTrace,
);
}
/// 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');
LoggerService.info(' $message', name: source);
}
/// 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');
LoggerService.info('$message', name: source);
}
}
}