90 lines
2.8 KiB
Dart
90 lines
2.8 KiB
Dart
import 'road_alert_models.dart';
|
|
import 'road_alert_provider_interface.dart';
|
|
|
|
class LocalRoadAlertProvider implements RoadAlertProvider {
|
|
@override
|
|
String get id => 'local_demo';
|
|
|
|
@override
|
|
String get name => 'Demo / Local Alerts';
|
|
|
|
@override
|
|
Set<RoadAlertCategory> get supportedCategories => const {
|
|
RoadAlertCategory.police,
|
|
RoadAlertCategory.speedCamera,
|
|
RoadAlertCategory.accident,
|
|
RoadAlertCategory.hazard,
|
|
RoadAlertCategory.roadClosure,
|
|
RoadAlertCategory.construction,
|
|
RoadAlertCategory.traffic,
|
|
RoadAlertCategory.other,
|
|
};
|
|
|
|
@override
|
|
Future<RoadAlertProviderStatus> testConnection(String apiKey) async {
|
|
return RoadAlertProviderStatus.connected;
|
|
}
|
|
|
|
@override
|
|
Future<List<RoadAlert>> getAlerts({
|
|
required double latitude,
|
|
required double longitude,
|
|
required double radiusMeters,
|
|
String? apiKey,
|
|
}) async {
|
|
// Generate simulated road alerts within 200m-800m of the user for offline demo
|
|
final now = DateTime.now();
|
|
|
|
return [
|
|
RoadAlert(
|
|
id: 'demo_hazard_1',
|
|
providerId: id,
|
|
category: RoadAlertCategory.hazard,
|
|
latitude: latitude + 0.0025,
|
|
longitude: longitude + 0.0018,
|
|
roadName: 'Main Highway / Curve 4',
|
|
description: 'Debris reported in right lane',
|
|
reportedAt: now.subtract(const Duration(minutes: 10)),
|
|
expiresAt: now.add(const Duration(minutes: 50)),
|
|
lastUpdated: now,
|
|
confidence: 0.9,
|
|
severity: RoadAlertSeverity.medium,
|
|
source: 'Demo Local Provider',
|
|
sourceType: RoadAlertSourceType.userReported,
|
|
),
|
|
RoadAlert(
|
|
id: 'demo_construction_1',
|
|
providerId: id,
|
|
category: RoadAlertCategory.construction,
|
|
latitude: latitude - 0.0031,
|
|
longitude: longitude - 0.0022,
|
|
roadName: 'Valley Expressway',
|
|
description: 'Roadwork & lane closure ahead',
|
|
reportedAt: now.subtract(const Duration(minutes: 30)),
|
|
expiresAt: now.add(const Duration(hours: 2)),
|
|
lastUpdated: now,
|
|
confidence: 0.95,
|
|
severity: RoadAlertSeverity.high,
|
|
source: 'Demo Local Provider',
|
|
sourceType: RoadAlertSourceType.providerReported,
|
|
),
|
|
RoadAlert(
|
|
id: 'demo_police_1',
|
|
providerId: id,
|
|
category: RoadAlertCategory.police,
|
|
latitude: latitude + 0.0042,
|
|
longitude: longitude - 0.0015,
|
|
roadName: 'State Route 9',
|
|
description: 'Police reported on shoulder',
|
|
reportedAt: now.subtract(const Duration(minutes: 5)),
|
|
expiresAt: now.add(const Duration(minutes: 25)),
|
|
lastUpdated: now,
|
|
confidence: 0.75,
|
|
severity: RoadAlertSeverity.medium,
|
|
source: 'Demo Community Report',
|
|
sourceType: RoadAlertSourceType.userReported,
|
|
),
|
|
];
|
|
}
|
|
}
|