Update default location to Thrissur and remove Whitefield, Bengaluru
This commit is contained in:
@@ -57,6 +57,7 @@ class _SearchScreenState extends State<SearchScreen> {
|
||||
List<_LocationItem> _searchResults = [];
|
||||
bool _showSearchResults = false;
|
||||
bool _loadingLocation = false;
|
||||
bool _isSearching = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -124,14 +125,48 @@ class _SearchScreenState extends State<SearchScreen> {
|
||||
Navigator.of(context).pop(result);
|
||||
}
|
||||
|
||||
void _selectAndClose(String location) {
|
||||
Future<void> _selectAndClose(String location) async {
|
||||
// Looks up pincode + coordinates from the database for the given city name.
|
||||
final match = _locationDb.cast<_LocationItem?>().firstWhere(
|
||||
(loc) => loc!.city.toLowerCase() == location.toLowerCase() ||
|
||||
loc.displayTitle.toLowerCase() == location.toLowerCase(),
|
||||
(loc) => loc != null && (loc.city.toLowerCase() == location.toLowerCase() ||
|
||||
loc.displayTitle.toLowerCase() == location.toLowerCase()),
|
||||
orElse: () => null,
|
||||
);
|
||||
_selectWithPincode(location, pincode: match?.pincode, lat: match?.lat, lng: match?.lng);
|
||||
|
||||
if (match != null) {
|
||||
_selectWithPincode(location, pincode: match.pincode, lat: match.lat, lng: match.lng);
|
||||
return;
|
||||
}
|
||||
|
||||
// Fallback: Geocode the location name
|
||||
setState(() => _isSearching = true);
|
||||
try {
|
||||
final placemarksByAddress = await locationFromAddress(location);
|
||||
if (placemarksByAddress.isNotEmpty) {
|
||||
final loc = placemarksByAddress.first;
|
||||
final placemarks = await placemarkFromCoordinates(loc.latitude, loc.longitude);
|
||||
String label = location;
|
||||
String? pincode;
|
||||
if (placemarks.isNotEmpty) {
|
||||
final p = placemarks.first;
|
||||
final parts = <String>[];
|
||||
if ((p.locality ?? '').isNotEmpty) parts.add(p.locality!);
|
||||
if ((p.subAdministrativeArea ?? '').isNotEmpty && p.subAdministrativeArea != p.locality) parts.add(p.subAdministrativeArea!);
|
||||
if (parts.isNotEmpty) label = parts.join(', ');
|
||||
pincode = p.postalCode;
|
||||
}
|
||||
if (mounted) {
|
||||
_selectWithPincode(label, pincode: pincode ?? 'all', lat: loc.latitude, lng: loc.longitude);
|
||||
}
|
||||
return;
|
||||
}
|
||||
} catch (_) {
|
||||
// Geocoding failed, proceed with just the text label
|
||||
} finally {
|
||||
if (mounted) setState(() => _isSearching = false);
|
||||
}
|
||||
|
||||
_selectWithPincode(location);
|
||||
}
|
||||
|
||||
Future<void> _useCurrentLocation() async {
|
||||
@@ -263,6 +298,7 @@ class _SearchScreenState extends State<SearchScreen> {
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _ctrl,
|
||||
enabled: !_isSearching,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Search city, area or locality',
|
||||
hintStyle: TextStyle(color: Color(0xFF9CA3AF)),
|
||||
@@ -282,7 +318,12 @@ class _SearchScreenState extends State<SearchScreen> {
|
||||
},
|
||||
),
|
||||
),
|
||||
if (_ctrl.text.isNotEmpty)
|
||||
if (_isSearching)
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(right: 8.0),
|
||||
child: SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2)),
|
||||
)
|
||||
else if (_ctrl.text.isNotEmpty)
|
||||
IconButton(
|
||||
icon: const Icon(Icons.clear, size: 20),
|
||||
onPressed: () {
|
||||
|
||||
Reference in New Issue
Block a user