feat: Refactor note editor dialog and delete confirmation for improved readability and reusability

This commit is contained in:
2026-05-21 16:26:31 +02:00
parent 49fc33edc0
commit 28f4ede4aa
3 changed files with 518 additions and 458 deletions
+392 -288
View File
@@ -316,12 +316,6 @@ class _HomeScreenState extends State<HomeScreen> {
final Widget body = _isLoading final Widget body = _isLoading
? const Center(child: CircularProgressIndicator()) ? const Center(child: CircularProgressIndicator())
: visibleNotes.isEmpty
? _EmptyState(
showDeletedNotes: _showDeletedNotes,
categoryName: currentCategory?.name,
searchQuery: _searchQuery,
)
: RefreshIndicator( : RefreshIndicator(
onRefresh: () async { onRefresh: () async {
await widget.onRequestSync(); await widget.onRequestSync();
@@ -330,295 +324,405 @@ class _HomeScreenState extends State<HomeScreen> {
cursor: _isDragging cursor: _isDragging
? SystemMouseCursors.grabbing ? SystemMouseCursors.grabbing
: SystemMouseCursors.basic, : SystemMouseCursors.basic,
child: MasonryGridView.count( child: CustomScrollView(
crossAxisCount: crossAxisCount, physics: const AlwaysScrollableScrollPhysics(),
mainAxisSpacing: 10, slivers: visibleNotes.isEmpty
crossAxisSpacing: 10, ? [
itemCount: visibleNotes.length, SliverFillRemaining(
itemBuilder: (BuildContext context, int index) { hasScrollBody: false,
final List<Note> filteredNotes = visibleNotes; child: _EmptyState(
return DragTarget<int>( showDeletedNotes: _showDeletedNotes,
onAcceptWithDetails: (DragTargetDetails<int> details) { categoryName: currentCategory?.name,
final Note targetNote = filteredNotes[index]; searchQuery: _searchQuery,
final int originalTargetIndex = _notes.indexOf( ),
targetNote, ),
); ]
_reorderNote(details.data, originalTargetIndex); : [
}, SliverPadding(
builder: (context, candidateData, rejectedData) { padding: const EdgeInsets.only(bottom: 8),
return LayoutBuilder( sliver: SliverMasonryGrid.count(
builder: (context, constraints) { crossAxisCount: crossAxisCount,
final double cellWidth = constraints.maxWidth; mainAxisSpacing: 10,
final bool requiresLongPressToDrag = crossAxisSpacing: 10,
_requiresLongPressToDrag(_lastPointerKind); childCount: visibleNotes.length,
itemBuilder: (BuildContext context, int index) {
final List<Note> filteredNotes = visibleNotes;
return DragTarget<int>(
onAcceptWithDetails:
(DragTargetDetails<int> details) {
final Note targetNote =
filteredNotes[index];
final int originalTargetIndex = _notes
.indexOf(targetNote);
_reorderNote(
details.data,
originalTargetIndex,
);
},
builder: (context, candidateData, rejectedData) {
return LayoutBuilder(
builder: (context, constraints) {
final double cellWidth =
constraints.maxWidth;
final bool requiresLongPressToDrag =
_requiresLongPressToDrag(
_lastPointerKind,
);
final Widget draggableNote = requiresLongPressToDrag final Widget draggableNote =
? LongPressDraggable<int>( requiresLongPressToDrag
data: _notes.indexOf(filteredNotes[index]), ? LongPressDraggable<int>(
delay: const Duration(milliseconds: 280), data: _notes.indexOf(
onDragStarted: () { filteredNotes[index],
if (!mounted) return;
setState(() {
_isDragging = true;
});
},
onDragEnd: (_) {
if (!mounted) return;
setState(() {
_isDragging = false;
});
},
onDraggableCanceled: (_, _) {
if (!mounted) return;
setState(() {
_isDragging = false;
});
},
feedback: MouseRegion(
cursor: SystemMouseCursors.grabbing,
child: Material(
color: Colors.transparent,
elevation: 8,
child: SizedBox(
width: cellWidth,
child: TweenAnimationBuilder<double>(
tween: Tween(begin: 0.97, end: 1.0),
duration: const Duration(
milliseconds: 180,
),
curve: Curves.easeOutCubic,
builder: (context, scale, child) {
return Transform.scale(
scale: scale,
alignment: Alignment.topLeft,
child: child,
);
},
child: Opacity(
opacity: 0.95,
child: NoteCard(
note: filteredNotes[index],
onTap: () {},
isDragging: true,
),
),
),
),
),
),
childWhenDragging: MouseRegion(
cursor: SystemMouseCursors.grabbing,
child: Opacity(
opacity: 0.3,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: const Color.fromRGBO(
24,
25,
26,
1,
),
borderRadius: BorderRadius.circular(
12,
),
border: Border.all(
color: Colors.white24,
width: 1,
),
),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
filteredNotes[index].title,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
), ),
maxLines: 2, delay: const Duration(
), milliseconds: 280,
const SizedBox(height: 8), ),
Text( onDragStarted: () {
filteredNotes[index].body, if (!mounted) return;
style: const TextStyle( setState(() {
color: Colors.white70, _isDragging = true;
fontSize: 14, });
},
onDragEnd: (_) {
if (!mounted) return;
setState(() {
_isDragging = false;
});
},
onDraggableCanceled: (_, _) {
if (!mounted) return;
setState(() {
_isDragging = false;
});
},
feedback: MouseRegion(
cursor:
SystemMouseCursors.grabbing,
child: Material(
color: Colors.transparent,
elevation: 8,
child: SizedBox(
width: cellWidth,
child: TweenAnimationBuilder<double>(
tween: Tween(
begin: 0.97,
end: 1.0,
),
duration: const Duration(
milliseconds: 180,
),
curve:
Curves.easeOutCubic,
builder:
(
context,
scale,
child,
) {
return Transform.scale(
scale: scale,
alignment:
Alignment
.topLeft,
child: child,
);
},
child: Opacity(
opacity: 0.95,
child: NoteCard(
note:
filteredNotes[index],
onTap: () {},
isDragging: true,
),
),
),
),
),
),
childWhenDragging: MouseRegion(
cursor:
SystemMouseCursors.grabbing,
child: Opacity(
opacity: 0.3,
child: Container(
padding:
const EdgeInsets.all(
16,
),
decoration: BoxDecoration(
color:
const Color.fromRGBO(
24,
25,
26,
1,
),
borderRadius:
BorderRadius.circular(
12,
),
border: Border.all(
color: Colors.white24,
width: 1,
),
),
child: Column(
crossAxisAlignment:
CrossAxisAlignment
.start,
mainAxisSize:
MainAxisSize.min,
children: [
Text(
filteredNotes[index]
.title,
style:
const TextStyle(
color: Colors
.white,
fontSize: 16,
fontWeight:
FontWeight
.bold,
),
maxLines: 2,
),
const SizedBox(
height: 8,
),
Text(
filteredNotes[index]
.body,
style:
const TextStyle(
color: Colors
.white70,
fontSize: 14,
),
maxLines: 20,
overflow:
TextOverflow.clip,
),
],
),
),
),
),
child: Container(
decoration: BoxDecoration(
border:
candidateData.isNotEmpty
? Border.all(
color: Colors
.blue
.shade400,
width: 2,
)
: null,
borderRadius:
BorderRadius.circular(12),
),
child: NoteCard(
key: ValueKey<String>(
filteredNotes[index].id,
),
note: filteredNotes[index],
onTap: () => _openNoteEditor(
filteredNotes[index],
),
isDragging: _isDragging,
),
), ),
maxLines: 20,
overflow: TextOverflow.clip,
),
],
),
),
),
),
child: Container(
decoration: BoxDecoration(
border: candidateData.isNotEmpty
? Border.all(
color: Colors.blue.shade400,
width: 2,
) )
: null, : Draggable<int>(
borderRadius: BorderRadius.circular(12), data: _notes.indexOf(
), filteredNotes[index],
child: NoteCard( ),
key: ValueKey<String>( onDragStarted: () {
filteredNotes[index].id, if (!mounted) return;
), setState(() {
note: filteredNotes[index], _isDragging = true;
onTap: () => });
_openNoteEditor(filteredNotes[index]), },
isDragging: _isDragging, onDragEnd: (_) {
), if (!mounted) return;
), setState(() {
) _isDragging = false;
: Draggable<int>( });
data: _notes.indexOf(filteredNotes[index]), },
onDragStarted: () { onDraggableCanceled: (_, _) {
if (!mounted) return; if (!mounted) return;
setState(() { setState(() {
_isDragging = true; _isDragging = false;
}); });
}, },
onDragEnd: (_) { feedback: MouseRegion(
if (!mounted) return; cursor:
setState(() { SystemMouseCursors.grabbing,
_isDragging = false; child: Material(
}); color: Colors.transparent,
}, elevation: 8,
onDraggableCanceled: (_, _) { child: SizedBox(
if (!mounted) return; width: cellWidth,
setState(() { child: TweenAnimationBuilder<double>(
_isDragging = false; tween: Tween(
}); begin: 0.97,
}, end: 1.0,
feedback: MouseRegion( ),
cursor: SystemMouseCursors.grabbing, duration: const Duration(
child: Material( milliseconds: 180,
color: Colors.transparent, ),
elevation: 8, curve:
child: SizedBox( Curves.easeOutCubic,
width: cellWidth, builder:
child: TweenAnimationBuilder<double>( (
tween: Tween(begin: 0.97, end: 1.0), context,
duration: const Duration( scale,
milliseconds: 180, child,
), ) {
curve: Curves.easeOutCubic, return Transform.scale(
builder: (context, scale, child) { scale: scale,
return Transform.scale( alignment:
scale: scale, Alignment
alignment: Alignment.topLeft, .topLeft,
child: child, child: child,
);
},
child: Opacity(
opacity: 0.95,
child: NoteCard(
note:
filteredNotes[index],
onTap: () {},
isDragging: true,
),
),
),
),
),
),
childWhenDragging: MouseRegion(
cursor:
SystemMouseCursors.grabbing,
child: Opacity(
opacity: 0.3,
child: Container(
padding:
const EdgeInsets.all(
16,
),
decoration: BoxDecoration(
color:
const Color.fromRGBO(
24,
25,
26,
1,
),
borderRadius:
BorderRadius.circular(
12,
),
border: Border.all(
color: Colors.white24,
width: 1,
),
),
child: Column(
crossAxisAlignment:
CrossAxisAlignment
.start,
mainAxisSize:
MainAxisSize.min,
children: [
Text(
filteredNotes[index]
.title,
style:
const TextStyle(
color: Colors
.white,
fontSize: 16,
fontWeight:
FontWeight
.bold,
),
maxLines: 2,
overflow: TextOverflow
.ellipsis,
),
const SizedBox(
height: 8,
),
Text(
filteredNotes[index]
.body,
style:
const TextStyle(
color: Colors
.white70,
fontSize: 14,
),
maxLines: 20,
overflow:
TextOverflow.clip,
),
],
),
),
),
),
child: Container(
decoration: BoxDecoration(
border:
candidateData.isNotEmpty
? Border.all(
color: Colors
.blue
.shade400,
width: 2,
)
: null,
borderRadius:
BorderRadius.circular(12),
),
child: NoteCard(
key: ValueKey<String>(
filteredNotes[index].id,
),
note: filteredNotes[index],
onTap: () => _openNoteEditor(
filteredNotes[index],
),
isDragging: _isDragging,
),
),
); );
},
child: Opacity(
opacity: 0.95,
child: NoteCard(
note: filteredNotes[index],
onTap: () {},
isDragging: true,
),
),
),
),
),
),
childWhenDragging: MouseRegion(
cursor: SystemMouseCursors.grabbing,
child: Opacity(
opacity: 0.3,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: const Color.fromRGBO(
24,
25,
26,
1,
),
borderRadius: BorderRadius.circular(
12,
),
border: Border.all(
color: Colors.white24,
width: 1,
),
),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Text(
filteredNotes[index].title,
style: const TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 8),
Text(
filteredNotes[index].body,
style: const TextStyle(
color: Colors.white70,
fontSize: 14,
),
maxLines: 20,
overflow: TextOverflow.clip,
),
],
),
),
),
),
child: Container(
decoration: BoxDecoration(
border: candidateData.isNotEmpty
? Border.all(
color: Colors.blue.shade400,
width: 2,
)
: null,
borderRadius: BorderRadius.circular(12),
),
child: NoteCard(
key: ValueKey<String>(
filteredNotes[index].id,
),
note: filteredNotes[index],
onTap: () =>
_openNoteEditor(filteredNotes[index]),
isDragging: _isDragging,
),
),
);
return Listener( return Listener(
onPointerDown: (PointerDownEvent event) { onPointerDown:
if (_lastPointerKind == event.kind) { (PointerDownEvent event) {
return; if (_lastPointerKind ==
} event.kind) {
return;
}
setState(() { setState(() {
_lastPointerKind = event.kind; _lastPointerKind = event.kind;
}); });
},
child: draggableNote,
);
},
);
},
);
}, },
child: draggableNote, ),
); ),
}, ],
);
},
);
},
), ),
), ),
); );
@@ -904,7 +1008,7 @@ class _CategoryDialogState extends State<_CategoryDialog> {
await widget.onRequestSync(); await widget.onRequestSync();
} catch (_) {} } catch (_) {}
if (mounted) { if (mounted) {
await widget.onCategoryDeleted(); await widget.onCategoryDeleted();
Navigator.pop(context); Navigator.pop(context);
} }
} catch (e) { } catch (e) {
+87 -154
View File
@@ -28,39 +28,44 @@ class NoteEditorScreen extends StatefulWidget {
@override @override
State<NoteEditorScreen> createState() => _NoteEditorScreenState(); State<NoteEditorScreen> createState() => _NoteEditorScreenState();
static Future<dynamic> _showGeneralEditorDialog(
BuildContext context, {
Note? note,
String? categoryId,
}) {
return showGeneralDialog<dynamic>(
context: context,
barrierDismissible: false,
barrierColor: Colors.transparent,
transitionDuration: const Duration(milliseconds: 200),
pageBuilder: (context, animation, secondaryAnimation) {
return NoteEditorScreen(note: note, categoryId: categoryId);
},
transitionBuilder: (context, animation, secondaryAnimation, child) {
return ScaleTransition(scale: animation, child: child);
},
);
}
static Future<dynamic> showDialog( static Future<dynamic> showDialog(
BuildContext context, { BuildContext context, {
Note? note, Note? note,
String? categoryId, String? categoryId,
}) { }) {
if (isAndroid || isIOS) { if (isAndroid || isIOS) {
return showGeneralDialog<dynamic>( return _showGeneralEditorDialog(
context: context, context,
barrierDismissible: false, note: note,
barrierColor: Colors.transparent, categoryId: categoryId,
transitionDuration: const Duration(milliseconds: 200),
pageBuilder: (context, animation, secondaryAnimation) {
return NoteEditorScreen(note: note, categoryId: categoryId);
},
transitionBuilder: (context, animation, secondaryAnimation, child) {
return ScaleTransition(scale: animation, child: child);
},
); );
} }
final OverlayState? overlayState = Overlay.of(context, rootOverlay: true); final OverlayState? overlayState = Overlay.of(context, rootOverlay: true);
if (overlayState == null) { if (overlayState == null) {
return showGeneralDialog<dynamic>( return _showGeneralEditorDialog(
context: context, context,
barrierDismissible: false, note: note,
barrierColor: Colors.transparent, categoryId: categoryId,
transitionDuration: const Duration(milliseconds: 200),
pageBuilder: (context, animation, secondaryAnimation) {
return NoteEditorScreen(note: note, categoryId: categoryId);
},
transitionBuilder: (context, animation, secondaryAnimation, child) {
return ScaleTransition(scale: animation, child: child);
},
); );
} }
@@ -161,43 +166,52 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
_complete(updatedNote); _complete(updatedNote);
} }
Future<bool> _showDeleteConfirmation() async { Widget _buildDeleteConfirmationDialog({
required ValueChanged<bool> onConfirmed,
}) {
final bool isDeletedNote = _currentNote.isDeleted; final bool isDeletedNote = _currentNote.isDeleted;
return AlertDialog(
backgroundColor: const Color(0xFF303134),
title: Text(
isDeletedNote ? 'Eliminar permanentemente' : 'Eliminar nota',
style: const TextStyle(color: Colors.white),
),
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: Colors.white70),
),
actions: [
TextButton(
onPressed: () => onConfirmed(false),
child: const Text(
'Cancelar',
style: TextStyle(color: Colors.white70),
),
),
TextButton(
onPressed: () => onConfirmed(true),
child: Text(
isDeletedNote ? 'Eliminar permanentemente' : 'Eliminar',
style: const TextStyle(color: Colors.red),
),
),
],
);
}
Future<bool> _showDeleteConfirmation() async {
if (_isMobileLayout) { if (_isMobileLayout) {
final bool? confirmed = await showDialog<bool>( final bool? confirmed = await showDialog<bool>(
context: context, context: context,
barrierDismissible: false, barrierDismissible: false,
barrierColor: Colors.transparent, barrierColor: Colors.transparent,
builder: (BuildContext dialogContext) { builder: (BuildContext dialogContext) {
return AlertDialog( return _buildDeleteConfirmationDialog(
backgroundColor: const Color(0xFF303134), onConfirmed: (bool confirmed) =>
title: Text( Navigator.of(dialogContext).pop(confirmed),
isDeletedNote ? 'Eliminar permanentemente' : 'Eliminar nota',
style: const TextStyle(color: Colors.white),
),
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: Colors.white70),
),
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(false),
child: const Text(
'Cancelar',
style: TextStyle(color: Colors.white70),
),
),
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(true),
child: Text(
isDeletedNote ? 'Eliminar permanentemente' : 'Eliminar',
style: const TextStyle(color: Colors.red),
),
),
],
); );
}, },
); );
@@ -212,34 +226,9 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
barrierDismissible: false, barrierDismissible: false,
barrierColor: Colors.transparent, barrierColor: Colors.transparent,
builder: (BuildContext dialogContext) { builder: (BuildContext dialogContext) {
return AlertDialog( return _buildDeleteConfirmationDialog(
backgroundColor: const Color(0xFF303134), onConfirmed: (bool confirmed) =>
title: Text( Navigator.of(dialogContext).pop(confirmed),
isDeletedNote ? 'Eliminar permanentemente' : 'Eliminar nota',
style: const TextStyle(color: Colors.white),
),
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: Colors.white70),
),
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(false),
child: const Text(
'Cancelar',
style: TextStyle(color: Colors.white70),
),
),
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(true),
child: Text(
isDeletedNote ? 'Eliminar permanentemente' : 'Eliminar',
style: const TextStyle(color: Colors.red),
),
),
],
); );
}, },
); );
@@ -251,18 +240,18 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
late final OverlayEntry entry; late final OverlayEntry entry;
bool didRemove = false; bool didRemove = false;
void close(bool confirmed) {
if (!completer.isCompleted) {
completer.complete(confirmed);
}
if (!didRemove && entry.mounted) {
didRemove = true;
entry.remove();
}
}
entry = OverlayEntry( entry = OverlayEntry(
builder: (BuildContext overlayContext) { builder: (BuildContext overlayContext) {
final ValueChanged<bool> close = (bool confirmed) {
if (!completer.isCompleted) {
completer.complete(confirmed);
}
if (!didRemove && entry.mounted) {
didRemove = true;
entry.remove();
}
};
return Material( return Material(
color: Colors.transparent, color: Colors.transparent,
child: Stack( child: Stack(
@@ -276,39 +265,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
Center( Center(
child: ConstrainedBox( child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 420), constraints: const BoxConstraints(maxWidth: 420),
child: AlertDialog( child: _buildDeleteConfirmationDialog(onConfirmed: close),
backgroundColor: const Color(0xFF303134),
title: Text(
isDeletedNote
? 'Eliminar permanentemente'
: 'Eliminar nota',
style: const TextStyle(color: Colors.white),
),
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: Colors.white70),
),
actions: [
TextButton(
onPressed: () => close(false),
child: const Text(
'Cancelar',
style: TextStyle(color: Colors.white70),
),
),
TextButton(
onPressed: () => close(true),
child: Text(
isDeletedNote
? 'Eliminar permanentemente'
: 'Eliminar',
style: const TextStyle(color: Colors.red),
),
),
],
),
), ),
), ),
], ],
@@ -351,26 +308,15 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
return Column( return Column(
children: [ children: [
Container( Container(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
horizontal: 16,
vertical: 12,
),
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border( border: Border(bottom: BorderSide(color: Colors.white12, width: 1)),
bottom: BorderSide(
color: Colors.white12,
width: 1,
),
),
), ),
child: Row( child: Row(
children: [ children: [
IconButton( IconButton(
onPressed: _closeWithoutSaving, onPressed: _closeWithoutSaving,
icon: const Icon( icon: const Icon(Icons.close, color: Colors.white70),
Icons.close,
color: Colors.white70,
),
tooltip: 'Cerrar sin guardar', tooltip: 'Cerrar sin guardar',
), ),
const SizedBox(width: 8), const SizedBox(width: 8),
@@ -434,9 +380,7 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
), ),
decoration: const InputDecoration( decoration: const InputDecoration(
hintText: 'Escribe tu nota...', hintText: 'Escribe tu nota...',
hintStyle: TextStyle( hintStyle: TextStyle(color: Colors.white30),
color: Colors.white30,
),
border: InputBorder.none, border: InputBorder.none,
contentPadding: EdgeInsets.zero, contentPadding: EdgeInsets.zero,
), ),
@@ -447,14 +391,9 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
), ),
), ),
Container( Container(
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
horizontal: 16,
vertical: 12,
),
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border( border: Border(top: BorderSide(color: Colors.white12, width: 1)),
top: BorderSide(color: Colors.white12, width: 1),
),
), ),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
@@ -462,18 +401,12 @@ class _NoteEditorScreenState extends State<NoteEditorScreen> {
if (!_isNewNote) if (!_isNewNote)
IconButton( IconButton(
onPressed: _deleteNote, onPressed: _deleteNote,
icon: const Icon( icon: const Icon(Icons.delete_outline, color: Colors.red),
Icons.delete_outline,
color: Colors.red,
),
tooltip: 'Eliminar nota', tooltip: 'Eliminar nota',
) )
else else
const SizedBox(width: 48), const SizedBox(width: 48),
FilledButton( FilledButton(onPressed: _saveNote, child: const Text('Guardar')),
onPressed: _saveNote,
child: const Text('Guardar'),
),
], ],
), ),
), ),
+39 -16
View File
@@ -45,12 +45,9 @@ class MenuDrawer extends StatelessWidget {
child: Column( child: Column(
children: categories.map((category) { children: categories.map((category) {
final categoryId = 'category_${category.id}'; final categoryId = 'category_${category.id}';
final IconData categoryIcon = category.iconCodePoint == null final IconData categoryIcon = _iconForCodePoint(
? Icons.folder_outlined category.iconCodePoint,
: IconData( );
category.iconCodePoint!,
fontFamily: 'MaterialIcons',
);
return _MenuItemTile( return _MenuItemTile(
icon: categoryIcon, icon: categoryIcon,
@@ -102,6 +99,31 @@ class MenuDrawer extends StatelessWidget {
} }
} }
IconData _iconForCodePoint(int? codePoint) {
if (codePoint == null) {
return Icons.folder_outlined;
}
const List<IconData> icons = [
Icons.folder,
Icons.work,
Icons.star,
Icons.home,
Icons.school,
Icons.book,
Icons.music_note,
Icons.lightbulb,
];
for (final IconData icon in icons) {
if (icon.codePoint == codePoint) {
return icon;
}
}
return Icons.folder_outlined;
}
class _MenuItemTile extends StatelessWidget { class _MenuItemTile extends StatelessWidget {
const _MenuItemTile({ const _MenuItemTile({
required this.icon, required this.icon,
@@ -136,7 +158,7 @@ class _MenuItemTile extends StatelessWidget {
top: 2, top: 2,
bottom: 2, bottom: 2,
), ),
decoration: BoxDecoration( child: Material(
color: backgroundColor, color: backgroundColor,
borderRadius: selected borderRadius: selected
? const BorderRadius.only( ? const BorderRadius.only(
@@ -144,16 +166,17 @@ class _MenuItemTile extends StatelessWidget {
bottomRight: Radius.circular(999), bottomRight: Radius.circular(999),
) )
: BorderRadius.circular(12), : BorderRadius.circular(12),
), clipBehavior: Clip.antiAlias,
child: ListTile( child: ListTile(
leading: Icon(icon, color: iconColor ?? foregroundColor), leading: Icon(icon, color: iconColor ?? foregroundColor),
trailing: trailing, trailing: trailing,
title: Text( title: Text(
label, label,
style: TextStyle(color: textColor ?? foregroundColor, fontSize: 14), style: TextStyle(color: textColor ?? foregroundColor, fontSize: 14),
),
onTap: onTap,
hoverColor: Colors.white.withValues(alpha: 0.1),
), ),
onTap: onTap,
hoverColor: Colors.white.withValues(alpha: 0.1),
), ),
); );
} }