fleet_hazard
Turn scattered vehicle reports into map-ready hazard zones. Clusters individual snow/ice reports by geography and severity — pure Dart, no Flutter dependency.
Use fleet_hazard when you need to aggregate telemetry from multiple vehicles
into hazard zones that can be rendered on any map widget.
Features
FleetReportmodel with road condition, timestamp, confidence, and position.HazardZonecluster model with severity, vehicle count, and average confidence.HazardAggregatorpure-Dart clustering algorithm for snowy and icy reports.FleetProviderabstract interface so apps can swap simulated, local, or remote telemetry backends.- Pure Dart package with no Flutter dependency.
Install
dependencies:
fleet_hazard: ^0.3.0
Quick Start
import 'package:fleet_hazard/fleet_hazard.dart';
import 'package:latlong2/latlong.dart';
final reports = [
FleetReport(
vehicleId: 'V-001',
position: const LatLng(35.050, 137.250),
timestamp: DateTime.now(),
condition: RoadCondition.snowy,
),
FleetReport(
vehicleId: 'V-002',
position: const LatLng(35.052, 137.252),
timestamp: DateTime.now(),
condition: RoadCondition.icy,
),
];
final zones = HazardAggregator.aggregate(reports);
for (final zone in zones) {
print('${zone.severity.name}: ${zone.vehicleCount} vehicles');
}
Integration Pattern
fleet_hazard usually lives between a telemetry stream and a map overlay.
Collect reports from your provider, aggregate them into zones, then render the
zone summaries in whatever map widget or overlay layer your app uses.
import 'dart:async';
import 'package:fleet_hazard/fleet_hazard.dart';
import 'package:flutter/material.dart';
class HazardSummaryList extends StatefulWidget {
const HazardSummaryList({
super.key,
required this.provider,
});
final FleetProvider provider;
@override
State<HazardSummaryList> createState() => _HazardSummaryListState();
}
class _HazardSummaryListState extends State<HazardSummaryList> {
final reports = <FleetReport>[];
StreamSubscription<FleetReport>? subscription;
@override
void initState() {
super.initState();
subscription = widget.provider.reports.listen((report) {
setState(() {
reports.add(report);
});
});
widget.provider.startListening();
}
@override
void dispose() {
subscription?.cancel();
widget.provider.stopListening();
widget.provider.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final zones = HazardAggregator.aggregate(reports);
return ListView(
shrinkWrap: true,
children: [
for (final zone in zones)
ListTile(
title: Text('${zone.severity.name} zone'),
subtitle: Text(
'${zone.vehicleCount} vehicles • '
'${zone.radiusMeters.toStringAsFixed(0)}m radius',
),
),
],
);
}
}
In a full navigation UI, this same zones list is what you would pass to a map
overlay layer so the driver sees clustered snowy and icy segments, not raw per-
vehicle noise.
Implement a provider
class MyFleetProvider implements FleetProvider {
@override
Stream<FleetReport> get reports => _controller.stream;
@override
Future<void> startListening() async {
// Connect to your telemetry source
}
@override
Future<void> stopListening() async {
// Stop updates
}
@override
void dispose() {
// Release resources
}
}
API Overview
| Type | Purpose |
|---|---|
FleetReport |
Individual vehicle report carrying position, road condition, confidence, and timestamp. |
HazardZone |
Clustered geographic hazard summary with severity and confidence rollups. |
HazardAggregator |
Pure Dart clustering algorithm that converts reports into hazard zones. |
FleetProvider |
Stream-based interface for simulated, local, or remote fleet telemetry sources. |
RoadCondition |
Canonical hazard labels such as dry, snowy, and icy. |
Works With
| Package | How |
|---|---|
| driving_weather | Weather conditions correlate with fleet-reported hazards |
| map_viewport_bloc | Hazard zones render at Z3 in the viewport layer stack |
| driving_consent | Fleet data sharing requires explicit consent |
See Also
- driving_conditions — Road surface and safety scoring
- navigation_safety — Safety alert overlay
- kalman_dr — Dead reckoning through GPS loss
Part of SNGNav — 11 packages for offline-first navigation on Flutter.
License
BSD-3-Clause — see LICENSE.
Libraries
- fleet_hazard
- Fleet telemetry hazard model and clustering.