feat: Add long press functionality to menu items for category editing

This commit is contained in:
2026-05-22 10:54:56 +02:00
parent e0f226d3bc
commit 2069de55ae
+10 -5
View File
@@ -56,10 +56,12 @@ class MenuDrawer extends StatelessWidget {
label: category.name, label: category.name,
selected: selectedItem == categoryId, selected: selectedItem == categoryId,
onTap: () => onMenuItemTapped?.call(categoryId), onTap: () => onMenuItemTapped?.call(categoryId),
onLongPress: onEditCategory == null
? null
: () => onEditCategory?.call(category),
iconColor: Color(category.colorValue ?? 0xFFFFC107), iconColor: Color(category.colorValue ?? 0xFFFFC107),
textColor: Color(category.colorValue ?? 0xFFFFC107), textColor: Color(category.colorValue ?? 0xFFFFC107),
trailing: selectedItem == categoryId trailing: IconButton(
? IconButton(
padding: const EdgeInsets.all(8), padding: const EdgeInsets.all(8),
constraints: const BoxConstraints( constraints: const BoxConstraints(
minWidth: 0, minWidth: 0,
@@ -71,8 +73,7 @@ class MenuDrawer extends StatelessWidget {
size: 20, size: 20,
), ),
onPressed: () => onEditCategory?.call(category), onPressed: () => onEditCategory?.call(category),
) ),
: null,
); );
}).toList(), }).toList(),
), ),
@@ -113,6 +114,7 @@ class _MenuItemTile extends StatefulWidget {
required this.label, required this.label,
this.selected = false, this.selected = false,
this.onTap, this.onTap,
this.onLongPress,
this.iconColor, this.iconColor,
this.textColor, this.textColor,
this.trailing, this.trailing,
@@ -122,6 +124,7 @@ class _MenuItemTile extends StatefulWidget {
final String label; final String label;
final bool selected; final bool selected;
final VoidCallback? onTap; final VoidCallback? onTap;
final VoidCallback? onLongPress;
final Color? iconColor; final Color? iconColor;
final Color? textColor; final Color? textColor;
final Widget? trailing; final Widget? trailing;
@@ -140,6 +143,7 @@ class _MenuItemTileState extends State<_MenuItemTile> {
? Colors.white.withValues(alpha: 0.10) ? Colors.white.withValues(alpha: 0.10)
: Colors.transparent; : Colors.transparent;
final Color foregroundColor = active ? Colors.white : Colors.white70; final Color foregroundColor = active ? Colors.white : Colors.white70;
final Widget? trailing = _hovering ? widget.trailing : null;
return MouseRegion( return MouseRegion(
onEnter: (_) { onEnter: (_) {
@@ -166,12 +170,13 @@ class _MenuItemTileState extends State<_MenuItemTile> {
child: ListTile( child: ListTile(
contentPadding: const EdgeInsets.only(left: 16, right: 8), contentPadding: const EdgeInsets.only(left: 16, right: 8),
leading: Icon(widget.icon, color: widget.iconColor ?? foregroundColor), leading: Icon(widget.icon, color: widget.iconColor ?? foregroundColor),
trailing: widget.trailing, trailing: trailing,
title: Text( title: Text(
widget.label, widget.label,
style: TextStyle(color: widget.textColor ?? foregroundColor, fontSize: 14), style: TextStyle(color: widget.textColor ?? foregroundColor, fontSize: 14),
), ),
onTap: widget.onTap, onTap: widget.onTap,
onLongPress: widget.onLongPress,
), ),
), ),
), ),