feat: implement core architecture, design system, localization, and trip features for both driver and rider apps.
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:intaleq_maps/intaleq_maps.dart';
|
||||
|
||||
/// خطاب polyline مشفر ومسافة/وقت تقريبيان.
|
||||
class RouteModel extends Equatable {
|
||||
final int distanceMeters;
|
||||
final int durationSeconds;
|
||||
final String? polyline;
|
||||
|
||||
const RouteModel({
|
||||
required this.distanceMeters,
|
||||
required this.durationSeconds,
|
||||
this.polyline,
|
||||
});
|
||||
|
||||
factory RouteModel.fromJson(Map<String, dynamic> j) {
|
||||
final dist = j['distanceMeters'] ?? j['distance'];
|
||||
final dur = j['durationSeconds'] ?? j['duration'];
|
||||
return RouteModel(
|
||||
distanceMeters: dist is int ? dist : int.tryParse('$dist') ?? 0,
|
||||
durationSeconds: dur is int ? dur : int.tryParse('$dur') ?? 0,
|
||||
polyline: j['polyline'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
String get distanceText {
|
||||
if (distanceMeters < 1000) return '$distanceMeters m';
|
||||
return '${(distanceMeters / 1000).toStringAsFixed(1)} km';
|
||||
}
|
||||
|
||||
String get durationText {
|
||||
final min = durationSeconds ~/ 60;
|
||||
if (min < 60) return '$min min';
|
||||
final h = min ~/ 60;
|
||||
final rem = min % 60;
|
||||
return '$h h ${rem > 0 ? '$rem min' : ''}';
|
||||
}
|
||||
|
||||
List<LatLng> decodePolyline() {
|
||||
if (polyline == null || polyline!.isEmpty) return [];
|
||||
return _decodeEncodedPolyline(polyline!);
|
||||
}
|
||||
|
||||
/// فك تشفير polyline وفقاً لخوارزمية Google.
|
||||
static List<LatLng> _decodeEncodedPolyline(String encoded) {
|
||||
final List<LatLng> poly = [];
|
||||
int index = 0, lat = 0, lng = 0;
|
||||
|
||||
while (index < encoded.length) {
|
||||
int b, shift = 0, result = 0;
|
||||
do {
|
||||
b = encoded.codeUnitAt(index++) - 63;
|
||||
result |= (b & 0x1f) << shift;
|
||||
shift += 5;
|
||||
} while (b >= 0x20);
|
||||
lat += ((result & 1) != 0) ? ~(result >> 1) : (result >> 1);
|
||||
|
||||
shift = 0;
|
||||
result = 0;
|
||||
do {
|
||||
b = encoded.codeUnitAt(index++) - 63;
|
||||
result |= (b & 0x1f) << shift;
|
||||
shift += 5;
|
||||
} while (b >= 0x20);
|
||||
lng += ((result & 1) != 0) ? ~(result >> 1) : (result >> 1);
|
||||
|
||||
poly.add(LatLng(lat / 1e5, lng / 1e5));
|
||||
}
|
||||
return poly;
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [distanceMeters, durationSeconds, polyline];
|
||||
}
|
||||
Reference in New Issue
Block a user