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),