Aidra Driver 1.3.5+68
Aidra Driver - Your path to green energy
Loading...
Searching...
No Matches
driver_requests_repository.dart
Go to the documentation of this file.
1import 'dart:convert';
2import 'package:http/http.dart' as http;
3import '../models/driver_request.dart';
4
6 static const String _apiUrl = 'https://www.jsonkeeper.com/b/MJLRW';
7
8 static Future<List<DriverRequest>> getMockedRequests() async {
9 final response = await http.get(Uri.parse(_apiUrl));
10
11 if (response.statusCode == 200) {
12 final Map<String, dynamic> jsonData = json.decode(response.body);
13 final List<dynamic> driverRequestsJson = jsonData['driverRequests'];
14
15 final requests = driverRequestsJson
16 .map((json) => DriverRequest.fromJson(json))
17 .toList();
18
19 // Tweak dates to today with varying times between 8 AM to 6 PM
20 return _tweakRequestDates(requests);
21 } else {
22 throw Exception('Failed to load driver requests: ${response.statusCode}');
23 }
24 }
25
27 static List<DriverRequest> _tweakRequestDates(List<DriverRequest> requests) {
28 final now = DateTime.now();
29 final today = DateTime(now.year, now.month, now.day);
30
31 return requests.asMap().entries.map((entry) {
32 final index = entry.key;
33 final request = entry.value;
34
35 // Calculate hour between 8 AM (8) and 6 PM (18)
36 // Distribute evenly across the day based on request index
37 final totalHours = 10; // 8 AM to 6 PM = 10 hours
38 final hourInterval = totalHours / requests.length;
39 final hour = 8 + (index * hourInterval).floor();
40
41 // Add some minute variation (0-59 minutes)
42 final minute = (index * 17) % 60; // 17 gives good distribution
43
44 final newCreationDate = today.add(Duration(hours: hour, minutes: minute));
45
46 return DriverRequest(
47 id: request.id,
48 driverName: request.driverName,
49 creationDate: newCreationDate,
50 stations: request.stations,
51 startPoint: request.startPoint,
52 endPoint: request.endPoint,
53 );
54 }).toList();
55 }
56}
abstract class CollectionsToScheduleEvent extends Equatable request
class Partner String
final String startPoint
final List< Station > stations
DriverRequest({ required this.id, required this.driverName, required this.creationDate, required this.stations, required this.startPoint, required this.endPoint, })
final String endPoint
final DateTime creationDate
final String driverName