import 'package:flutter/material.dart'; /// A shared widget for displaying MPOB-standard bounding boxes. class PalmBoundingBox extends StatelessWidget { final Rect normalizedRect; final String label; final double confidence; final BoxConstraints constraints; final bool isLocked; const PalmBoundingBox({ super.key, required this.normalizedRect, required this.label, required this.confidence, required this.constraints, this.isLocked = false, }); /// MPOB-standard color palette Color _getMPOBColor(String label) { if (isLocked) return const Color(0xFF22C55E); // Force Green when locked switch (label) { case 'Ripe': return const Color(0xFF22C55E); // Industrial Green case 'Underripe': return const Color(0xFFFBBF24); // Industrial Orange/Yellow case 'Unripe': return const Color(0xFF3B82F6); // Industrial Blue case 'Abnormal': return const Color(0xFFDC2626); // Critical Red case 'Empty_Bunch': return const Color(0xFF64748B); // Waste Gray default: return Colors.yellow; } } @override Widget build(BuildContext context) { final color = _getMPOBColor(label); return Positioned( left: normalizedRect.left * constraints.maxWidth, top: normalizedRect.top * constraints.maxHeight, width: normalizedRect.width * constraints.maxWidth, height: normalizedRect.height * constraints.maxHeight, child: Container( decoration: BoxDecoration( border: Border.all(color: color, width: 3), borderRadius: BorderRadius.circular(4), ), child: Align( alignment: Alignment.topLeft, child: Container( padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2), color: color, child: Text( "$label ${(confidence * 100).toStringAsFixed(0)}%", style: const TextStyle( color: Colors.white, fontSize: 10, fontWeight: FontWeight.bold, ), ), ), ), ), ); } }