palm_bounding_box.dart 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import 'package:flutter/material.dart';
  2. import '../constants/mpob_colors.dart';
  3. /// A shared widget for displaying MPOB-standard bounding boxes.
  4. class PalmBoundingBox extends StatelessWidget {
  5. final Rect normalizedRect;
  6. final String label;
  7. final double confidence;
  8. final BoxConstraints constraints;
  9. final bool isLocked;
  10. final bool isManual;
  11. final double opacity;
  12. const PalmBoundingBox({
  13. super.key,
  14. required this.normalizedRect,
  15. required this.label,
  16. required this.confidence,
  17. required this.constraints,
  18. this.isLocked = false,
  19. this.isManual = false,
  20. this.opacity = 1.0,
  21. });
  22. /// MPOB-standard color palette
  23. Color _getMPOBColor(String label) {
  24. if (isLocked) return const Color(0xFF22C55E); // Force Green when locked
  25. return getMPOBColor(label);
  26. }
  27. @override
  28. Widget build(BuildContext context) {
  29. final color = _getMPOBColor(label);
  30. return Positioned(
  31. left: normalizedRect.left * constraints.maxWidth,
  32. top: normalizedRect.top * constraints.maxHeight,
  33. width: normalizedRect.width * constraints.maxWidth,
  34. height: normalizedRect.height * constraints.maxHeight,
  35. child: Opacity(
  36. opacity: opacity,
  37. child: Container(
  38. decoration: BoxDecoration(
  39. border: Border.all(color: color, width: 3),
  40. borderRadius: BorderRadius.circular(4),
  41. ),
  42. child: Align(
  43. alignment: Alignment.topLeft,
  44. child: Container(
  45. padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
  46. color: color,
  47. child: Text(
  48. "$label ${(confidence * 100).toStringAsFixed(0)}%${isManual ? ' • Added' : ''}",
  49. style: const TextStyle(
  50. color: Colors.white,
  51. fontSize: 10,
  52. fontWeight: FontWeight.bold,
  53. ),
  54. ),
  55. ),
  56. ),
  57. ),
  58. ),
  59. );
  60. }
  61. }