Refactor theme management: Replace AppColors with AppPalette

- Removed AppColors class and migrated all references to AppPalette.
- Updated VaultAccessScreen, MenuDrawer, NoteCard, SearchAppBar, and other widgets to use AppPalette for color management.
- Introduced AppPalette to handle light and dark themes with appropriate color schemes.
- Adjusted theme application in AppTheme to utilize AppPalette extensions.
- Updated tests to reflect changes in theme structure and color references.
This commit is contained in:
2026-05-23 13:55:40 +02:00
parent 29881183ed
commit 1dede9eb78
16 changed files with 1031 additions and 618 deletions
+60 -58
View File
@@ -7,7 +7,7 @@ import 'package:intl/intl.dart';
import 'package:notas/models/category.dart';
import 'package:notas/models/note.dart';
import 'package:notas/platform/app_platform.dart';
import 'package:notas/theme/app_colors.dart';
import 'package:notas/theme/app_palette.dart';
import 'package:notas/widgets/category_style.dart';
// NoteEditorScreen: unified UI for creating and editing notes.
@@ -42,7 +42,7 @@ class NoteEditorScreen extends StatefulWidget {
return showGeneralDialog<dynamic>(
context: context,
barrierDismissible: false,
barrierColor: AppColors.transparent,
barrierColor: Colors.transparent,
transitionDuration: const Duration(milliseconds: 200),
pageBuilder: (context, animation, secondaryAnimation) {
return NoteEditorScreen(
@@ -120,6 +120,11 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
bool get _isMobileLayout => isAndroid || isIOS;
AppPalette _paletteOf(BuildContext context) {
return Theme.of(context).extension<AppPalette>() ??
AppPalette.fromBrightness(Theme.of(context).brightness);
}
@override
void initState() {
super.initState();
@@ -200,36 +205,37 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
required ValueChanged<bool> onConfirmed,
}) {
final bool isDeletedNote = _currentNote.isDeleted;
final AppPalette palette = _paletteOf(context);
return AlertDialog(
backgroundColor: AppColors.cardBackground,
backgroundColor: palette.cardBackground,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(12),
side: BorderSide(color: AppColors.border),
side: BorderSide(color: palette.border),
),
title: Text(
isDeletedNote ? 'Eliminar permanentemente' : 'Eliminar nota',
style: const TextStyle(color: AppColors.textPrimary),
style: TextStyle(color: palette.textPrimary),
),
content: Text(
isDeletedNote
? 'Esta nota ya está borrada. Si la eliminas ahora, se borrará permanentemente.'
: '¿Estás seguro de que deseas eliminar esta nota?',
style: const TextStyle(color: AppColors.textSecondary),
style: TextStyle(color: palette.textSecondary),
),
actions: [
TextButton(
onPressed: () => onConfirmed(false),
child: const Text(
child: Text(
'Cancelar',
style: TextStyle(color: AppColors.textSecondary),
style: TextStyle(color: palette.textSecondary),
),
),
TextButton(
onPressed: () => onConfirmed(true),
child: Text(
isDeletedNote ? 'Eliminar permanentemente' : 'Eliminar',
style: const TextStyle(color: AppColors.destructive),
style: TextStyle(color: palette.destructiveAccent),
),
),
],
@@ -241,7 +247,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
final bool? confirmed = await showDialog<bool>(
context: context,
barrierDismissible: false,
barrierColor: AppColors.transparent,
barrierColor: Colors.transparent,
builder: (BuildContext dialogContext) {
return _buildDeleteConfirmationDialog(
onConfirmed: (bool confirmed) =>
@@ -258,7 +264,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
final bool? confirmed = await showDialog<bool>(
context: context,
barrierDismissible: false,
barrierColor: AppColors.transparent,
barrierColor: Colors.transparent,
builder: (BuildContext dialogContext) {
return _buildDeleteConfirmationDialog(
onConfirmed: (bool confirmed) =>
@@ -287,14 +293,11 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
};
return Material(
color: AppColors.transparent,
color: Colors.transparent,
child: Stack(
children: [
const Positioned.fill(
child: ModalBarrier(
dismissible: false,
color: AppColors.overlay,
),
child: ModalBarrier(dismissible: false, color: Colors.black54),
),
Center(
child: ConstrainedBox(
@@ -323,25 +326,30 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
}
Color _categoryBackgroundColor(Category? category) {
final AppPalette palette = _paletteOf(context);
if (category?.colorValue == null) {
return AppColors.borderMuted;
return palette.borderMuted;
}
return Color(category!.colorValue!);
}
Color _categoryForegroundColor(Category? category) {
final AppPalette palette = _paletteOf(context);
if (category == null || category.colorValue == null) {
return AppColors.textPrimary;
return palette.textPrimary;
}
final Color background = Color(category.colorValue!);
return background.computeLuminance() > 0.55
? AppColors.textOnSurfaceDark
: AppColors.textPrimary;
? palette.textOnSurfaceDark
: palette.textPrimary;
}
Widget _buildCategorySelectorBox({Category? category}) {
final AppPalette palette = _paletteOf(context);
final String label = category?.name ?? 'Sin categoría';
final IconData icon = CategoryStyle.iconForCodePoint(
category?.iconCodePoint,
@@ -358,7 +366,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
border: Border.all(
color: category?.colorValue != null
? backgroundColor.withValues(alpha: 0.85)
: AppColors.textDisabled,
: palette.textDisabled,
),
),
child: Row(
@@ -409,12 +417,13 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
_categoryMenuEntry = OverlayEntry(
builder: (BuildContext overlayContext) {
final AppPalette palette = _paletteOf(overlayContext);
final Size screenSize = MediaQuery.of(overlayContext).size;
final double menuWidth = math.min(screenSize.width - 32, 320);
final double menuHeight = math.min(screenSize.height - 32, 360);
return Material(
color: AppColors.transparent,
color: Colors.transparent,
child: Stack(
children: [
Positioned.fill(
@@ -432,7 +441,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
),
child: Material(
elevation: 10,
color: AppColors.surfaceElevated,
color: palette.surfaceElevated,
borderRadius: BorderRadius.circular(12),
clipBehavior: Clip.antiAlias,
child: ListView(
@@ -482,6 +491,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
required bool isSelected,
required VoidCallback onTap,
}) {
final AppPalette palette = _paletteOf(context);
final Color backgroundColor = _categoryBackgroundColor(category);
final Color foregroundColor = _categoryForegroundColor(category);
final IconData icon = CategoryStyle.iconForCodePoint(
@@ -492,7 +502,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
onTap: onTap,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
color: isSelected ? AppColors.hover : null,
color: isSelected ? palette.hover : null,
child: Row(
children: [
Container(
@@ -504,7 +514,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
border: Border.all(
color: category?.colorValue != null
? backgroundColor.withValues(alpha: 0.85)
: AppColors.textDisabled,
: palette.textDisabled,
),
),
child: Icon(icon, size: 16, color: foregroundColor),
@@ -553,6 +563,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
}
Widget _buildEditorContent({required bool isMobile}) {
final AppPalette palette = _paletteOf(context);
final double titleSpacing = isMobile ? 16.0 : 8.0;
return Column(
@@ -560,15 +571,13 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: AppColors.border, width: 1),
),
border: Border(bottom: BorderSide(color: palette.border, width: 1)),
),
child: Row(
children: [
IconButton(
onPressed: _closeWithoutSaving,
icon: const Icon(Icons.close, color: AppColors.textSecondary),
icon: Icon(Icons.close, color: palette.textSecondary),
tooltip: 'Cerrar sin guardar',
),
const SizedBox(width: 8),
@@ -579,23 +588,17 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
children: [
Text(
'Posicion: ${_currentNote.position}',
style: const TextStyle(
color: AppColors.textMuted,
fontSize: 12,
),
style: TextStyle(color: palette.textMuted, fontSize: 12),
),
Text(
'Creado: ${_formatDate(_currentNote.createdAt)}',
style: const TextStyle(
color: AppColors.textMuted,
fontSize: 12,
),
style: TextStyle(color: palette.textMuted, fontSize: 12),
),
if (_currentNote.updatedAt != _currentNote.createdAt)
Text(
'Modificado: ${_formatDate(_currentNote.updatedAt)}',
style: const TextStyle(
color: AppColors.textMuted,
style: TextStyle(
color: palette.textMuted,
fontSize: 12,
),
),
@@ -629,14 +632,14 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
children: [
TextField(
controller: _titleController,
style: const TextStyle(
color: AppColors.textPrimary,
style: TextStyle(
color: palette.textPrimary,
fontSize: 28,
fontWeight: FontWeight.bold,
),
decoration: const InputDecoration(
decoration: InputDecoration(
hintText: 'Título',
hintStyle: TextStyle(color: AppColors.textHint),
hintStyle: TextStyle(color: palette.textHint),
border: InputBorder.none,
contentPadding: EdgeInsets.zero,
),
@@ -648,14 +651,14 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
keyboardType: TextInputType.multiline,
maxLines: null,
expands: true,
style: const TextStyle(
color: AppColors.textPrimary,
style: TextStyle(
color: palette.textPrimary,
fontSize: 16,
height: 1.6,
),
decoration: const InputDecoration(
decoration: InputDecoration(
hintText: 'Escribe tu nota...',
hintStyle: TextStyle(color: AppColors.textHint),
hintStyle: TextStyle(color: palette.textHint),
border: InputBorder.none,
contentPadding: EdgeInsets.zero,
),
@@ -668,7 +671,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
decoration: BoxDecoration(
border: Border(top: BorderSide(color: AppColors.border, width: 1)),
border: Border(top: BorderSide(color: palette.border, width: 1)),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -676,9 +679,9 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
if (!_isNewNote)
IconButton(
onPressed: _deleteNote,
icon: const Icon(
icon: Icon(
Icons.delete_outline,
color: AppColors.destructive,
color: palette.destructiveAccent,
),
tooltip: 'Eliminar nota',
)
@@ -694,12 +697,14 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
@override
Widget build(BuildContext context) {
final AppPalette palette = _paletteOf(context);
if (_isMobileLayout) {
return Material(
color: AppColors.transparent,
color: palette.transparent,
child: SafeArea(
child: Container(
color: AppColors.cardBackground,
color: palette.cardBackground,
child: _buildEditorContent(isMobile: true),
),
),
@@ -714,10 +719,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
return Stack(
children: [
Positioned.fill(
child: ModalBarrier(
dismissible: false,
color: AppColors.shadowDim,
),
child: ModalBarrier(dismissible: false, color: palette.shadowDim),
),
Positioned.fill(
child: Center(
@@ -725,10 +727,10 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
width: maxWidth,
height: maxHeight,
child: Material(
color: AppColors.cardBackground,
color: palette.cardBackground,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(16),
side: BorderSide(color: AppColors.textDisabled, width: 1),
side: BorderSide(color: palette.textDisabled, width: 1),
),
clipBehavior: Clip.antiAlias,
child: _buildEditorContent(isMobile: false),