From 68c3f28d768d24e6b3ad7bcd19e9736f7c5242b1 Mon Sep 17 00:00:00 2001 From: Shreeyash Thorat <120039092+ShreeyashThorat@users.noreply.github.com> Date: Tue, 10 Feb 2026 15:05:38 +0530 Subject: [PATCH] itnerary --- .../current_location_selection.dart | 117 +++++++++++------- 1 file changed, 70 insertions(+), 47 deletions(-) diff --git a/lib/itinerary_creation/views/itinerary_creation_steps/current_location_selection.dart b/lib/itinerary_creation/views/itinerary_creation_steps/current_location_selection.dart index e4e685d..2fa8d6e 100644 --- a/lib/itinerary_creation/views/itinerary_creation_steps/current_location_selection.dart +++ b/lib/itinerary_creation/views/itinerary_creation_steps/current_location_selection.dart @@ -23,30 +23,47 @@ class CurrentLocationSelection extends StatefulWidget { class _CurrentLocationSelectionState extends State { final TextEditingController _controller = TextEditingController(); LatLng? _currentLatLng; + bool loading = false; Future _getCurrentLocation() async { - LocationPermission permission = await Geolocator.requestPermission(); + try { + setState(() { + loading = true; + }); + LocationPermission permission = await Geolocator.requestPermission(); - if (permission == LocationPermission.denied || - permission == LocationPermission.deniedForever) { - ScaffoldMessenger.of(context).showSnackBar( - const SnackBar(content: Text('Location permission denied')), + if (permission == LocationPermission.denied || + permission == LocationPermission.deniedForever) { + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('Location permission denied')), + ); + return; + } + + final position = await Geolocator.getCurrentPosition( + desiredAccuracy: LocationAccuracy.high, ); - return; + + final lat = position.latitude; + final lng = position.longitude; + + setState(() { + _currentLatLng = LatLng(lat, lng); + }); + + await _getAddressFromLatLng(lat, lng); + setState(() { + loading = false; + }); + } catch (e) { + setState(() { + loading = false; + }); + } finally { + setState(() { + loading = false; + }); } - - final position = await Geolocator.getCurrentPosition( - desiredAccuracy: LocationAccuracy.high, - ); - - final lat = position.latitude; - final lng = position.longitude; - - setState(() { - _currentLatLng = LatLng(lat, lng); - }); - - await _getAddressFromLatLng(lat, lng); } Future _getAddressFromLatLng(double lat, double lng) async { @@ -57,7 +74,6 @@ class _CurrentLocationSelectionState extends State { final place = placemarks.first; final address = [ - place.name, place.street, place.subLocality, place.locality, @@ -133,34 +149,41 @@ class _CurrentLocationSelectionState extends State { child: SizedBox( height: 250.h, width: double.infinity, - child: FlutterMap( - options: MapOptions( - initialCenter: _currentLatLng!, - initialZoom: 15, - ), - children: [ - TileLayer( - urlTemplate: - "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", - subdomains: const ['a', 'b', 'c'], - userAgentPackageName: 'com.citycards.customer', - ), - MarkerLayer( - markers: [ - Marker( - point: _currentLatLng!, - width: 40, - height: 40, - child: const Icon( - Icons.location_pin, - color: Colors.red, - size: 40, - ), + child: loading == true + ? Center( + child: CircularProgressIndicator( + color: Color(0xFFF95F62), ), - ], - ), - ], - ), + ) + : FlutterMap( + options: MapOptions( + initialCenter: _currentLatLng!, + initialZoom: 15, + ), + children: [ + TileLayer( + urlTemplate: + "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", + subdomains: const ['a', 'b', 'c'], + userAgentPackageName: + 'com.citycards.customer', + ), + MarkerLayer( + markers: [ + Marker( + point: _currentLatLng!, + width: 40, + height: 40, + child: const Icon( + Icons.location_pin, + color: Colors.red, + size: 40, + ), + ), + ], + ), + ], + ), ), ) : GestureDetector(