From d0a5faf802cabfd4888c6fdbd76c054dfb46b872 Mon Sep 17 00:00:00 2001 From: Doaa <121sadman121@gmail.com> Date: Fri, 27 Jun 2025 00:59:28 +0300 Subject: [PATCH 1/2] parcel viewer --- lib/screens/map/parcel_viewer_screen.dart | 143 +++++++++++++++++----- 1 file changed, 113 insertions(+), 30 deletions(-) diff --git a/lib/screens/map/parcel_viewer_screen.dart b/lib/screens/map/parcel_viewer_screen.dart index 42c3cbd..896300b 100644 --- a/lib/screens/map/parcel_viewer_screen.dart +++ b/lib/screens/map/parcel_viewer_screen.dart @@ -1,3 +1,5 @@ +// I have preserved all your original comments. + import 'package:buildflow_frontend/screens/home_page.dart'; import 'package:flutter/material.dart'; import 'package:flutter_map/flutter_map.dart'; @@ -25,6 +27,7 @@ class _ParcelViewerScreenState extends State { final TextEditingController _genericSearchController = TextEditingController(); + // This service is kept for other functions like getParcelDetailsAndGeometry final LWSCExtendedGeoService _lwscGeoService = LWSCExtendedGeoService(); final NominatimService _nominatimService = NominatimService(); @@ -65,58 +68,126 @@ class _ParcelViewerScreenState extends State { super.dispose(); } + // This function fetches localities directly. It is already correct for the new data. Future _fetchLocalities() async { setState(() { _isLoadingLocalities = true; _hasLocalitiesError = false; }); + + const String apiUrl = + 'https://geo.lwsc.ps/api/services/app/Lookup/GetLocalities'; + try { - final fetchedLocalities = await _lwscGeoService.getLocalities(); - setState(() { - _localities = fetchedLocalities; - _isLoadingLocalities = false; - }); - print('DEBUG: Fetched localities: ${_localities.length} items.'); - print('DEBUG: Localities content: $_localities'); - } catch (e) { + final response = await http.get(Uri.parse(apiUrl)); + + if (response.statusCode == 200) { + final data = json.decode(response.body); + + if (data['success'] == true && data['result'] != null) { + final List localitiesList = data['result']; + final Map fetchedLocalities = { + for (var locality in localitiesList) + (locality['name'] as String): (locality['id'] as int), + }; + + setState(() { + _localities = fetchedLocalities; + _isLoadingLocalities = false; + }); + print( + 'DEBUG: Fetched localities successfully: ${_localities.length} items.', + ); + } else { + throw Exception( + 'API returned success=false. Error: ${data['error']}', + ); + } + } else { + throw Exception( + 'Failed to load localities. Status Code: ${response.statusCode}', + ); + } + } catch (e, stacktrace) { setState(() { _isLoadingLocalities = false; _hasLocalitiesError = true; }); _showSnackBar('Error fetching regions. Automatic search disabled.'); - print('ERROR: Failed to fetch localities: $e'); + print( + '==================== FETCH LOCALITIES FAILED ====================', + ); + print('ERROR: $e'); + print('STACKTRACE: \n$stacktrace'); + print( + '=================================================================', + ); } } + // ⭐️⭐️⭐️ START OF MODIFICATION / بداية التعديل ⭐️⭐️⭐️ + // This function is now updated to fetch blocks directly from an API. + // تم تحديث هذه الدالة لجلب بيانات الأحواض (Basins) مباشرة من الـ API Future _fetchBlocks(int localityId) async { setState(() { _isLoadingBlocks = true; _hasBlocksError = false; + _blocks = {}; // Clear previous blocks + _selectedBasinName = null; + _selectedBlockId = null; }); + + // ⚠️⚠️⚠️ انتبه: هذا الرابط هو تخمين. يرجى التأكد من الرابط الصحيح واستبداله إذا لزم الأمر. + // ⚠️⚠️⚠️ ATTENTION: This URL is a guess based on the localities URL. Please verify and replace it with the correct one. + final String apiUrl = + 'https://geo.lwsc.ps/api/services/app/Lookup/GetBlocksByLocalityId?localityId=$localityId'; + + print('DEBUG: Fetching blocks from URL: $apiUrl'); + try { - print('DEBUG: Fetching blocks for localityId: $localityId'); - final fetchedBlocks = await _lwscGeoService.getBlocksByLocalityId( - localityId, - ); - setState(() { - _blocks = fetchedBlocks; - _selectedBasinName = null; - _selectedBlockId = null; - _isLoadingBlocks = false; - }); - print('DEBUG: Fetched blocks: ${_blocks.length} items.'); - print('DEBUG: Blocks content: $_blocks'); - } catch (e) { + final response = await http.get(Uri.parse(apiUrl)); + + if (response.statusCode == 200) { + final data = json.decode(response.body); + + if (data['success'] == true && data['result'] != null) { + final List blocksList = data['result']; + + // The logic is the same: create a Map from 'name' and 'id' + final Map fetchedBlocks = { + for (var block in blocksList) + (block['name'] as String): (block['id'] as int), + }; + + setState(() { + _blocks = fetchedBlocks; + _isLoadingBlocks = false; + }); + print('DEBUG: Fetched blocks successfully: ${_blocks.length} items.'); + print('DEBUG: Blocks content: $_blocks'); + } else { + throw Exception( + 'API returned success=false. Error: ${data['error']}', + ); + } + } else { + throw Exception( + 'Failed to load blocks. Status Code: ${response.statusCode}', + ); + } + } catch (e, stacktrace) { setState(() { _isLoadingBlocks = false; _hasBlocksError = true; }); - _showSnackBar( - 'Error fetching basins. Automatic search disabled for basin.', - ); - print('ERROR: Failed to fetch blocks: $e'); + _showSnackBar('Error fetching basins. Please try again.'); + print('==================== FETCH BLOCKS FAILED ===================='); + print('ERROR: $e'); + print('STACKTRACE: \n$stacktrace'); + print('==============================================================='); } } + // ⭐️⭐️⭐️ END OF MODIFICATION / نهاية التعديل ⭐️⭐️⭐️ Future _getCurrentUserLocation() async { bool serviceEnabled; @@ -262,6 +333,7 @@ class _ParcelViewerScreenState extends State { } } + // This function is now updated to allow choosing between the fastest and shortest route. Future _drawRoute(LatLng start, LatLng end) async { setState(() { _isLoadingRoute = true; @@ -269,7 +341,7 @@ class _ParcelViewerScreenState extends State { }); const String openRouteServiceApiKey = - 'YOUR_OPENROUTESERVICE_API_KEY'; // ⚠️⚠️⚠️ استبدلي هذا ⚠️⚠️⚠️ + '5b3ce3597851110001cf6248c8a94e6a10234e2aa666b69d1689a2ad'; // ⚠️⚠️⚠️ استبدلي هذا ⚠️⚠️⚠️ if (openRouteServiceApiKey == 'YOUR_OPENROUTESERVICE_API_KEY') { _showSnackBar('Please get your OpenRouteService API Key for routing.'); setState(() { @@ -278,10 +350,17 @@ class _ParcelViewerScreenState extends State { return; } + // ⭐️⭐️⭐️ THE CHANGE IS HERE / التغيير هنا ⭐️⭐️⭐️ + // Choose your preference: 'fastest' (default) or 'shortest' + // اختر ما تفضله: 'fastest' (الأسرع - الافتراضي) أو 'shortest' (الأقصر) + const String preference = 'shortest'; + final Uri uri = Uri.parse( - 'https://api.openrouteservice.org/v2/directions/driving-car?api_key=$openRouteServiceApiKey&start=${start.longitude},${start.latitude}&end=${end.longitude},${end.latitude}', + 'https://api.openrouteservice.org/v2/directions/driving-car?api_key=$openRouteServiceApiKey&preference=$preference&start=${start.longitude},${start.latitude}&end=${end.longitude},${end.latitude}', ); + print('DEBUG: Requesting route with URL: $uri'); // For debugging + try { final response = await http.get( uri, @@ -304,7 +383,9 @@ class _ParcelViewerScreenState extends State { setState(() { _routePoints = points; }); - _showSnackBar('Route calculated successfully.'); + _showSnackBar( + 'Route calculated successfully (Preference: $preference).', + ); } else { _showSnackBar('No route found for these locations.'); } @@ -373,7 +454,7 @@ class _ParcelViewerScreenState extends State { children: [ IconButton( icon: const Icon(Icons.arrow_back_ios_new_rounded, size: 28), - color: AppColors.accent, + color: Colors.white, onPressed: () => const HomeScreen(), ), Expanded( @@ -563,6 +644,7 @@ class _ParcelViewerScreenState extends State { _selectedLocalityName = newValue; _selectedLocalityId = _localities[newValue]; + // Reset everything below when region changes _blocks = {}; _selectedBasinName = null; _selectedBlockId = null; @@ -615,6 +697,7 @@ class _ParcelViewerScreenState extends State { setState(() { _selectedBasinName = newValue; _selectedBlockId = _blocks[newValue]; + // Reset parcel details when basin changes _parcelPolygonCoordinates = null; _parcelCenter = null; _routePoints = []; From 03c85094b4d8af1492dedf978326dea4c4d88504 Mon Sep 17 00:00:00 2001 From: Doaa <121sadman121@gmail.com> Date: Fri, 27 Jun 2025 01:04:36 +0300 Subject: [PATCH 2/2] . --- macos/Flutter/GeneratedPluginRegistrant.swift | 2 - pubspec.lock | 169 +----------------- .../flutter/generated_plugin_registrant.cc | 3 - windows/flutter/generated_plugins.cmake | 1 - 4 files changed, 8 insertions(+), 167 deletions(-) diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index f02ed9f..97c61e1 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -12,7 +12,6 @@ import firebase_auth import firebase_core import firebase_storage import flutter_secure_storage_macos -import geolocator_apple import path_provider_foundation import shared_preferences_foundation import url_launcher_macos @@ -26,7 +25,6 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin")) FLTFirebaseStoragePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseStoragePlugin")) FlutterSecureStorageMacosPlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStorageMacosPlugin")) - GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin")) diff --git a/pubspec.lock b/pubspec.lock index db4c62e..ccaec9b 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -81,14 +81,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.3.4+2" - crypto: - dependency: transitive - description: - name: crypto - sha256: "1e445881f28f22d6140f181e07737b22f1e099a5e1ff94b0af2f9e4a463f4855" - url: "https://pub.dev" - source: hosted - version: "3.0.6" cupertino_icons: dependency: "direct main" description: @@ -157,10 +149,10 @@ packages: dependency: transitive description: name: file_selector_macos - sha256: "271ab9986df0c135d45c3cdb6bd0faa5db6f4976d3e4b437cf7d0f258d941bfc" + sha256: "8c9250b2bd2d8d4268e39c82543bacbaca0fda7d29e0728c3c4bbb7c820fd711" url: "https://pub.dev" source: hosted - version: "0.9.4+2" + version: "0.9.4+3" file_selector_platform_interface: dependency: transitive description: @@ -249,14 +241,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.9.7" - fixnum: - dependency: transitive - description: - name: fixnum - sha256: b6dc7065e46c974bc7c5f143080a6764ec7a4be6da1285ececdc37be96de53be - url: "https://pub.dev" - source: hosted - version: "1.1.1" flutter: dependency: "direct main" description: flutter @@ -278,14 +262,6 @@ packages: url: "https://pub.dev" source: hosted version: "5.0.0" - flutter_map: - dependency: "direct main" - description: - name: flutter_map - sha256: "87cc8349b8fa5dccda5af50018c7374b6645334a0d680931c1fe11bce88fa5bb" - url: "https://pub.dev" - source: hosted - version: "6.2.1" flutter_plugin_android_lifecycle: dependency: transitive description: @@ -360,54 +336,6 @@ packages: description: flutter source: sdk version: "0.0.0" - geolocator: - dependency: "direct main" - description: - name: geolocator - sha256: "6cb9fb6e5928b58b9a84bdf85012d757fd07aab8215c5205337021c4999bad27" - url: "https://pub.dev" - source: hosted - version: "11.1.0" - geolocator_android: - dependency: transitive - description: - name: geolocator_android - sha256: fcb1760a50d7500deca37c9a666785c047139b5f9ee15aa5469fae7dbbe3170d - url: "https://pub.dev" - source: hosted - version: "4.6.2" - geolocator_apple: - dependency: transitive - description: - name: geolocator_apple - sha256: dbdd8789d5aaf14cf69f74d4925ad1336b4433a6efdf2fce91e8955dc921bf22 - url: "https://pub.dev" - source: hosted - version: "2.3.13" - geolocator_platform_interface: - dependency: transitive - description: - name: geolocator_platform_interface - sha256: "30cb64f0b9adcc0fb36f628b4ebf4f731a2961a0ebd849f4b56200205056fe67" - url: "https://pub.dev" - source: hosted - version: "4.2.6" - geolocator_web: - dependency: transitive - description: - name: geolocator_web - sha256: "49d8f846ebeb5e2b6641fe477a7e97e5dd73f03cbfef3fd5c42177b7300fb0ed" - url: "https://pub.dev" - source: hosted - version: "3.0.0" - geolocator_windows: - dependency: transitive - description: - name: geolocator_windows - sha256: "175435404d20278ffd220de83c2ca293b73db95eafbdc8131fe8609be1421eb6" - url: "https://pub.dev" - source: hosted - version: "0.2.5" get: dependency: "direct main" description: @@ -428,10 +356,10 @@ packages: dependency: "direct main" description: name: http - sha256: "2c11f3f94c687ee9bad77c171151672986360b2b001d109814ee7140b2cf261b" + sha256: "5895291c13fa8a3bd82e76d5627f69e0d85ca6a30dcac95c4ea19a5d555879c2" url: "https://pub.dev" source: hosted - version: "1.4.0" + version: "0.13.6" http_parser: dependency: "direct main" description: @@ -520,14 +448,6 @@ packages: url: "https://pub.dev" source: hosted version: "0.6.7" - latlong2: - dependency: "direct main" - description: - name: latlong2 - sha256: "98227922caf49e6056f91b6c56945ea1c7b166f28ffcd5fb8e72fc0b453cc8fe" - url: "https://pub.dev" - source: hosted - version: "0.9.1" leak_tracker: dependency: transitive description: @@ -560,14 +480,6 @@ packages: url: "https://pub.dev" source: hosted version: "5.1.1" - lists: - dependency: transitive - description: - name: lists - sha256: "4ca5c19ae4350de036a7e996cdd1ee39c93ac0a2b840f4915459b7d0a7d4ab27" - url: "https://pub.dev" - source: hosted - version: "1.0.1" logger: dependency: "direct main" description: @@ -600,14 +512,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.16.0" - mgrs_dart: - dependency: transitive - description: - name: mgrs_dart - sha256: fb89ae62f05fa0bb90f70c31fc870bcbcfd516c843fb554452ab3396f78586f7 - url: "https://pub.dev" - source: hosted - version: "2.0.0" mime: dependency: transitive description: @@ -688,22 +592,6 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.8" - polylabel: - dependency: transitive - description: - name: polylabel - sha256: "41b9099afb2aa6c1730bdd8a0fab1400d287694ec7615dd8516935fa3144214b" - url: "https://pub.dev" - source: hosted - version: "1.0.1" - proj4dart: - dependency: "direct main" - description: - name: proj4dart - sha256: c8a659ac9b6864aa47c171e78d41bbe6f5e1d7bd790a5814249e6b68bc44324e - url: "https://pub.dev" - source: hosted - version: "2.1.0" shared_preferences: dependency: transitive description: @@ -765,14 +653,6 @@ packages: description: flutter source: sdk version: "0.0.0" - smooth_page_indicator: - dependency: "direct main" - description: - name: smooth_page_indicator - sha256: b21ebb8bc39cf72d11c7cfd809162a48c3800668ced1c9da3aade13a32cf6c1c - url: "https://pub.dev" - source: hosted - version: "1.2.1" source_span: dependency: transitive description: @@ -781,14 +661,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.10.1" - sprintf: - dependency: transitive - description: - name: sprintf - sha256: "1fc9ffe69d4df602376b52949af107d8f5703b77cda567c4d7d86a0693120f23" - url: "https://pub.dev" - source: hosted - version: "7.0.0" stack_trace: dependency: transitive description: @@ -837,14 +709,6 @@ packages: url: "https://pub.dev" source: hosted version: "1.4.0" - unicode: - dependency: transitive - description: - name: unicode - sha256: "0f69e46593d65245774d4f17125c6084d2c20b4e473a983f6e21b7d7762218f1" - url: "https://pub.dev" - source: hosted - version: "0.3.1" url_launcher: dependency: "direct main" description: @@ -909,14 +773,6 @@ packages: url: "https://pub.dev" source: hosted version: "3.1.4" - uuid: - dependency: transitive - description: - name: uuid - sha256: a5be9ef6618a7ac1e964353ef476418026db906c4facdedaa299b7a2e71690ff - url: "https://pub.dev" - source: hosted - version: "4.5.1" vector_math: dependency: transitive description: @@ -961,10 +817,10 @@ packages: dependency: transitive description: name: webview_flutter_platform_interface - sha256: "7cb32b21825bd65569665c32bb00a34ded5779786d6201f5350979d2d529940d" + sha256: f0dc2dc3a2b1e3a6abdd6801b9355ebfeb3b8f6cde6b9dc7c9235909c4a1f147 url: "https://pub.dev" source: hosted - version: "2.13.0" + version: "2.13.1" webview_flutter_web: dependency: "direct main" description: @@ -985,19 +841,10 @@ packages: dependency: transitive description: name: win32 - sha256: "329edf97fdd893e0f1e3b9e88d6a0e627128cc17cc316a8d67fda8f1451178ba" + sha256: "66814138c3562338d05613a6e368ed8cfb237ad6d64a9e9334be3f309acfca03" url: "https://pub.dev" source: hosted version: "5.14.0" - wkt_parser: - dependency: transitive - description: - name: wkt_parser - sha256: "8a555fc60de3116c00aad67891bcab20f81a958e4219cc106e3c037aa3937f13" - url: "https://pub.dev" - source: hosted - version: "2.0.0" - xdg_directories: dependency: transitive description: @@ -1007,5 +854,5 @@ packages: source: hosted version: "1.1.0" sdks: - dart: ">=3.7.0 <4.0.0" + dart: ">=3.8.0 <4.0.0" flutter: ">=3.27.0" diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 1611ba8..8288eb3 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -13,7 +13,6 @@ #include #include #include -#include #include void RegisterPlugins(flutter::PluginRegistry* registry) { @@ -31,8 +30,6 @@ void RegisterPlugins(flutter::PluginRegistry* registry) { registry->GetRegistrarForPlugin("FirebaseStoragePluginCApi")); FlutterSecureStorageWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin")); - GeolocatorWindowsRegisterWithRegistrar( - registry->GetRegistrarForPlugin("GeolocatorWindows")); UrlLauncherWindowsRegisterWithRegistrar( registry->GetRegistrarForPlugin("UrlLauncherWindows")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 8f5f101..f8cd131 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -10,7 +10,6 @@ list(APPEND FLUTTER_PLUGIN_LIST firebase_core firebase_storage flutter_secure_storage_windows - geolocator_windows url_launcher_windows )