104 lines
3.2 KiB
Dart
104 lines
3.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../../../core/theme/app_colors.dart';
|
|
import '../../../services/alerts/road_alert_models.dart';
|
|
import '../../../services/alerts/road_alert_service.dart';
|
|
import '../../../services/map/map_provider_interface.dart';
|
|
import '../../../services/map/unified_map_view.dart';
|
|
import '../../../services/telemetry_service.dart';
|
|
|
|
/// Embedded tactical map panel for Touring mode and responsive dashboard views.
|
|
///
|
|
/// Subscribes to vehicle coordinates and heading via [telemetryStreamProvider]
|
|
/// and alert pins via [activeAlertsStreamProvider].
|
|
class DashboardMapPanel extends ConsumerWidget {
|
|
final double zoom;
|
|
|
|
const DashboardMapPanel({
|
|
super.key,
|
|
this.zoom = 16.5,
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final vehicleCoords = ref.watch(
|
|
telemetryStreamProvider.select(
|
|
(s) => (
|
|
lat: s.value?.latitude,
|
|
lng: s.value?.longitude,
|
|
heading: s.value?.heading ?? 0.0,
|
|
),
|
|
),
|
|
);
|
|
|
|
final centerLat = (vehicleCoords.lat != null && vehicleCoords.lat != 0.0)
|
|
? vehicleCoords.lat!
|
|
: 37.7749;
|
|
final centerLng = (vehicleCoords.lng != null && vehicleCoords.lng != 0.0)
|
|
? vehicleCoords.lng!
|
|
: -122.4194;
|
|
|
|
final vehicleMarker = AppMapMarker(
|
|
id: 'dash_vehicle',
|
|
position: AppLatLng(centerLat, centerLng),
|
|
heading: vehicleCoords.heading,
|
|
iconWidget: const Icon(
|
|
Icons.navigation,
|
|
color: AppColors.cyberCyan,
|
|
size: 36,
|
|
),
|
|
);
|
|
|
|
final activeAlertsAsync = ref.watch(activeAlertsStreamProvider);
|
|
final activeAlerts = activeAlertsAsync.value ?? [];
|
|
final mapMarkers = <AppMapMarker>[vehicleMarker];
|
|
|
|
for (final alert in activeAlerts) {
|
|
mapMarkers.add(
|
|
AppMapMarker(
|
|
id: 'dash_alert__',
|
|
position: AppLatLng(alert.latitude, alert.longitude),
|
|
heading: alert.heading ?? 0.0,
|
|
label: alert.category.displayName,
|
|
iconWidget: Container(
|
|
padding: const EdgeInsets.all(4),
|
|
decoration: BoxDecoration(
|
|
color: alert.category.color.withValues(alpha: 0.9),
|
|
shape: BoxShape.circle,
|
|
boxShadow: const [BoxShadow(color: Colors.black54, blurRadius: 4)],
|
|
),
|
|
child: Icon(alert.category.icon, color: Colors.black, size: 16),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(14),
|
|
border: Border.all(
|
|
color: Theme.of(context).brightness == Brightness.dark
|
|
? AppColors.darkOutline
|
|
: AppColors.lightOutline,
|
|
width: 1.2,
|
|
),
|
|
),
|
|
clipBehavior: Clip.antiAlias,
|
|
child: LayoutBuilder(
|
|
builder: (context, constraints) {
|
|
return SizedBox(
|
|
width: constraints.maxWidth,
|
|
height: constraints.maxHeight,
|
|
child: UnifiedMapView(
|
|
key: ValueKey('dash_map_x'),
|
|
center: AppLatLng(centerLat, centerLng),
|
|
zoom: zoom,
|
|
markers: mapMarkers,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|