feat(tactical): sovereign military suite with 100% real satellite DEM intervisibility, viewshed 360, offline engines, and entitlements

This commit is contained in:
Hamza-Ayed
2026-08-22 15:11:16 +03:00
parent 4a7859f4c2
commit c10fd2396c
74 changed files with 14866 additions and 4001 deletions
@@ -4,7 +4,9 @@ import 'package:flutter_compass/flutter_compass.dart';
import '../models/angle_unit.dart';
import '../models/landmark.dart';
import '../services/landmark_database.dart';
import '../services/local_sqlite_db.dart';
import '../services/resection_calculator.dart';
import '../services/tactical_api_service.dart';
import 'tactical_crosshair.dart';
class CameraResectionView extends StatefulWidget {
@@ -32,57 +34,40 @@ class CameraResectionView extends StatefulWidget {
class _CameraResectionViewState extends State<CameraResectionView> {
CameraController? _cameraController;
bool _isCameraReady = false;
double _headingDeg = 45.0;
double _headingDeg = 0.0;
bool _isLockedAnim = false;
// Search & Filter state
// Search state
final TextEditingController _searchController = TextEditingController();
String _selectedRegion = 'الكل';
List<TacticalLandmark> _filteredLandmarks = [];
List<TacticalLandmark> _searchResults = [];
bool _isSearching = false;
TacticalLandmark? _selectedLandmark;
final List<String> _regions = const [
'الكل',
'عمان الغربية',
'وسط عمان',
'شمال عمان',
'الزرقاء',
'إربد',
'عجلون',
'جرش',
'المفرق',
'الكرك',
'الطفيلة',
'معان',
'العقبة',
];
@override
void initState() {
super.initState();
_filteredLandmarks = LandmarkDatabase.allLandmarks;
if (_filteredLandmarks.isNotEmpty) {
_selectedLandmark = _filteredLandmarks[0];
}
_initCamera();
_initCompass();
_initDefaultLandmark();
}
void _initDefaultLandmark() {
final all = LandmarkDatabase.allLandmarks;
if (all.isNotEmpty) {
_selectedLandmark = all[0];
_searchResults = all.take(10).toList();
}
}
Future<void> _initCamera() async {
try {
final cameras = await availableCameras();
if (cameras.isNotEmpty) {
final backCamera = cameras.firstWhere(
(c) => c.lensDirection == CameraLensDirection.back,
orElse: () => cameras.first,
);
_cameraController = CameraController(
backCamera,
cameras.first,
ResolutionPreset.high,
enableAudio: false,
);
await _cameraController!.initialize();
if (mounted) {
setState(() => _isCameraReady = true);
@@ -110,31 +95,53 @@ class _CameraResectionViewState extends State<CameraResectionView> {
super.dispose();
}
void _onSearchChanged(String query) {
setState(() {
_filteredLandmarks = LandmarkDatabase.search(
query,
region: _selectedRegion,
);
if (_filteredLandmarks.isNotEmpty &&
!_filteredLandmarks.any((l) => l.id == _selectedLandmark?.id)) {
_selectedLandmark = _filteredLandmarks[0];
}
});
}
Future<void> _onSearchChanged(String query) async {
final cleanQuery = query.trim();
if (cleanQuery.isEmpty) {
setState(() {
_searchResults = LandmarkDatabase.allLandmarks.take(10).toList();
_isSearching = false;
});
return;
}
void _onRegionSelected(String region) {
setState(() {
_selectedRegion = region;
_filteredLandmarks = LandmarkDatabase.search(
_searchController.text,
region: region,
);
if (_filteredLandmarks.isNotEmpty &&
!_filteredLandmarks.any((l) => l.id == _selectedLandmark?.id)) {
_selectedLandmark = _filteredLandmarks[0];
setState(() => _isSearching = true);
// 1. Search SQLite Local Places Database (Mosques, Schools, Intersections, Hills)
List<TacticalLandmark> dbResults = [];
try {
dbResults = await LocalSqliteDb.searchPlaces(cleanQuery, limit: 30);
} catch (_) {}
// 2. Search Static Strategic Landmarks
final staticResults = LandmarkDatabase.search(cleanQuery);
// 3. Search Online Geocoding API if local results are few
List<TacticalLandmark> onlineResults = [];
if (dbResults.length < 5) {
try {
onlineResults = await TacticalApiService.searchOnlinePlaces(cleanQuery);
} catch (_) {}
}
final combined = <TacticalLandmark>[...dbResults, ...onlineResults, ...staticResults];
final seen = <String>{};
final unique = <TacticalLandmark>[];
for (final r in combined) {
if (seen.add('${r.name}_${r.lat}_${r.lng}')) {
unique.add(r);
}
});
}
if (mounted) {
setState(() {
_searchResults = unique;
_isSearching = false;
if (_searchResults.isNotEmpty && !_searchResults.any((l) => l.id == _selectedLandmark?.id)) {
_selectedLandmark = _searchResults[0];
}
});
}
}
void _lockCurrentObservation() {
@@ -155,12 +162,27 @@ class _CameraResectionViewState extends State<CameraResectionView> {
widget.onObservationAdded(obs);
final remaining = _filteredLandmarks
.where((l) => l.id != _selectedLandmark!.id && !widget.observations.any((o) => o.landmark.id == l.id))
.toList();
if (remaining.isNotEmpty) {
setState(() => _selectedLandmark = remaining[0]);
// Auto-advance to map calculation if we have 2 observations
final nextObsCount = widget.observations.length +
(widget.observations.any((o) => o.landmark.id == obs.landmark.id) ? 0 : 1);
if (nextObsCount >= 2) {
Future.delayed(const Duration(milliseconds: 400), () {
if (mounted) {
widget.onCalculatePressed();
}
});
return;
}
// Reset search for second landmark
_searchController.clear();
setState(() {
_searchResults = LandmarkDatabase.allLandmarks.where((l) => l.id != _selectedLandmark!.id).take(10).toList();
if (_searchResults.isNotEmpty) {
_selectedLandmark = _searchResults[0];
}
});
}
@override
@@ -193,31 +215,8 @@ class _CameraResectionViewState extends State<CameraResectionView> {
colors: [Color(0xFF0F172A), Color(0xFF020617)],
),
),
child: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: const Color(0x330071E3),
borderRadius: BorderRadius.circular(50),
border: Border.all(color: const Color(0x660071E3)),
),
child: const Icon(Icons.camera_alt, size: 36, color: Color(0xFF38BDF8)),
),
const SizedBox(height: 12),
const Text(
'منظار الاستطلاع والتسديد البصري (HUD)',
style: TextStyle(color: Colors.white, fontSize: 13, fontWeight: FontWeight.bold),
),
const SizedBox(height: 4),
const Text(
'وجه الكاميرا أو حرك مؤشر السمت للتسديد على المعلم',
style: TextStyle(color: Color(0xFF94A3B8), fontSize: 11),
),
],
),
child: const Center(
child: Icon(Icons.camera_alt, size: 48, color: Color(0xFF38BDF8)),
),
),
@@ -230,43 +229,46 @@ class _CameraResectionViewState extends State<CameraResectionView> {
targetName: _selectedLandmark?.name,
),
// ── 3. Top Header: Step Flow + Close Button ─────────────────
// ── 3. Top Header: Step Flow + Search Bar ────────────────────
Positioned(
top: 48,
top: 44,
left: 16,
right: 16,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Top Action Row
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
// Step Flow Badge
// Step Indicator Badge
Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
decoration: BoxDecoration(
color: const Color(0xEB0F172A),
color: const Color(0xF00F172A),
borderRadius: BorderRadius.circular(20),
border: Border.all(
color: obsCount >= 2 ? const Color(0xFF22C55E) : const Color(0xFF0071E3),
width: 1.5,
),
),
child: Row(
children: [
Icon(
obsCount >= 2 ? Icons.check_circle : Icons.gps_fixed,
size: 14,
size: 16,
color: obsCount >= 2 ? const Color(0xFF4ADE80) : const Color(0xFF38BDF8),
),
const SizedBox(width: 6),
const SizedBox(width: 8),
Text(
obsCount == 0
? 'الخطوة 1: تسديد المعلم الأول'
? 'الخطوة 1: ابحث وسدد على المعلم الأول'
: (obsCount == 1
? 'الخطوة 2: تسديد المعلم الثاني'
: 'تم رصد $obsCount معالم (جاهز للحساب)'),
? 'الخطوة 2: ابحث وسدد على المعلم الثاني'
: 'تم رصد $obsCount معالم • جاري استخراج الموقع'),
style: TextStyle(
color: obsCount >= 2 ? const Color(0xFF4ADE80) : Colors.white,
fontSize: 11,
fontSize: 11.5,
fontWeight: FontWeight.bold,
),
),
@@ -274,10 +276,10 @@ class _CameraResectionViewState extends State<CameraResectionView> {
),
),
// Close / Return to Map Button
// Close Button
IconButton.filled(
onPressed: widget.onClose,
icon: const Icon(Icons.close, size: 16),
icon: const Icon(Icons.close, size: 18),
style: IconButton.styleFrom(
backgroundColor: const Color(0xCC0F172A),
foregroundColor: Colors.white,
@@ -288,220 +290,194 @@ class _CameraResectionViewState extends State<CameraResectionView> {
const SizedBox(height: 10),
// Search Bar for Landmarks
// Unified Place / Mosque / Landmark Search Field
Container(
decoration: BoxDecoration(
color: const Color(0xEB0F172A),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.white12),
color: const Color(0xF50F172A),
borderRadius: BorderRadius.circular(14),
border: Border.all(color: const Color(0xFF0071E3)),
boxShadow: const [BoxShadow(color: Colors.black54, blurRadius: 15)],
),
child: TextField(
controller: _searchController,
onChanged: _onSearchChanged,
style: const TextStyle(color: Colors.white, fontSize: 12),
style: const TextStyle(color: Colors.white, fontSize: 13),
decoration: InputDecoration(
hintText: 'ابحث عن معلم بالاسم أو المحافظة أو النوع...',
hintStyle: const TextStyle(color: Color(0xFF64748B), fontSize: 11),
prefixIcon: const Icon(Icons.search, color: Color(0xFF38BDF8), size: 18),
hintText: 'ابحث عن أي مسجد، مبنى، قلعة، تقاطع، أو معلم...',
hintStyle: const TextStyle(color: Color(0xFF94A3B8), fontSize: 12),
prefixIcon: const Icon(Icons.search, color: Color(0xFF38BDF8), size: 20),
suffixIcon: _searchController.text.isNotEmpty
? IconButton(
icon: const Icon(Icons.clear, size: 14, color: Colors.white60),
icon: const Icon(Icons.clear, size: 16, color: Colors.white70),
onPressed: () {
_searchController.clear();
_onSearchChanged('');
},
)
: null,
contentPadding: const EdgeInsets.symmetric(vertical: 10),
contentPadding: const EdgeInsets.symmetric(vertical: 12),
border: InputBorder.none,
),
),
),
const SizedBox(height: 6),
if (_isSearching) ...[
const SizedBox(height: 4),
const LinearProgressIndicator(minHeight: 2, color: Color(0xFF0071E3), backgroundColor: Colors.transparent),
],
// Region filter horizontal pills
SizedBox(
height: 28,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: _regions.length,
itemBuilder: (context, i) {
final r = _regions[i];
final isSelected = r == _selectedRegion;
return Padding(
padding: const EdgeInsets.only(left: 6),
child: ChoiceChip(
label: Text(r, style: TextStyle(fontSize: 10, color: isSelected ? Colors.white : const Color(0xFF94A3B8))),
selected: isSelected,
onSelected: (_) => _onRegionSelected(r),
backgroundColor: const Color(0x990F172A),
selectedColor: const Color(0xFF0071E3),
padding: const EdgeInsets.symmetric(horizontal: 4),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(14)),
),
);
},
// Search Results Dropdown List (if search has text or active)
if (_searchController.text.isNotEmpty && _searchResults.isNotEmpty)
Container(
margin: const EdgeInsets.only(top: 6),
constraints: const BoxConstraints(maxHeight: 180),
decoration: BoxDecoration(
color: const Color(0xF80F172A),
borderRadius: BorderRadius.circular(14),
border: Border.all(color: Colors.white12),
boxShadow: const [BoxShadow(color: Colors.black87, blurRadius: 20)],
),
child: ListView.separated(
padding: const EdgeInsets.symmetric(vertical: 4),
shrinkWrap: true,
itemCount: _searchResults.length,
separatorBuilder: (_, __) => const Divider(color: Colors.white10, height: 1),
itemBuilder: (context, idx) {
final lm = _searchResults[idx];
final isSelected = lm.id == _selectedLandmark?.id;
return ListTile(
dense: true,
visualDensity: VisualDensity.compact,
leading: Icon(
lm.typeIcon,
color: isSelected ? const Color(0xFF38BDF8) : const Color(0xFF94A3B8),
size: 18,
),
title: Text(
lm.name,
style: TextStyle(
color: isSelected ? const Color(0xFF38BDF8) : Colors.white,
fontSize: 12,
fontWeight: FontWeight.bold,
),
),
subtitle: Text(
'${lm.region} • ${lm.elevationM}م',
style: const TextStyle(color: Color(0xFF64748B), fontSize: 10),
),
trailing: isSelected ? const Icon(Icons.check, color: Color(0xFF38BDF8), size: 16) : null,
onTap: () {
setState(() => _selectedLandmark = lm);
_searchController.text = lm.name;
},
);
},
),
),
),
],
),
),
// ── 4. Bottom Control Panel ────────────────────────────────
// ── 4. Bottom HUD: Active Target Details & Lock Action ───────
Positioned(
bottom: 20,
bottom: 24,
left: 16,
right: 16,
child: Container(
padding: const EdgeInsets.all(14),
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: const Color(0xF50F172A),
borderRadius: BorderRadius.circular(18),
border: Border.all(color: const Color(0x800071E3)),
borderRadius: BorderRadius.circular(20),
border: Border.all(color: const Color(0xFF0071E3), width: 1.5),
boxShadow: const [BoxShadow(color: Colors.black87, blurRadius: 25)],
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Heading Slider fine-tune (for desktop/field override)
Row(
children: [
const Text('ضبط السمت:', style: TextStyle(fontSize: 10, color: Color(0xFF94A3B8))),
Expanded(
child: Slider(
value: _headingDeg,
min: 0,
max: 359,
activeColor: const Color(0xFF0071E3),
onChanged: (v) => setState(() => _headingDeg = v),
),
// Targeted Landmark Card
if (_selectedLandmark != null)
Container(
margin: const EdgeInsets.only(bottom: 12),
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
decoration: BoxDecoration(
color: const Color(0x661E293B),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.white12),
),
Text(
AngleFormatter.format(_headingDeg, widget.angleUnit, includeLabel: false),
style: const TextStyle(fontSize: 11, fontWeight: FontWeight.bold, color: Color(0xFF38BDF8)),
),
],
),
// Landmark Selector Cards (Horizontal Carousel)
if (_filteredLandmarks.isNotEmpty)
SizedBox(
height: 52,
child: ListView.builder(
scrollDirection: Axis.horizontal,
itemCount: _filteredLandmarks.length,
itemBuilder: (context, idx) {
final lm = _filteredLandmarks[idx];
final isSelected = lm.id == _selectedLandmark?.id;
final isObserved = widget.observations.any((o) => o.landmark.id == lm.id);
return GestureDetector(
onTap: () => setState(() => _selectedLandmark = lm),
child: Container(
margin: const EdgeInsets.only(left: 8),
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: isSelected
? const Color(0xFF0071E3)
: (isObserved ? const Color(0x3322C55E) : const Color(0xFF1E293B)),
borderRadius: BorderRadius.circular(10),
border: Border.all(
color: isSelected
? Colors.white
: (isObserved ? const Color(0xFF22C55E) : Colors.white12),
child: Row(
children: [
Icon(_selectedLandmark!.typeIcon, color: const Color(0xFF38BDF8), size: 22),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
_selectedLandmark!.name,
style: const TextStyle(
color: Colors.white,
fontSize: 13,
fontWeight: FontWeight.bold,
),
overflow: TextOverflow.ellipsis,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Row(
children: [
if (isObserved)
const Icon(Icons.check_circle, size: 12, color: Color(0xFF4ADE80)),
if (isObserved) const SizedBox(width: 4),
Text(
lm.name,
style: TextStyle(
fontSize: 11,
fontWeight: FontWeight.bold,
color: isSelected ? Colors.white : const Color(0xFFE2E8F0),
),
),
],
),
Text(
'${lm.region} • ${lm.elevationM}م',
style: TextStyle(
fontSize: 9.5,
color: isSelected ? Colors.white70 : const Color(0xFF94A3B8),
),
),
],
Text(
'${_selectedLandmark!.region} • إحداثيات: ${_selectedLandmark!.lat.toStringAsFixed(4)}, ${_selectedLandmark!.lng.toStringAsFixed(4)}',
style: const TextStyle(color: Color(0xFF94A3B8), fontSize: 10),
),
],
),
),
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: const Color(0x330071E3),
borderRadius: BorderRadius.circular(8),
),
child: Text(
AngleFormatter.format(trueAzimuth, widget.angleUnit, includeLabel: false),
style: const TextStyle(
color: Color(0xFF38BDF8),
fontSize: 12,
fontWeight: FontWeight.w900,
),
),
);
},
),
],
),
),
const SizedBox(height: 12),
// Action Buttons: Lock Landmark + Calculate Button
// Main Lock / Action Button
Row(
children: [
// Lock Target Button
Expanded(
flex: 3,
child: ElevatedButton.icon(
onPressed: _lockCurrentObservation,
icon: const Icon(Icons.lock_outline, size: 16),
onPressed: _selectedLandmark != null ? _lockCurrentObservation : null,
icon: Icon(
obsCount >= 1 ? Icons.my_location : Icons.lock_outline,
size: 18,
),
label: Text(
obsCount == 0
? 'تثبيت رصد المعلم الأول'
: (obsCount == 1 ? 'تثبيت رصد المعلم الثاني' : 'تثبيت معلم إضافي (+1)'),
style: const TextStyle(fontSize: 12, fontWeight: FontWeight.bold),
: 'تثبيت رصد المعلم الثاني (استخراج الموقع فوراً)',
style: const TextStyle(fontSize: 12.5, fontWeight: FontWeight.w900),
),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF0071E3),
backgroundColor: obsCount >= 1 ? const Color(0xFF22C55E) : const Color(0xFF0071E3),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 12),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
padding: const EdgeInsets.symmetric(vertical: 14),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
elevation: 4,
),
),
),
// Calculate & Show on Map (Available when >= 2)
if (obsCount >= 2) ...[
const SizedBox(width: 8),
Expanded(
flex: 2,
child: ElevatedButton.icon(
onPressed: widget.onCalculatePressed,
icon: const Icon(Icons.map, size: 16),
label: const Text(
'استخراج الموقع',
style: TextStyle(fontSize: 11.5, fontWeight: FontWeight.w900),
),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF22C55E),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 12),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
),
),
),
],
// Reset Button
if (obsCount > 0) ...[
const SizedBox(width: 8),
IconButton.filledTonal(
onPressed: widget.onResetPressed,
icon: const Icon(Icons.refresh, size: 16),
icon: const Icon(Icons.refresh, size: 18),
style: IconButton.styleFrom(
backgroundColor: const Color(0x33EF4444),
foregroundColor: const Color(0xFFF87171),
@@ -0,0 +1,240 @@
import 'package:flutter/material.dart';
import 'package:intaleq_maps/intaleq_maps.dart';
import '../services/military_grid_utils.dart';
enum MapPickerTarget {
losObserver,
losTarget,
routeOrigin,
routeDestination,
}
class InteractiveMapPickerHud extends StatelessWidget {
final MapPickerTarget target;
final LatLng centerPosition;
final VoidCallback onConfirm;
final VoidCallback onCancel;
const InteractiveMapPickerHud({
super.key,
required this.target,
required this.centerPosition,
required this.onConfirm,
required this.onCancel,
});
String get title {
switch (target) {
case MapPickerTarget.losObserver:
return 'تحديد موقع الراصد الميداني (Observer) 🔴';
case MapPickerTarget.losTarget:
return 'تحديد موقع الهدف التكتيكي (Target) 🎯';
case MapPickerTarget.routeOrigin:
return 'تحديد نقطة الانطلاق (البداية) 🟢';
case MapPickerTarget.routeDestination:
return 'تحديد نقطة الوصول والهدف (الوجهة) 🏁';
}
}
Color get themeColor {
switch (target) {
case MapPickerTarget.losObserver:
return const Color(0xFF38BDF8);
case MapPickerTarget.losTarget:
return const Color(0xFFEF4444);
case MapPickerTarget.routeOrigin:
return const Color(0xFF22C55E);
case MapPickerTarget.routeDestination:
return const Color(0xFFF59E0B);
}
}
IconData get pinIcon {
switch (target) {
case MapPickerTarget.losObserver:
return Icons.person_pin_circle;
case MapPickerTarget.losTarget:
return Icons.gps_fixed;
case MapPickerTarget.routeOrigin:
return Icons.my_location;
case MapPickerTarget.routeDestination:
return Icons.flag;
}
}
@override
Widget build(BuildContext context) {
final milCoords = MilitaryGridUtils.fromLatLng(centerPosition);
return Stack(
children: [
// ── 1. Center Floating Marker & Tooltip (Siro Rider Style) ──
Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
// Dynamic Floating Coordinates Bubble
Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
decoration: BoxDecoration(
color: const Color(0xF20F172A),
borderRadius: BorderRadius.circular(20),
border: Border.all(color: themeColor, width: 1.5),
boxShadow: const [BoxShadow(color: Colors.black54, blurRadius: 15)],
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
'شرقيات: ${milCoords.eastingStr} م • شماليات: ${milCoords.northingStr} م',
style: const TextStyle(color: Colors.white, fontSize: 11, fontWeight: FontWeight.bold),
),
Text(
'${centerPosition.latitude.toStringAsFixed(5)}, ${centerPosition.longitude.toStringAsFixed(5)}',
style: const TextStyle(color: Color(0xFF94A3B8), fontSize: 9.5),
),
],
),
),
const SizedBox(height: 6),
// Animated Floating Pin Icon
Icon(pinIcon, size: 44, color: themeColor),
// Ground Shadow Reticle
Container(
width: 10,
height: 5,
decoration: BoxDecoration(
color: Colors.black.withAlpha(128),
borderRadius: BorderRadius.circular(10),
),
),
const SizedBox(height: 48), // Offset to position pin tip at exact screen center
],
),
),
// ── 2. Top Instructions Bar ─────────────────────────────────
Positioned(
top: 50,
left: 20,
right: 20,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
decoration: BoxDecoration(
color: const Color(0xF20F172A),
borderRadius: BorderRadius.circular(14),
border: Border.all(color: Colors.white12),
boxShadow: const [BoxShadow(color: Colors.black54, blurRadius: 12)],
),
child: Row(
children: [
Icon(Icons.touch_app, color: themeColor, size: 20),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
title,
style: const TextStyle(color: Colors.white, fontSize: 12.5, fontWeight: FontWeight.bold),
),
const Text(
'حرك الخريطة وضع رأس المؤشر على النقطة المطلوبة بدقة',
style: TextStyle(color: Color(0xFF94A3B8), fontSize: 10),
),
],
),
),
IconButton(
icon: const Icon(Icons.close, color: Colors.white70, size: 18),
onPressed: onCancel,
),
],
),
),
),
// ── 3. Bottom Confirmation Action Bar ────────────────────────
Positioned(
bottom: 24,
left: 16,
right: 16,
child: Container(
padding: const EdgeInsets.all(16),
decoration: BoxDecoration(
color: const Color(0xF50F172A),
borderRadius: BorderRadius.circular(20),
border: Border.all(color: themeColor, width: 1.5),
boxShadow: const [BoxShadow(color: Colors.black87, blurRadius: 25)],
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
const Text('الموقع المحدد حالياً:', style: TextStyle(color: Color(0xFF94A3B8), fontSize: 11)),
Text(
'المربع: ${milCoords.shortGrid} (${milCoords.zone}N)',
style: TextStyle(color: themeColor, fontSize: 11, fontWeight: FontWeight.bold),
),
],
),
const SizedBox(height: 6),
Container(
width: double.infinity,
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: const Color(0xFF1E293B),
borderRadius: BorderRadius.circular(10),
),
child: Text(
milCoords.arabicFullFormat,
textAlign: TextAlign.center,
style: const TextStyle(color: Colors.white, fontSize: 12, fontWeight: FontWeight.bold),
),
),
const SizedBox(height: 12),
Row(
children: [
Expanded(
flex: 3,
child: ElevatedButton.icon(
onPressed: onConfirm,
icon: const Icon(Icons.check, size: 18),
label: const Text('تثبيت وتأكيد هذا الموقع', style: TextStyle(fontSize: 13, fontWeight: FontWeight.bold)),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF0071E3),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 13),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
),
),
const SizedBox(width: 8),
Expanded(
flex: 1,
child: OutlinedButton(
onPressed: onCancel,
style: OutlinedButton.styleFrom(
foregroundColor: const Color(0xFF94A3B8),
side: const BorderSide(color: Colors.white24),
padding: const EdgeInsets.symmetric(vertical: 13),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
child: const Text('إلغاء', style: TextStyle(fontSize: 12)),
),
),
],
),
],
),
),
),
],
);
}
}
@@ -198,8 +198,18 @@ class _OfflinePackageDialogState extends State<OfflinePackageDialog> {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(title, style: const TextStyle(color: Color(0xFF94A3B8), fontSize: 11)),
Text(value, style: const TextStyle(color: Colors.white, fontSize: 11, fontWeight: FontWeight.bold)),
Expanded(
child: Text(
title,
style: const TextStyle(color: Color(0xFF94A3B8), fontSize: 11),
overflow: TextOverflow.ellipsis,
),
),
const SizedBox(width: 8),
Text(
value,
style: const TextStyle(color: Colors.white, fontSize: 11, fontWeight: FontWeight.bold),
),
],
);
}
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import '../models/landmark.dart';
import '../services/landmark_database.dart';
import '../services/local_sqlite_db.dart';
import '../services/tactical_api_service.dart';
class PlaceSearchSheet extends StatefulWidget {
final Function(TacticalLandmark, bool startNavigation) onDestinationSelected;
@@ -24,21 +25,39 @@ class _PlaceSearchSheetState extends State<PlaceSearchSheet> {
}
void _onSearch(String query) async {
if (query.trim().isEmpty) {
final cleanQuery = query.trim();
if (cleanQuery.isEmpty) {
setState(() => _results = LandmarkDatabase.allLandmarks.take(15).toList());
return;
}
setState(() => _isSearching = true);
// 1. Search SQLite Database
final dbResults = await LocalSqliteDb.searchPlaces(query, limit: 30);
// 1. Search SQLite Database (Instant offline search)
List<TacticalLandmark> dbResults = [];
try {
dbResults = await LocalSqliteDb.searchPlaces(cleanQuery, limit: 30);
} catch (_) {}
// 2. Search Landmark database as fallback
final staticResults = LandmarkDatabase.search(query);
// 2. Search Static Landmark database
final staticResults = LandmarkDatabase.search(cleanQuery);
final combined = <TacticalLandmark>[...dbResults, ...staticResults];
final unique = combined.toSet().toList();
// 3. Search Online Geocoding API if offline results are few
List<TacticalLandmark> onlineResults = [];
if (dbResults.length < 5) {
try {
onlineResults = await TacticalApiService.searchOnlinePlaces(cleanQuery);
} catch (_) {}
}
final combined = <TacticalLandmark>[...dbResults, ...onlineResults, ...staticResults];
final seen = <String>{};
final unique = <TacticalLandmark>[];
for (final r in combined) {
if (seen.add('${r.name}_${r.lat}_${r.lng}')) {
unique.add(r);
}
}
if (mounted) {
setState(() {
@@ -145,6 +164,10 @@ class _PlaceSearchSheetState extends State<PlaceSearchSheet> {
'${item.region} • ${item.typeLabelArabic}',
style: const TextStyle(color: Color(0xFF94A3B8), fontSize: 10.5),
),
onTap: () {
Navigator.pop(context);
widget.onDestinationSelected(item, false); // Preview route with fit bounds
},
trailing: ElevatedButton.icon(
onPressed: () {
Navigator.pop(context);
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,369 @@
import 'package:flutter/material.dart';
import 'package:intaleq_maps/intaleq_maps.dart';
import '../models/landmark.dart';
import '../services/landmark_database.dart';
import '../services/local_sqlite_db.dart';
import '../services/offline_routing_engine.dart';
import '../services/tactical_api_service.dart';
class TacticalRoutePlannerSheet extends StatefulWidget {
final LatLng currentGps;
final LatLng? resectionFix;
final LatLng? initialOrigin;
final LatLng? initialDestination;
final Function(LatLng origin, LatLng destination, TacticalVehicleProfile profile, bool autoStartNav) onRouteConfirmed;
final VoidCallback onPickOriginOnMap;
final VoidCallback onPickDestinationOnMap;
final VoidCallback onClose;
const TacticalRoutePlannerSheet({
super.key,
required this.currentGps,
this.resectionFix,
this.initialOrigin,
this.initialDestination,
required this.onRouteConfirmed,
required this.onPickOriginOnMap,
required this.onPickDestinationOnMap,
required this.onClose,
});
@override
State<TacticalRoutePlannerSheet> createState() => _TacticalRoutePlannerSheetState();
}
class _TacticalRoutePlannerSheetState extends State<TacticalRoutePlannerSheet> {
late LatLng _origin;
String _originName = 'موقعي الحالي (GPS)';
LatLng? _destination;
TacticalVehicleProfile _selectedProfile = TacticalVehicleProfile.convoy;
// Search state
final TextEditingController _destSearchCtrl = TextEditingController();
List<TacticalLandmark> _searchResults = [];
bool _isSearching = false;
@override
void initState() {
super.initState();
_origin = widget.initialOrigin ?? widget.resectionFix ?? widget.currentGps;
if (widget.initialOrigin != null) {
_originName = 'نقطة محددة من الخريطة (${widget.initialOrigin!.latitude.toStringAsFixed(4)}, ${widget.initialOrigin!.longitude.toStringAsFixed(4)})';
} else if (widget.resectionFix != null) {
_originName = 'موقع الراصد المستخرج (التقاطع البصري)';
}
if (widget.initialDestination != null) {
_destination = widget.initialDestination;
_destSearchCtrl.text = 'نقطة الهدف المحددة (${widget.initialDestination!.latitude.toStringAsFixed(4)}, ${widget.initialDestination!.longitude.toStringAsFixed(4)})';
}
}
@override
void dispose() {
_destSearchCtrl.dispose();
super.dispose();
}
void _onSearch(String query) async {
final cleanQuery = query.trim();
if (cleanQuery.isEmpty) {
setState(() => _searchResults = []);
return;
}
setState(() => _isSearching = true);
List<TacticalLandmark> dbResults = [];
try {
dbResults = await LocalSqliteDb.searchPlaces(cleanQuery, limit: 25);
} catch (_) {}
final staticResults = LandmarkDatabase.search(cleanQuery);
List<TacticalLandmark> onlineResults = [];
if (dbResults.length < 5) {
try {
onlineResults = await TacticalApiService.searchOnlinePlaces(cleanQuery);
} catch (_) {}
}
final combined = <TacticalLandmark>[...dbResults, ...onlineResults, ...staticResults];
final seen = <String>{};
final unique = <TacticalLandmark>[];
for (final r in combined) {
if (seen.add('${r.name}_${r.lat}_${r.lng}')) {
unique.add(r);
}
}
if (mounted) {
setState(() {
_searchResults = unique;
_isSearching = false;
});
}
}
void _selectDestination(TacticalLandmark item) {
setState(() {
_destination = LatLng(item.lat, item.lng);
_searchResults = [];
_destSearchCtrl.text = '${item.name} (${item.region})';
});
}
void _calculateAndPreview() {
if (_destination == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
backgroundColor: Color(0xFFEF4444),
content: Text('يرجى تحديد نقطة الوصول / الهدف أولاً.'),
),
);
return;
}
Navigator.pop(context);
widget.onRouteConfirmed(_origin, _destination!, _selectedProfile, false);
}
@override
Widget build(BuildContext context) {
return Container(
padding: const EdgeInsets.only(top: 14, left: 16, right: 16, bottom: 24),
decoration: const BoxDecoration(
color: Color(0xF50F172A),
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
border: Border(top: BorderSide(color: Color(0xFF0071E3), width: 2)),
boxShadow: [BoxShadow(color: Colors.black87, blurRadius: 30)],
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// Header
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Container(
padding: const EdgeInsets.all(6),
decoration: BoxDecoration(
color: const Color(0x330071E3),
borderRadius: BorderRadius.circular(8),
border: Border.all(color: const Color(0xFF0071E3)),
),
child: const Icon(Icons.alt_route, color: Color(0xFF38BDF8), size: 20),
),
const SizedBox(width: 10),
const Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'مخطط مسارات القوافل التكتيكية (Routing)',
style: TextStyle(color: Colors.white, fontSize: 13.5, fontWeight: FontWeight.bold),
),
Text(
'حساب المسار وتضاريس الطرق وسرعة القوافل',
style: TextStyle(color: Color(0xFF94A3B8), fontSize: 10.5),
),
],
),
],
),
IconButton(
onPressed: widget.onClose,
icon: const Icon(Icons.close, color: Colors.white70, size: 20),
),
],
),
const SizedBox(height: 12),
// Origin & Destination Box
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: const Color(0xFF1E293B),
borderRadius: BorderRadius.circular(14),
border: Border.all(color: Colors.white12),
),
child: Column(
children: [
// Origin Row
Row(
children: [
const Icon(Icons.my_location, color: Color(0xFF22C55E), size: 18),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text('نقطة الانطلاق (البداية):', style: TextStyle(color: Color(0xFF94A3B8), fontSize: 10)),
Text(
_originName,
style: const TextStyle(color: Colors.white, fontSize: 12, fontWeight: FontWeight.bold),
overflow: TextOverflow.ellipsis,
),
],
),
),
IconButton(
icon: const Icon(Icons.touch_app, size: 18, color: Color(0xFF38BDF8)),
tooltip: 'تحديد نقطة البداية على الخريطة',
onPressed: () {
Navigator.pop(context);
widget.onPickOriginOnMap();
},
),
],
),
const Divider(color: Colors.white12, height: 16),
// Destination Search Row
Row(
children: [
const Icon(Icons.location_on, color: Color(0xFFEF4444), size: 18),
const SizedBox(width: 10),
Expanded(
child: TextField(
controller: _destSearchCtrl,
onChanged: _onSearch,
style: const TextStyle(color: Colors.white, fontSize: 12.5),
decoration: InputDecoration(
hintText: 'ابحث عن نقطة الوصول أو الهدف...',
hintStyle: const TextStyle(color: Color(0xFF64748B), fontSize: 11.5),
isDense: true,
border: InputBorder.none,
contentPadding: const EdgeInsets.symmetric(vertical: 6),
suffixIcon: _destSearchCtrl.text.isNotEmpty
? IconButton(
icon: const Icon(Icons.clear, size: 14, color: Colors.white60),
onPressed: () {
_destSearchCtrl.clear();
_onSearch('');
},
)
: null,
),
),
),
IconButton(
icon: const Icon(Icons.touch_app, size: 18, color: Color(0xFFF59E0B)),
tooltip: 'تحديد الهدف على الخريطة',
onPressed: () {
Navigator.pop(context);
widget.onPickDestinationOnMap();
},
),
],
),
],
),
),
if (_isSearching) ...[
const SizedBox(height: 4),
const LinearProgressIndicator(minHeight: 2, color: Color(0xFF0071E3), backgroundColor: Colors.transparent),
],
// Search Results Dropdown
if (_searchResults.isNotEmpty) ...[
const SizedBox(height: 6),
Container(
constraints: const BoxConstraints(maxHeight: 160),
decoration: BoxDecoration(
color: const Color(0xFF1E293B),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.white12),
),
child: ListView.separated(
padding: EdgeInsets.zero,
shrinkWrap: true,
itemCount: _searchResults.length,
separatorBuilder: (_, __) => const Divider(color: Colors.white10, height: 1),
itemBuilder: (ctx, i) {
final item = _searchResults[i];
return ListTile(
dense: true,
visualDensity: VisualDensity.compact,
leading: Icon(item.typeIcon, size: 16, color: const Color(0xFF38BDF8)),
title: Text(item.name, style: const TextStyle(color: Colors.white, fontSize: 11.5, fontWeight: FontWeight.bold)),
subtitle: Text('${item.region} • ${item.typeLabelArabic}', style: const TextStyle(color: Color(0xFF64748B), fontSize: 10)),
onTap: () => _selectDestination(item),
);
},
),
),
],
const SizedBox(height: 12),
// Vehicle Profiles
Row(
children: [
_buildProfileChip(TacticalVehicleProfile.convoy, 'قافلة عسكرية', Icons.local_shipping),
const SizedBox(width: 6),
_buildProfileChip(TacticalVehicleProfile.offroad4x4, 'دفع رباعي 4x4', Icons.directions_car),
const SizedBox(width: 6),
_buildProfileChip(TacticalVehicleProfile.rapidResponse, 'تدخل سريع', Icons.electric_bolt),
],
),
const SizedBox(height: 14),
// Action Button
SizedBox(
width: double.infinity,
child: ElevatedButton.icon(
onPressed: _calculateAndPreview,
icon: const Icon(Icons.route, size: 18),
label: const Text('حساب المسار وتضاريس الانحدار', style: TextStyle(fontSize: 13, fontWeight: FontWeight.w900)),
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF0071E3),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 13),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
),
),
],
),
);
}
Widget _buildProfileChip(TacticalVehicleProfile prof, String label, IconData icon) {
final isSelected = _selectedProfile == prof;
return Expanded(
child: GestureDetector(
onTap: () => setState(() => _selectedProfile = prof),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 8),
decoration: BoxDecoration(
color: isSelected ? const Color(0xFF0071E3) : const Color(0xFF1E293B),
borderRadius: BorderRadius.circular(10),
border: Border.all(color: isSelected ? Colors.white : Colors.white12),
),
child: Column(
children: [
Icon(icon, size: 16, color: isSelected ? Colors.white : const Color(0xFF94A3B8)),
const SizedBox(height: 3),
Text(
label,
style: TextStyle(
color: isSelected ? Colors.white : const Color(0xFF94A3B8),
fontSize: 10,
fontWeight: FontWeight.bold,
),
),
],
),
),
),
);
}
}
@@ -0,0 +1,516 @@
import 'package:flutter/material.dart';
import 'package:intaleq_maps/intaleq_maps.dart';
import '../services/viewshed_360_engine.dart';
import '../services/offline_los_engine.dart';
import '../services/military_grid_utils.dart';
/// Tactical Bottom Sheet for 360° Radial Viewshed (تحليل حقل الرؤية الدائري 360 درجة)
class TacticalViewshedSheet extends StatefulWidget {
final LatLng observer;
final LatLng? currentGps;
final Function(LatLng newObs)? onUpdateObserver;
final Function(Viewshed360Report report) onReportUpdated;
final VoidCallback onPickObserverOnMap;
final VoidCallback onClose;
const TacticalViewshedSheet({
super.key,
required this.observer,
this.currentGps,
this.onUpdateObserver,
required this.onReportUpdated,
required this.onPickObserverOnMap,
required this.onClose,
});
@override
State<TacticalViewshedSheet> createState() => _TacticalViewshedSheetState();
}
class _TacticalViewshedSheetState extends State<TacticalViewshedSheet> with SingleTickerProviderStateMixin {
late LatLng _currentObs;
double _radiusKm = 5.0;
double _observerHeightM = 2.0;
int _rayCount = 360; // 360 continuous 1-degree radial rays (15-20ms)
Viewshed360Report? _report;
bool _isCalculating = false;
bool _showCoordInputs = false;
late TabController _coordTabController;
late TextEditingController _obsEastingCtrl;
late TextEditingController _obsNorthingCtrl;
late TextEditingController _obsLatCtrl;
late TextEditingController _obsLngCtrl;
@override
void initState() {
super.initState();
_currentObs = widget.observer;
_coordTabController = TabController(length: 2, vsync: this);
final obsMil = MilitaryGridUtils.fromLatLng(_currentObs);
_obsEastingCtrl = TextEditingController(text: obsMil.eastingStr);
_obsNorthingCtrl = TextEditingController(text: obsMil.northingStr);
_obsLatCtrl = TextEditingController(text: _currentObs.latitude.toStringAsFixed(6));
_obsLngCtrl = TextEditingController(text: _currentObs.longitude.toStringAsFixed(6));
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) _computeViewshed();
});
}
@override
void didUpdateWidget(covariant TacticalViewshedSheet oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.observer != widget.observer) {
_currentObs = widget.observer;
final obsMil = MilitaryGridUtils.fromLatLng(_currentObs);
_obsEastingCtrl.text = obsMil.eastingStr;
_obsNorthingCtrl.text = obsMil.northingStr;
_obsLatCtrl.text = _currentObs.latitude.toStringAsFixed(6);
_obsLngCtrl.text = _currentObs.longitude.toStringAsFixed(6);
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) _computeViewshed();
});
}
}
@override
void dispose() {
_coordTabController.dispose();
_obsEastingCtrl.dispose();
_obsNorthingCtrl.dispose();
_obsLatCtrl.dispose();
_obsLngCtrl.dispose();
super.dispose();
}
void _computeViewshed() async {
setState(() => _isCalculating = true);
final report = await Viewshed360Engine.calculateAsync(
observer: _currentObs,
radiusMeters: _radiusKm * 1000.0,
observerHeightM: _observerHeightM,
rayCount: _rayCount,
);
if (mounted) {
setState(() {
_report = report;
_isCalculating = false;
});
widget.onReportUpdated(report);
}
}
void _applyManualCoordinates() {
LatLng newObs = _currentObs;
if (_coordTabController.index == 0) {
final e = double.tryParse(_obsEastingCtrl.text) ?? 0;
final n = double.tryParse(_obsNorthingCtrl.text) ?? 0;
if (e > 100000 && n > 1000000) {
newObs = MilitaryGridUtils.toLatLng(easting: e, northing: n);
}
} else {
final lat = double.tryParse(_obsLatCtrl.text);
final lng = double.tryParse(_obsLngCtrl.text);
if (lat != null && lng != null) {
newObs = LatLng(lat, lng);
}
}
setState(() {
_currentObs = newObs;
_showCoordInputs = false;
});
widget.onUpdateObserver?.call(newObs);
_computeViewshed();
}
@override
Widget build(BuildContext context) {
final obsMil = MilitaryGridUtils.fromLatLng(_currentObs);
final obsElev = JordanDemSurface.elevationAt(_currentObs.latitude, _currentObs.longitude);
return Container(
padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 14),
decoration: const BoxDecoration(
color: Color(0xFF0F172A),
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
border: Border(top: BorderSide(color: Color(0xFF38BDF8), width: 1.5)),
),
child: SafeArea(
top: false,
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// Handle Bar
Center(
child: Container(
width: 40,
height: 4,
margin: const EdgeInsets.only(bottom: 12),
decoration: BoxDecoration(
color: Colors.white24,
borderRadius: BorderRadius.circular(2),
),
),
),
// Header Bar
Row(
children: [
Container(
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
color: const Color(0x3322C55E),
borderRadius: BorderRadius.circular(10),
border: Border.all(color: const Color(0xFF22C55E)),
),
child: const Icon(Icons.radar, color: Color(0xFF4ADE80), size: 22),
),
const SizedBox(width: 12),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text(
'منظومة حقل الرؤية والرصد 360° (360° Viewshed)',
style: TextStyle(color: Colors.white, fontSize: 13, fontWeight: FontWeight.bold),
overflow: TextOverflow.ellipsis,
),
Text(
'مركز الرصد: ${obsMil.arabicFullFormat} • ارتفاع: ${obsElev.round()}م',
style: const TextStyle(color: Color(0xFF38BDF8), fontSize: 11),
overflow: TextOverflow.ellipsis,
),
],
),
),
IconButton(
onPressed: widget.onClose,
icon: const Icon(Icons.close, color: Colors.white70, size: 20),
),
],
),
const SizedBox(height: 12),
// Metrics Card
if (_report != null)
Container(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 12),
decoration: BoxDecoration(
color: const Color(0xFF1E293B),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.white10),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
_buildMetricCol(
'المساحة المكشوفة',
'${_report!.visibleAreaSqKm.toStringAsFixed(1)} كم²',
const Color(0xFF4ADE80),
),
_buildDivider(),
_buildMetricCol(
'كفاءة التغطية',
'${_report!.visibilityPercentage}%',
_report!.visibilityPercentage > 50 ? const Color(0xFF4ADE80) : const Color(0xFFF59E0B),
),
_buildDivider(),
_buildMetricCol(
'متوسط المدى',
'${_report!.averageSightRangeKm.toStringAsFixed(1)} كم',
const Color(0xFF38BDF8),
),
],
),
),
const SizedBox(height: 12),
// Radius Slider
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
const Icon(Icons.blur_circular, size: 16, color: Color(0xFF38BDF8)),
const SizedBox(width: 6),
Text(
'نصف قطر المسح: ${_radiusKm.toStringAsFixed(1)} كم',
style: const TextStyle(color: Colors.white, fontSize: 12, fontWeight: FontWeight.bold),
),
],
),
Text(
'${(_radiusKm * 1000).round()} متر',
style: const TextStyle(color: Colors.white60, fontSize: 11),
),
],
),
Slider(
value: _radiusKm,
min: 1.0,
max: 15.0,
divisions: 14,
activeColor: const Color(0xFF38BDF8),
inactiveColor: Colors.white12,
onChanged: (val) {
setState(() => _radiusKm = val);
_computeViewshed();
},
),
// Optic Height Segmented Choice
Row(
children: [
const Icon(Icons.height, size: 16, color: Color(0xFFF59E0B)),
const SizedBox(width: 6),
const Text(
'ارتفاع نقطة الرصد / البصريات:',
style: TextStyle(color: Colors.white, fontSize: 12, fontWeight: FontWeight.bold),
),
],
),
const SizedBox(height: 6),
Row(
children: [
_buildHeightChip(2.0, '2م (منظار)'),
const SizedBox(width: 6),
_buildHeightChip(5.0, '5م (مركبة)'),
const SizedBox(width: 6),
_buildHeightChip(10.0, '10م (سارية)'),
const SizedBox(width: 6),
_buildHeightChip(25.0, '25م (برج)'),
],
),
const SizedBox(height: 12),
// Action Buttons Row: [Manual Coordinates / Map Selection / Current GPS]
Row(
children: [
Expanded(
child: OutlinedButton.icon(
onPressed: () => setState(() => _showCoordInputs = !_showCoordInputs),
style: OutlinedButton.styleFrom(
foregroundColor: const Color(0xFF38BDF8),
side: const BorderSide(color: Color(0xFF38BDF8)),
padding: const EdgeInsets.symmetric(vertical: 10),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
),
icon: Icon(_showCoordInputs ? Icons.expand_less : Icons.edit_location_alt, size: 16),
label: const Text('إدخال إحداثيات', style: TextStyle(fontSize: 11, fontWeight: FontWeight.bold)),
),
),
const SizedBox(width: 8),
Expanded(
child: ElevatedButton.icon(
onPressed: widget.onPickObserverOnMap,
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF0284C7),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 10),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
),
icon: const Icon(Icons.touch_app, size: 16),
label: const Text('نقر من الخريطة 👁️', style: TextStyle(fontSize: 11, fontWeight: FontWeight.bold)),
),
),
if (widget.currentGps != null) ...[
const SizedBox(width: 8),
IconButton(
tooltip: 'استخدام موقعي الحالي',
style: IconButton.styleFrom(
backgroundColor: const Color(0xFF1E293B),
foregroundColor: const Color(0xFF22C55E),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10),
side: const BorderSide(color: Color(0xFF22C55E)),
),
),
icon: const Icon(Icons.my_location, size: 18),
onPressed: () {
setState(() {
_currentObs = widget.currentGps!;
});
widget.onUpdateObserver?.call(_currentObs);
_computeViewshed();
},
),
],
],
),
// Coordinate Inputs Box
if (_showCoordInputs) ...[
const SizedBox(height: 12),
Container(
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
color: const Color(0xFF1E293B),
borderRadius: BorderRadius.circular(12),
border: Border.all(color: Colors.white12),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
TabBar(
controller: _coordTabController,
indicatorColor: const Color(0xFF38BDF8),
labelColor: const Color(0xFF38BDF8),
unselectedLabelColor: Colors.white60,
tabs: const [
Tab(text: 'شبكة عسكرية (UTM)'),
Tab(text: 'درجات عشرية (Lat/Lng)'),
],
),
const SizedBox(height: 10),
SizedBox(
height: 70,
child: TabBarView(
controller: _coordTabController,
children: [
// UTM
Row(
children: [
Expanded(
child: TextField(
controller: _obsEastingCtrl,
keyboardType: TextInputType.number,
style: const TextStyle(color: Colors.white, fontSize: 12),
decoration: InputDecoration(
labelText: 'شرقيات (Easting)',
labelStyle: const TextStyle(color: Colors.white60, fontSize: 11),
filled: true,
fillColor: const Color(0xFF0F172A),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
),
),
),
const SizedBox(width: 8),
Expanded(
child: TextField(
controller: _obsNorthingCtrl,
keyboardType: TextInputType.number,
style: const TextStyle(color: Colors.white, fontSize: 12),
decoration: InputDecoration(
labelText: 'شماليات (Northing)',
labelStyle: const TextStyle(color: Colors.white60, fontSize: 11),
filled: true,
fillColor: const Color(0xFF0F172A),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
),
),
),
],
),
// Decimal
Row(
children: [
Expanded(
child: TextField(
controller: _obsLatCtrl,
keyboardType: const TextInputType.numberWithOptions(decimal: true),
style: const TextStyle(color: Colors.white, fontSize: 12),
decoration: InputDecoration(
labelText: 'دائرة العرض (Lat)',
labelStyle: const TextStyle(color: Colors.white60, fontSize: 11),
filled: true,
fillColor: const Color(0xFF0F172A),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
),
),
),
const SizedBox(width: 8),
Expanded(
child: TextField(
controller: _obsLngCtrl,
keyboardType: const TextInputType.numberWithOptions(decimal: true),
style: const TextStyle(color: Colors.white, fontSize: 12),
decoration: InputDecoration(
labelText: 'خط الطول (Lng)',
labelStyle: const TextStyle(color: Colors.white60, fontSize: 11),
filled: true,
fillColor: const Color(0xFF0F172A),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
),
),
),
],
),
],
),
),
const SizedBox(height: 8),
ElevatedButton(
onPressed: _applyManualCoordinates,
style: ElevatedButton.styleFrom(
backgroundColor: const Color(0xFF22C55E),
foregroundColor: Colors.white,
padding: const EdgeInsets.symmetric(vertical: 10),
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
child: const Text('تطبيق الإحداثيات وإعادة الرصد', style: TextStyle(fontWeight: FontWeight.bold)),
),
],
),
),
],
],
),
),
),
);
}
Widget _buildHeightChip(double h, String label) {
final isSelected = _observerHeightM == h;
return Expanded(
child: InkWell(
onTap: () {
setState(() => _observerHeightM = h);
_computeViewshed();
},
child: Container(
padding: const EdgeInsets.symmetric(vertical: 6),
decoration: BoxDecoration(
color: isSelected ? const Color(0xFF0284C7) : const Color(0xFF1E293B),
borderRadius: BorderRadius.circular(8),
border: Border.all(color: isSelected ? const Color(0xFF38BDF8) : Colors.white12),
),
child: Center(
child: Text(
label,
style: TextStyle(
color: isSelected ? Colors.white : Colors.white70,
fontSize: 9.5,
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
),
),
),
),
),
);
}
Widget _buildMetricCol(String title, String val, Color color) {
return Column(
children: [
Text(title, style: const TextStyle(color: Colors.white60, fontSize: 10)),
const SizedBox(height: 2),
Text(val, style: TextStyle(color: color, fontSize: 13, fontWeight: FontWeight.bold)),
],
);
}
Widget _buildDivider() {
return Container(width: 1, height: 26, color: Colors.white12);
}
}