driving_weather 0.2.0
driving_weather: ^0.2.0 copied to clipboard
Weather condition model for driving applications — snow, ice, visibility, and hazardous conditions detection. Precipitation type/intensity, wind speed, ice risk, and temperature monitoring. Includes O [...]
driving_weather #
Weather condition model and provider abstraction for driving applications.
When to use this package #
Use driving_weather when you need a consistent weather model plus a swappable
provider interface for real and simulated driving conditions.
Features #
- WeatherCondition — Equatable model with precipitation type/intensity, temperature, visibility, wind speed, and ice risk
- WeatherProvider — Abstract interface for pluggable weather data sources
- OpenMeteoWeatherProvider — Real weather from Open-Meteo (free, no API key) with offline fallback
- SimulatedWeatherProvider — Demo provider with a realistic mountain-pass snow scenario
Install #
dependencies:
driving_weather: ^0.1.2
Quick Start #
import 'package:driving_weather/driving_weather.dart';
// Real weather from Open-Meteo (Nagoya region default)
final provider = OpenMeteoWeatherProvider(
latitude: 35.18,
longitude: 136.91,
);
await provider.startMonitoring();
provider.conditions.listen((condition) {
print('${condition.precipType.name} ${condition.intensity.name}');
print('Visibility: ${condition.visibilityMeters}m');
if (condition.isHazardous) {
print('⚠ Hazardous conditions detected');
}
if (condition.iceRisk) {
print('⚠ Ice risk — temperature: ${condition.temperatureCelsius}°C');
}
});
Simulated weather (for demos and testing) #
final sim = SimulatedWeatherProvider(
interval: Duration(seconds: 5),
);
await sim.startMonitoring();
// Cycles: clear → light snow → moderate → heavy → ice → clearing
Integration Pattern #
The usual app pattern is: start one weather provider in initState, subscribe
through StreamBuilder, and convert the raw condition into a compact status bar
or alert strip. This keeps the weather source swappable while the UI stays
stable.
import 'package:driving_weather/driving_weather.dart';
import 'package:flutter/material.dart';
class WeatherBanner extends StatefulWidget {
const WeatherBanner({super.key});
@override
State<WeatherBanner> createState() => _WeatherBannerState();
}
class _WeatherBannerState extends State<WeatherBanner> {
late final WeatherProvider provider;
@override
void initState() {
super.initState();
provider = SimulatedWeatherProvider(
interval: const Duration(seconds: 5),
)..startMonitoring();
}
@override
void dispose() {
provider.stopMonitoring();
provider.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return StreamBuilder<WeatherCondition>(
stream: provider.conditions,
builder: (context, snapshot) {
final condition = snapshot.data;
if (condition == null) {
return const Text('Loading weather...');
}
return ListTile(
title: Text(
'${condition.precipType.name} '
'${condition.intensity.name}',
),
subtitle: Text(
'Visibility ${condition.visibilityMeters.toStringAsFixed(0)}m • '
'Ice risk ${condition.iceRisk ? 'yes' : 'no'}',
),
trailing: condition.isHazardous
? const Icon(Icons.warning_amber_rounded)
: const Icon(Icons.cloud_outlined),
);
},
);
}
}
Swap SimulatedWeatherProvider for OpenMeteoWeatherProvider when you move
from demo mode to live weather. The widget contract does not have to change.
Custom weather source #
class MyFleetWeatherProvider implements WeatherProvider {
// Implement the 4 methods: conditions, startMonitoring,
// stopMonitoring, dispose
}
API Overview #
| Type | Purpose |
|---|---|
WeatherCondition |
Snapshot of precipitation, temperature, visibility, wind, and ice risk. |
WeatherProvider |
Abstract interface for live or simulated weather sources. |
OpenMeteoWeatherProvider |
Pulls real weather data with offline fallback behavior. |
SimulatedWeatherProvider |
Provides deterministic demo and test weather sequences. |
Model #
| Field | Type | Description |
|---|---|---|
precipType |
PrecipitationType |
none, rain, snow, sleet, hail |
intensity |
PrecipitationIntensity |
none, light, moderate, heavy |
temperatureCelsius |
double |
Temperature in °C |
visibilityMeters |
double |
10000 = clear, <1000 = reduced, <200 = hazardous |
windSpeedKmh |
double |
Wind speed |
iceRisk |
bool |
Black ice / road icing risk |
timestamp |
DateTime |
Observation time |
Convenience getters #
isSnowing— snow at any intensityhasReducedVisibility— visibility < 1 kmisHazardous— heavy precip, very low visibility, or iceisFreezing— temperature ≤ 0°C
Safety #
ASIL-QM — display and advisory only. Not for vehicle control.
See Also #
- kalman_dr — Dead reckoning through GPS loss (tunnels, urban canyons)
- routing_engine — Engine-agnostic routing (OSRM + Valhalla)
- driving_consent — Privacy consent with Jidoka semantics (UNKNOWN = DENIED)
- fleet_hazard — Fleet telemetry hazard model and geographic clustering
- driving_conditions — Pure Dart computation models for road surface, visibility, and safety score simulation
- navigation_safety — Flutter navigation safety state machine and safety overlay
- map_viewport_bloc — Flutter viewport and layer composition state machine
- routing_bloc — Flutter route lifecycle state machine and progress UI
- offline_tiles — Flutter offline tile manager with MBTiles fallback
Part of SNGNav #
driving_weather is one of the 10 packages in
SNGNav, an offline-first,
driver-assisting navigation reference product for embedded Linux.