feat: implement splash and onboarding flows, update app assets, and add project design documentation
This commit is contained in:
@@ -1,25 +1,44 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:intaleq_maps/intaleq_maps.dart';
|
||||
|
||||
/// خطاب polyline مشفر ومسافة/وقت تقريبيان.
|
||||
/// استجابة مسار من انطلق — مع polyline مشفر وإطار خريطة.
|
||||
class RouteModel extends Equatable {
|
||||
final int distanceMeters;
|
||||
final int durationSeconds;
|
||||
final String? polyline;
|
||||
final String? routeName;
|
||||
final String? startName;
|
||||
final String? endName;
|
||||
final List<String>? tags;
|
||||
final List<double>? bbox;
|
||||
final double? trafficFactor;
|
||||
|
||||
const RouteModel({
|
||||
required this.distanceMeters,
|
||||
required this.durationSeconds,
|
||||
this.polyline,
|
||||
this.routeName,
|
||||
this.startName,
|
||||
this.endName,
|
||||
this.tags,
|
||||
this.bbox,
|
||||
this.trafficFactor,
|
||||
});
|
||||
|
||||
/// استجابة مسار انطلق الحقيقية (تُمرر عبر الباك إند كما هي).
|
||||
factory RouteModel.fromJson(Map<String, dynamic> j) {
|
||||
final dist = j['distanceMeters'] ?? j['distance'];
|
||||
final dur = j['durationSeconds'] ?? j['duration'];
|
||||
final dist = (j['distance'] ?? 0) as num;
|
||||
final dur = (j['duration'] ?? 0) as num;
|
||||
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?,
|
||||
distanceMeters: dist.toInt(),
|
||||
durationSeconds: dur.toInt(),
|
||||
polyline: j['points'] as String?,
|
||||
routeName: j['routeName'] as String?,
|
||||
startName: j['startName'] as String?,
|
||||
endName: j['endName'] as String?,
|
||||
tags: (j['tags'] as List?)?.cast<String>(),
|
||||
bbox: (j['bbox'] as List?)?.map((e) => (e as num).toDouble()).toList(),
|
||||
trafficFactor: (j['trafficFactor'] as num?)?.toDouble(),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -36,39 +55,49 @@ class RouteModel extends Equatable {
|
||||
return '$h h ${rem > 0 ? '$rem min' : ''}';
|
||||
}
|
||||
|
||||
/// تحويل bbox إلى LatLngBounds لضبط الكاميرا مع حماية للمواقع القريبة على iOS.
|
||||
LatLngBounds? getLatLngBounds() {
|
||||
if (bbox == null || bbox!.length < 4) return null;
|
||||
var minLat = bbox![1];
|
||||
var minLng = bbox![0];
|
||||
var maxLat = bbox![3];
|
||||
var maxLng = bbox![2];
|
||||
|
||||
// إذا كانت المسافة بين النقاط قريبة جداً (أقل من 0.002 درجة)، نضمن توسعاً أمنياً أدنى لمنع عطل وقفل كاميرا MapLibre على iOS
|
||||
if ((maxLat - minLat).abs() < 0.002) {
|
||||
minLat -= 0.001;
|
||||
maxLat += 0.001;
|
||||
}
|
||||
if ((maxLng - minLng).abs() < 0.002) {
|
||||
minLng -= 0.001;
|
||||
maxLng += 0.001;
|
||||
}
|
||||
|
||||
return LatLngBounds(
|
||||
southwest: LatLng(minLat, minLng),
|
||||
northeast: LatLng(maxLat, maxLng),
|
||||
);
|
||||
}
|
||||
|
||||
/// فك الـ polyline عبر PolylineUtils من الباكيج.
|
||||
List<LatLng> decodePolyline() {
|
||||
if (polyline == null || polyline!.isEmpty) return [];
|
||||
return _decodeEncodedPolyline(polyline!);
|
||||
return PolylineUtils.decode(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;
|
||||
}
|
||||
/// هل المسار مباشر (لا أضلاع)?
|
||||
bool get isStraightLine => tags?.contains('straight-line') ?? false;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [distanceMeters, durationSeconds, polyline];
|
||||
List<Object?> get props => [
|
||||
distanceMeters,
|
||||
durationSeconds,
|
||||
polyline,
|
||||
routeName,
|
||||
startName,
|
||||
endName,
|
||||
tags,
|
||||
bbox,
|
||||
trafficFactor,
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user