refactor: Enhance category handling in note editor and card components
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:notas/data/note_body.dart';
|
||||
import 'package:notas/models/category.dart';
|
||||
import 'package:notas/models/note.dart';
|
||||
import 'package:notas/theme/app_palette.dart';
|
||||
import 'package:notas/widgets/category_style.dart';
|
||||
|
||||
class NoteCard extends StatelessWidget {
|
||||
const NoteCard({
|
||||
super.key,
|
||||
required this.note,
|
||||
this.category,
|
||||
this.isSelected = false,
|
||||
this.borderColor,
|
||||
this.onTap,
|
||||
@@ -17,6 +20,7 @@ class NoteCard extends StatelessWidget {
|
||||
});
|
||||
|
||||
final Note note;
|
||||
final Category? category;
|
||||
final bool isSelected;
|
||||
final Color? borderColor;
|
||||
final VoidCallback? onTap;
|
||||
@@ -28,6 +32,12 @@ class NoteCard extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final AppPalette palette = Theme.of(context).extension<AppPalette>()!;
|
||||
final String bodyText = noteBodyToPlainText(note.body).trim();
|
||||
final Color? categoryColor = category?.colorValue == null
|
||||
? null
|
||||
: Color(category!.colorValue!);
|
||||
final IconData? categoryIcon = category == null
|
||||
? null
|
||||
: CategoryStyle.iconForCodePoint(category!.iconCodePoint);
|
||||
|
||||
return Material(
|
||||
color: Colors.transparent, // 1. Fondo completamente transparente
|
||||
@@ -58,15 +68,34 @@ class NoteCard extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
note.title.isEmpty ? 'Sin título' : note.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: palette.textPrimary,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
if (categoryIcon != null) ...[
|
||||
Container(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: Icon(
|
||||
categoryIcon,
|
||||
size: 18,
|
||||
color: categoryColor ?? palette.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
Expanded(
|
||||
child: Text(
|
||||
note.title.isEmpty ? 'Sin título' : note.title,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(
|
||||
color: palette.textPrimary,
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
@@ -88,6 +117,11 @@ class NoteCard extends StatelessWidget {
|
||||
builder: (BuildContext buttonContext) {
|
||||
return PopupMenuButton<String>(
|
||||
icon: Icon(Icons.more_vert, color: palette.textSecondary),
|
||||
color: palette.surfaceElevated,
|
||||
elevation: 10,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
),
|
||||
onSelected: (String value) {
|
||||
switch (value) {
|
||||
case 'category':
|
||||
|
||||
Reference in New Issue
Block a user