import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:pad_scanner/pages/boxing/boxing_models.dart'; import 'package:pad_scanner/pages/boxing/widgets/boxing_shared_widgets.dart'; class MultiPackedRow extends StatelessWidget { final ManyToOnePackedItem item; final bool editing; final bool deleting; final bool isSubmitting; final String editingQuantity; final ValueChanged onEditingQuantityChanged; final VoidCallback onSave; final VoidCallback onCancelEdit; final VoidCallback onStartEdit; final VoidCallback onStartDelete; final VoidCallback onDelete; final VoidCallback onCancelDelete; const MultiPackedRow({ super.key, required this.item, required this.editing, required this.deleting, required this.isSubmitting, required this.editingQuantity, required this.onEditingQuantityChanged, required this.onSave, required this.onCancelEdit, required this.onStartEdit, required this.onStartDelete, required this.onDelete, required this.onCancelDelete, }); @override Widget build(BuildContext context) { final totalText = item.totalQuantity?.toString() ?? '--'; final barColor = editing ? Colors.amber : (deleting ? Colors.red : Colors.green); final Color bgColor; if (editing) { bgColor = Colors.yellow.shade50; } else if (deleting) { bgColor = Colors.red.shade50; } else { bgColor = Colors.transparent; } final rowStyle = TextStyle( fontSize: 15, fontWeight: FontWeight.w500, color: Colors.black87, ); return Column( children: [ Container( constraints: const BoxConstraints(minHeight: 36), padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6), decoration: BoxDecoration( color: bgColor, border: Border( left: BorderSide(color: barColor, width: 3), bottom: BorderSide(color: Colors.grey.shade200), ), ), child: Row( children: [ Expanded( flex: 26, child: Text( item.zongpaiNo, textAlign: TextAlign.center, overflow: TextOverflow.ellipsis, style: rowStyle.copyWith(fontWeight: FontWeight.w700), ), ), Expanded( flex: 30, child: Text( item.workOrderNo ?? '--', textAlign: TextAlign.center, overflow: TextOverflow.ellipsis, style: rowStyle, ), ), Expanded( flex: 23, child: editing ? SizedBox( width: 52, height: 26, child: TextField( keyboardType: TextInputType.none, inputFormatters: [ FilteringTextInputFormatter.digitsOnly, ], textAlign: TextAlign.center, controller: TextEditingController(text: editingQuantity) ..selection = TextSelection.collapsed( offset: editingQuantity.length, ), onChanged: onEditingQuantityChanged, decoration: InputDecoration( contentPadding: const EdgeInsets.symmetric( horizontal: 4, ), border: OutlineInputBorder( borderRadius: BorderRadius.circular(4), borderSide: const BorderSide( color: Colors.amber, width: 1.5, ), ), ), style: const TextStyle( fontSize: 15, fontWeight: FontWeight.w600, ), ), ) : Text( '${item.quantity} / $totalText', textAlign: TextAlign.center, style: TextStyle( fontSize: 15, fontWeight: FontWeight.w600, color: deleting ? Colors.red : Colors.green.shade700, ), ), ), SizedBox( width: 54, child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ if (editing) ...[ CompactIconButton( icon: Icons.check, color: Colors.green, onTap: isSubmitting ? null : onSave, ), CompactIconButton( icon: Icons.close, color: Colors.grey, onTap: isSubmitting ? null : onCancelEdit, ), ] else ...[ CompactIconButton( icon: Icons.edit, color: Colors.grey.shade700, onTap: isSubmitting ? null : onStartEdit, ), CompactIconButton( icon: Icons.delete_outline, color: Colors.red, onTap: isSubmitting ? null : onStartDelete, ), ], ], ), ), ], ), ), if (deleting) Container( height: 28, padding: const EdgeInsets.only(left: 15, right: 12), decoration: BoxDecoration( color: Colors.red.shade50, border: Border(bottom: BorderSide(color: Colors.red.shade200)), ), child: Row( children: [ Expanded( child: Text( '确认删除?', style: const TextStyle( fontSize: 12, color: Colors.red, fontWeight: FontWeight.w500, ), ), ), TextButton( onPressed: isSubmitting ? null : onDelete, style: TextButton.styleFrom( padding: const EdgeInsets.symmetric( horizontal: 8, vertical: 3, ), minimumSize: Size.zero, tapTargetSize: MaterialTapTargetSize.shrinkWrap, backgroundColor: Colors.red.shade100, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(4), ), ), child: const Text( '删除', style: TextStyle( fontSize: 12, fontWeight: FontWeight.w700, color: Colors.red, ), ), ), const SizedBox(width: 4), TextButton( onPressed: isSubmitting ? null : onCancelDelete, style: TextButton.styleFrom( padding: const EdgeInsets.symmetric( horizontal: 8, vertical: 3, ), minimumSize: Size.zero, tapTargetSize: MaterialTapTargetSize.shrinkWrap, ), child: const Text( '取消', style: TextStyle( fontSize: 12, fontWeight: FontWeight.w700, color: Colors.grey, ), ), ), ], ), ), ], ); } }