Files
flutterApp/lib/features/regions/presentation/widgets/region_boundary_layer.dart
2026-11-06 08:44:05 +08:00

99 lines
3.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
/// 独立分区图层,不复用或修改圈地路线的草稿点、障碍和返航线。
class RegionBoundaryLayer extends StatelessWidget {
const RegionBoundaryLayer({
super.key,
required this.points,
this.selected = true,
this.enabled = true,
this.showVertices = true,
this.label,
});
final List<LatLng> points;
final bool selected;
final bool enabled;
final bool showVertices;
final String? label;
Color get _color => enabled ? const Color(0xFF1C96F6) : Colors.grey;
@override
Widget build(BuildContext context) => Stack(
fit: StackFit.expand,
children: [
if (points.length == 4)
PolygonLayer(
polygons: [
Polygon(
points: points,
color: _color.withValues(alpha: selected ? 0.28 : 0.12),
borderColor: _color,
borderStrokeWidth: selected ? 3 : 1.5,
),
],
),
if (points.length > 1 && points.length < 4)
PolylineLayer(
polylines: [Polyline(points: points, color: _color, strokeWidth: 2)],
),
MarkerLayer(
markers: [
if (showVertices)
for (var index = 0; index < points.length; index++)
Marker(
point: points[index],
width: 24,
height: 24,
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
color: _color,
shape: BoxShape.circle,
border: Border.all(color: Colors.white, width: 2),
),
child: Text(
'${index + 1}',
style: const TextStyle(
color: Colors.white,
fontSize: 11,
fontWeight: FontWeight.w800,
),
),
),
),
if (label != null && label!.isNotEmpty && points.isNotEmpty)
Marker(
point: LatLngBounds.fromPoints(points).center,
width: 140,
height: 32,
child: Center(
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 8,
vertical: 4,
),
decoration: BoxDecoration(
color: _color.withValues(alpha: selected ? 0.95 : 0.75),
borderRadius: BorderRadius.circular(6),
),
child: Text(
label!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 11,
color: Colors.white,
fontWeight: FontWeight.w700,
),
),
),
),
),
],
),
],
);
}