import 'package:flutter/material.dart'; import 'package:manager_api_new/api.dart'; import 'package:manager_app/Components/map_geometry_picker.dart'; import 'package:manager_app/constants.dart'; class GeometryInputContainer extends StatelessWidget { final String label; final GeometryDTO? initialGeometry; final String? initialColor; final Function(GeometryDTO, String) onSave; final Color color; final bool isSmall; GeometryInputContainer({ required this.label, this.initialGeometry, this.initialColor, required this.onSave, this.color = kPrimaryColor, this.isSmall = false, }); @override Widget build(BuildContext context) { String typeInfo = initialGeometry?.type ?? "Aucun"; int pointCount = 0; if (initialGeometry?.coordinates != null) { if (initialGeometry!.type == "Point") { pointCount = 1; } else if (initialGeometry!.coordinates is List) { pointCount = (initialGeometry!.coordinates as List).length; } } Size size = MediaQuery.of(context).size; return Container( margin: EdgeInsets.symmetric(vertical: 4), child: Row( children: [ Container( width: 150, child: Text( label, style: const TextStyle( fontWeight: FontWeight.w400, fontSize: 16, ), ), ), Container( width: isSmall ? size.width * 0.15 : size.width * 0.25, child: InkWell( onTap: () { showDialog( context: context, builder: (context) => MapGeometryPicker( initialGeometry: initialGeometry, initialColor: initialColor, onSave: onSave, ), ); }, child: Container( padding: EdgeInsets.symmetric(horizontal: 12, vertical: 8), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.circular(29), border: Border.all(color: kSecond), ), child: Row( children: [ Icon( _getIconForType(initialGeometry?.type), color: color, size: 20, ), SizedBox(width: 8), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( initialGeometry != null ? "$typeInfo ($pointCount pts)" : "Définir", style: TextStyle( fontSize: 13, color: initialGeometry != null ? kBlack : kSecond, overflow: TextOverflow.ellipsis, ), ), if (initialColor != null) Row( children: [ Container( width: 8, height: 8, decoration: BoxDecoration( color: _parseColor(initialColor!), shape: BoxShape.circle, ), ), SizedBox(width: 4), Text(initialColor!, style: TextStyle( fontSize: 9, color: Colors.grey)), ], ), ], ), ), Icon(Icons.edit, color: kSecond, size: 16), ], ), ), ), ), ], ), ); } IconData _getIconForType(String? type) { switch (type) { case "Point": return Icons.location_on; case "LineString": return Icons.show_chart; case "Polygon": return Icons.pentagon; default: return Icons.map; } } Color _parseColor(String hex) { try { return Color(int.parse(hex.replaceFirst('#', '0xFF'))); } catch (e) { return kPrimaryColor; } } }