refactor: enhance theme and error handling across the application

- Updated error handling in EnhancedErrorService to utilize context for color tokens, improving theme consistency.
- Refactored various components to use context-aware shadow and color properties, enhancing visual coherence.
- Replaced hardcoded color values with dynamic tokens in multiple widgets, ensuring better adaptability to theme changes.
- Improved overall code maintainability by centralizing theme-related logic and reducing direct dependencies on static theme values.
This commit is contained in:
cogwheel0
2025-10-03 00:12:25 +05:30
parent ad3834b43e
commit 1ea85d5ed1
21 changed files with 1009 additions and 454 deletions

View File

@@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
import 'api_error.dart';
import 'api_error_handler.dart';
import 'api_error_interceptor.dart';
import '../../shared/theme/app_theme.dart';
import '../../shared/theme/theme_extensions.dart';
import 'package:conduit/l10n/app_localizations.dart';
import '../utils/debug_logger.dart';
@@ -132,7 +131,7 @@ class EnhancedErrorService {
],
],
),
backgroundColor: _getErrorColor(error),
backgroundColor: _getErrorColor(context, error),
duration: duration ?? _getSnackbarDuration(error),
action: isRetryableError && onRetry != null
? SnackBarAction(
@@ -169,7 +168,7 @@ class EnhancedErrorService {
return AlertDialog(
title: Row(
children: [
Icon(_getErrorIcon(error), color: _getErrorColor(error)),
Icon(_getErrorIcon(error), color: _getErrorColor(context, error)),
const SizedBox(width: Spacing.sm),
Expanded(child: Text(title ?? _getErrorTitle(error))),
],
@@ -250,7 +249,7 @@ class EnhancedErrorService {
Icon(
_getErrorIcon(error),
size: IconSize.xxl,
color: _getErrorColor(error),
color: _getErrorColor(context, error),
),
const SizedBox(height: Spacing.md),
Text(
@@ -416,27 +415,28 @@ class EnhancedErrorService {
return Icons.error_outline;
}
Color _getErrorColor(dynamic error) {
Color _getErrorColor(BuildContext context, dynamic error) {
final tokens = context.colorTokens;
if (error is ApiError) {
switch (error.type) {
case ApiErrorType.network:
case ApiErrorType.timeout:
return AppTheme.warning;
return tokens.statusWarning60;
case ApiErrorType.authentication:
case ApiErrorType.authorization:
return AppTheme.error;
return tokens.statusError60;
case ApiErrorType.validation:
case ApiErrorType.badRequest:
return AppTheme.warning;
return tokens.statusWarning60;
case ApiErrorType.server:
return AppTheme.error;
return tokens.statusError60;
case ApiErrorType.rateLimit:
return AppTheme.info;
return tokens.statusInfo60;
default:
return AppTheme.error;
return tokens.statusError60;
}
}
return AppTheme.error;
return tokens.statusError60;
}
String _getErrorTitle(dynamic error) {