diff --git a/lib/screens/medicine_cabinet_screen.dart b/lib/screens/medicine_cabinet_screen.dart index f5f2fbc..775d7e3 100644 --- a/lib/screens/medicine_cabinet_screen.dart +++ b/lib/screens/medicine_cabinet_screen.dart @@ -109,7 +109,10 @@ class _MedicineCabinetScreenState extends State { Future _editMedicine(MedicineItem item) async { final updatedItem = await showDialog( context: context, - builder: (_) => MedicineEditDialog(initialItem: item), + builder: (_) => MedicineEditDialog( + initialItem: item, + onDelete: () => _deleteMedicine(item), + ), ); if (updatedItem != null) { @@ -544,15 +547,31 @@ class _MedicineCabinetScreenState extends State { ), PopupMenuButton( icon: const Icon(Icons.more_vert, size: 20, color: Colors.grey), + tooltip: '更多操作', onSelected: (val) { if (val == 'edit') _editMedicine(item); if (val == 'delete') _deleteMedicine(item); }, itemBuilder: (ctx) => [ - const PopupMenuItem(value: 'edit', child: Text('编辑药品')), + const PopupMenuItem( + value: 'edit', + child: Row( + children: [ + Icon(Icons.edit_outlined, size: 18, color: Colors.black87), + SizedBox(width: 8), + Text('编辑药品'), + ], + ), + ), const PopupMenuItem( value: 'delete', - child: Text('移出药箱', style: TextStyle(color: Colors.red)), + child: Row( + children: [ + Icon(Icons.delete_outline, size: 18, color: Colors.red), + SizedBox(width: 8), + Text('删除药品', style: TextStyle(color: Colors.red, fontWeight: FontWeight.bold)), + ], + ), ), ], ), @@ -685,7 +704,7 @@ class _MedicineCabinetScreenState extends State { ), ], - // 危险警告提醒条 (超期或过期) + // 危险警告提醒条 (超期或过期,带一键下架/清理按钮) if (isDanger) ...[ const SizedBox(height: 8), Container( @@ -702,11 +721,22 @@ class _MedicineCabinetScreenState extends State { Expanded( child: Text( item.healthStatus == MedicineHealthStatus.overdueInUse - ? '已超出开封后推荐使用期限,易滋生细菌/失效,建议丢弃更换。' + ? '已超出开封推荐使用期限,易滋生细菌/失效。' : '已超出出厂有效期,严禁继续使用!', style: const TextStyle(color: Colors.red, fontSize: 11, fontWeight: FontWeight.w600), ), ), + TextButton.icon( + style: TextButton.styleFrom( + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2), + minimumSize: Size.zero, + tapTargetSize: MaterialTapTargetSize.shrinkWrap, + foregroundColor: Colors.red, + ), + onPressed: () => _deleteMedicine(item), + icon: const Icon(Icons.delete_outline, size: 14), + label: const Text('清理下架', style: TextStyle(fontSize: 11, fontWeight: FontWeight.bold)), + ), ], ), ), diff --git a/lib/screens/medicine_edit_dialog.dart b/lib/screens/medicine_edit_dialog.dart index 4dfa419..ac441c6 100644 --- a/lib/screens/medicine_edit_dialog.dart +++ b/lib/screens/medicine_edit_dialog.dart @@ -7,11 +7,13 @@ import '../services/medicine_parser_service.dart'; class MedicineEditDialog extends StatefulWidget { final MedicineItem? initialItem; final ScannedMedicineInfo? scannedInfo; + final VoidCallback? onDelete; const MedicineEditDialog({ super.key, this.initialItem, this.scannedInfo, + this.onDelete, }); @override @@ -568,10 +570,41 @@ class _MedicineEditDialogState extends State { ), child: Row( children: [ - TextButton( - onPressed: () => Navigator.pop(context), - child: const Text('取消', style: TextStyle(color: Colors.grey)), - ), + if (isEditing && widget.onDelete != null) + TextButton.icon( + style: TextButton.styleFrom(foregroundColor: Colors.red), + onPressed: () async { + final confirm = await showDialog( + context: context, + builder: (ctx) => AlertDialog( + title: const Text('确认删除该药品?'), + content: Text('确定将【${widget.initialItem!.name}】移出药箱吗?该操作将多端同步生效。'), + actions: [ + TextButton( + onPressed: () => Navigator.pop(ctx, false), + child: const Text('取消'), + ), + ElevatedButton( + style: ElevatedButton.styleFrom(backgroundColor: Colors.red), + onPressed: () => Navigator.pop(ctx, true), + child: const Text('确认删除', style: TextStyle(color: Colors.white)), + ), + ], + ), + ); + if (confirm == true && context.mounted) { + Navigator.pop(context); + widget.onDelete!(); + } + }, + icon: const Icon(Icons.delete_outline, size: 18), + label: const Text('删除药品'), + ) + else + TextButton( + onPressed: () => Navigator.pop(context), + child: const Text('取消', style: TextStyle(color: Colors.grey)), + ), const Spacer(), ElevatedButton.icon( style: ElevatedButton.styleFrom(